~aleteoryx/muditaos

ref: 1ab84f774fd4cb6f2284157c3e1425df4986348b muditaos/module-gui/gui/widgets/BottomBar.cpp -rw-r--r-- 4.9 KiB
1ab84f77 — Kuba [EGD-7720] Unmounting file system on system closure 4 years 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

/*
 * BottomBar.cpp
 *
 *  Created on: 13 mar 2019
 *      Author: robert
 */
#include "BottomBar.hpp"
#include "Label.hpp"
#include "Margins.hpp"
#include "utf8/UTF8.hpp"
#include <Style.hpp>
#include <log/log.hpp>

namespace gui
{

    BottomBar::BottomBar()
    {

        Padding margins{style::window::bottomBar::leftMargin, 0, style::window::bottomBar::rightMargin, 0};
        left   = prepareLabel(Side::LEFT);
        center = prepareLabel(Side::CENTER);
        right  = prepareLabel(Side::RIGHT);

        left->setPadding(margins);
        center->setPadding(margins);
        right->setPadding(margins);

        addWidget(left);
        addWidget(center);
        addWidget(right);

        setFillColor(ColorFullWhite);
        setBorderColor(ColorNoColor);
        setFilled(true);
        setSize(style::window::bottomBar::w, style::window::bottomBar::h);
    }
    BottomBar::BottomBar(Item *parent, uint32_t x, uint32_t y, uint32_t w, uint32_t h) : Rect{parent, x, y, w, h}
    {

        Padding margins{style::window::bottomBar::leftMargin, 0, style::window::bottomBar::rightMargin, 0};
        left   = prepareLabel(Side::LEFT);
        center = prepareLabel(Side::CENTER);
        right  = prepareLabel(Side::RIGHT);

        left->setPadding(margins);
        center->setPadding(margins);
        right->setPadding(margins);

        addWidget(left);
        addWidget(center);
        addWidget(right);

        setFillColor(ColorFullWhite);
        setBorderColor(ColorNoColor);
        setFilled(true);
        setSize(style::window::bottomBar::w, style::window::bottomBar::h);
        updateDrawArea();
    }
    BottomBar::~BottomBar()
    {}

    gui::Label *BottomBar::prepareLabel(BottomBar::Side side)
    {
        Label *label = new Label(this, 0, 0, 0, 0);
        label->setBorderColor(Color{15, 15});
        switch (side) {
        case Side::LEFT:
            label->setAlignment(gui::Alignment(gui::Alignment::Horizontal::Left, gui::Alignment::Vertical::Center));
            label->setFont(style::footer::font::medium);
            break;
        case Side::CENTER:
            label->setAlignment(gui::Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Center));
            label->setFont(style::footer::font::bold);
            break;
        case Side::RIGHT:
            label->setAlignment(gui::Alignment(gui::Alignment::Horizontal::Right, gui::Alignment::Vertical::Center));
            label->setFont(style::footer::font::medium);
            break;
        };

        label->setFilled(false);

        return label;
    }

    Label *BottomBar::getSide(BottomBar::Side side)
    {
        switch (side) {
        case Side::LEFT:
            return left;
        case Side::CENTER:
            return center;
        case Side::RIGHT:
            return right;
        };
        return nullptr;
    }

    void BottomBar::setActive(BottomBar::Side side, bool active)
    {
        getSide(side)->setVisible(active);
    }

    bool BottomBar::isActive(BottomBar::Side side)
    {
        return getSide(side)->visible;
    }

    void BottomBar::setText(BottomBar::Side side, const UTF8 &str, bool active)
    {
        getSide(side)->setText(str);
        setActive(side, active);
    }

    UTF8 BottomBar::getText(BottomBar::Side side)
    {
        return getSide(side)->getText();
    }

    bool BottomBar::onDimensionChanged(const BoundingBox &oldDim, const BoundingBox &newDim)
    {
        Rect::onDimensionChanged(oldDim, newDim);
        left->setSize(newDim.w, newDim.h);
        center->setSize(newDim.w, newDim.h);
        right->setSize(newDim.w, newDim.h);
        return true;
    }

    void BottomBar::store()
    {
        store(Side::LEFT);
        store(Side::CENTER);
        store(Side::RIGHT);
    }

    void BottomBar::store(Side side)
    {
        auto &el = cache.get(side);
        if (!el.stored) {
            el.text      = getSide(side)->getText();
            el.isVisible = getSide(side)->visible;
            el.stored    = true;
        }
    }

    void BottomBar::restore()
    {
        restore(Side::LEFT);
        restore(Side::CENTER);
        restore(Side::RIGHT);
    }

    void BottomBar::restore(BottomBar::Side side)
    {
        auto &el = cache.get(side);
        if (el.stored) {
            setText(side, el.text, el.isVisible);
            el.stored = false;
        }
    }

    void BottomBar::setFont(Side side, const UTF8 &fontName)
    {
        switch (side) {
        case Side::LEFT:
            left->setFont(fontName);
            break;
        case Side::CENTER:
            center->setFont(fontName);
            break;
        case Side::RIGHT:
            right->setFont(fontName);
            break;
        }
    }

    void BottomBar::accept(GuiVisitor &visitor)
    {
        visitor.visit(*this);
    }

} /* namespace gui */