Files
MuditaOS/module-apps/application-calculator/widgets/MathOperationsBox.cpp
Artur Śleszyński a702bbd17c [EGD-6561] Make calculator input testable
I got sick of manually testing calculator like a troglodyte.
2021-04-20 13:17:54 +02:00

52 lines
1.7 KiB
C++

// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#include "MathOperationsBox.hpp"
#include "application-calculator/widgets/CalculatorStyle.hpp"
#include "application-calculator/data/CalculatorInputProcessor.hpp"
#include <gui/widgets/Label.hpp>
#include <cassert>
namespace gui
{
MathOperationsBox::MathOperationsBox(
gui::Item *parent, int offsetTop, uint32_t width, uint32_t height, uint32_t cellWidth, uint32_t cellHeight)
: GridLayout(parent, style::window::default_left_margin, offsetTop, width, height, {cellWidth, cellHeight})
{
assert(parent != nullptr);
parent->addWidget(this);
grid.x = cellWidth;
grid.y = cellHeight;
fillInTheGrid();
}
void MathOperationsBox::fillInTheGrid()
{
using namespace calc;
std::array<const std::string, style::calculator::grid_cells> math_operations = {
"",
symbols::strings::plus,
"",
symbols::strings::multiplication,
symbols::strings::equals,
symbols::strings::division,
"",
symbols::strings::minus,
""};
for (const auto &symbol : math_operations) {
auto cell = new Label(this);
cell->setSize(grid.x, grid.y);
cell->setAlignment(gui::Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Center));
cell->setEdges(gui::RectangleEdge::None);
cell->setText(symbol);
cell->setFont(style::window::font::largelight);
this->addWidget(cell);
}
}
} // namespace gui