~aleteoryx/muditaos

muditaos/module-apps/application-calculator/widgets/MathOperationsBox.cpp -rw-r--r-- 1.6 KiB
a405cad6Aleteoryx trim readme 6 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/blob/master/LICENSE.md

#include "CalculatorStyle.hpp"
#include "MathOperationsBox.hpp"
#include <data/CalculatorInputProcessor.hpp>
#include <module-gui/gui/widgets/text/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