~aleteoryx/muditaos

ref: cea4786a00f2c8d2a8d578d32e57689bd18930dc muditaos/module-gui/gui/widgets/CheckBox.cpp -rw-r--r-- 2.3 KiB
cea4786a — KacperLewandowski [EGD-3314] Develop EventTime, SeveralOptions and CheckBox items 5 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
#include "CheckBox.hpp"
#include "Style.hpp"
#include "Utils.hpp"

namespace gui
{

    CheckBox::CheckBox(Item *parent,
                       const uint32_t &x,
                       const uint32_t &y,
                       const uint32_t &w,
                       const uint32_t &h,
                       std::function<void(const UTF8 &, BottomBar::Side, bool)> bottomBarTemporaryMode,
                       std::function<void()> bottomBarRestoreFromTemporaryMode)
        : ImageBox(parent, x, y, w, h, image = new Image("small_tick")),
          bottomBarTemporaryMode(std::move(bottomBarTemporaryMode)),
          bottomBarRestoreFromTemporaryMode(std::move(bottomBarRestoreFromTemporaryMode))
    {
        setEdges(RectangleEdgeFlags::GUI_RECT_EDGE_BOTTOM);

        focusChangedCallback = [&](Item &item) {
            if (focus) {
                LOG_DEBUG("FOCUS");
                setFocusItem(image);
                if (image->visible) {
                    // bottomBarTemporaryMode(utils::localize.get("app_calendar_uncheck"), BottomBar::Side::LEFT,
                    // false);
                }
                else {
                    // bottomBarTemporaryMode(utils::localize.get("app_calendar_check"), BottomBar::Side::LEFT, false);
                }
            }
            else {
                LOG_DEBUG("NOT FOCUS");
                setFocusItem(nullptr);
                // bottomBarRestoreFromTemporaryMode();
            }
            return true;
        };

        inputCallback = [&](gui::Item &item, const gui::InputEvent &event) {
            LOG_DEBUG("INPUT CALLBACK");
            if (event.state != gui::InputEvent::State::keyReleasedShort) {
                return false;
            }
            if (event.keyCode == gui::KeyCode::KEY_ENTER) {
                LOG_DEBUG("KEY ENTER");
                image->setVisible(!image->visible);
                if (image->visible) {
                    bottomBarTemporaryMode(utils::localize.get("app_calendar_uncheck"), BottomBar::Side::CENTER, false);
                }
                else {
                    bottomBarTemporaryMode(utils::localize.get("app_calendar_check"), BottomBar::Side::CENTER, false);
                }
                return true;
            }
            return false;
        };
    }

} /* namespace gui */