~aleteoryx/muditaos

ref: 2eca1d9b04a9da03fadb0192b0597942481e3fef muditaos/module-apps/application-calendar/widgets/CheckBoxWithLabelItem.cpp -rw-r--r-- 4.9 KiB
2eca1d9b — Piotr Tański [EGD-7047] Fixed navigation down through input texts 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
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "CheckBoxWithLabelItem.hpp"
#include "application-calendar/widgets/CalendarStyle.hpp"
#include "windows/AppWindow.hpp"
#include <ListView.hpp>
#include <Style.hpp>
#include <Utils.hpp>
#include <InputEvent.hpp>

namespace gui
{

    CheckBoxWithLabelItem::CheckBoxWithLabelItem(app::Application *application,
                                                 const std::string &description,
                                                 std::shared_ptr<WeekDaysRepeatData> data)
        : app(application), checkBoxData(std::move(data))
    {
        app = application;
        assert(app != nullptr);

        setMinimumSize(style::window::default_body_width, style::window::calendar::item::checkBox::height);
        setMargins(gui::Margins(
            style::window::calendar::leftMargin, style::window::calendar::item::checkBox::margin_top, 0, 0));
        setEdges(RectangleEdge::None);

        hBox = new gui::HBox(this, 0, 0, 0, 0);
        hBox->setEdges(gui::RectangleEdge::None);

        checkBox = new gui::CheckBox(
            hBox,
            0,
            0,
            0,
            0,
            [=](const UTF8 &text) {
                app->getCurrentWindow()->bottomBarTemporaryMode(text, BottomBar::Side::LEFT, false);
            },
            [=]() { app->getCurrentWindow()->bottomBarRestoreFromTemporaryMode(); });

        checkBox->setMinimumSize(style::window::calendar::item::checkBox::input_box_label_w,
                                 style::window::calendar::item::checkBox::height);
        checkBox->activeItem = false;

        descriptionLabel = new gui::Label(hBox, 0, 0, 0, 0);
        descriptionLabel->setMinimumSize(style::window::calendar::item::checkBox::description_label_w,
                                         style::window::calendar::item::checkBox::height);
        descriptionLabel->setMargins(gui::Margins(style::margins::very_big, 0, 0, 0));
        descriptionLabel->setEdges(gui::RectangleEdge::None);
        descriptionLabel->setAlignment(Alignment(gui::Alignment::Horizontal::Left, gui::Alignment::Vertical::Top));
        descriptionLabel->setFont(style::window::font::medium);
        descriptionLabel->activeItem = false;
        descriptionLabel->setText(description);

        applyCallbacks();
        if (checkBoxData != nullptr) {
            setCheckBoxes();
        }
        onContentChangedCallback = [&]() { return checkBox->isChecked(); };
    }

    void CheckBoxWithLabelItem::applyCallbacks()
    {
        focusChangedCallback = [&](Item &item) {
            if (focus) {
                descriptionLabel->setFont(style::window::font::mediumbold);
                setFocusItem(checkBox);
            }
            else {
                descriptionLabel->setFont(style::window::font::medium);
            }
            return true;
        };

        inputCallback = [&](gui::Item &item, const gui::InputEvent &event) {
            if (checkBox->onInput(event)) {
                checkBox->resizeItems();
                onContentChangedCallback = [&]() { return checkBox->isChecked(); };
                return true;
            }
            return false;
        };

        dimensionChangedCallback = [&](gui::Item &, const BoundingBox &newDim) -> bool {
            hBox->setArea({0, 0, newDim.w, newDim.h});
            return true;
        };
    }

    void CheckBoxWithLabelItem::setCheckBoxes()
    {
        if (descriptionLabel->getText() == utils::translate(style::strings::common::Monday)) {
            checkBox->setImageVisible(checkBoxData->getData(date::Monday.iso_encoding() - 1));
        }
        else if (descriptionLabel->getText() == utils::translate(style::strings::common::Tuesday)) {
            checkBox->setImageVisible(checkBoxData->getData(date::Tuesday.iso_encoding() - 1));
        }
        else if (descriptionLabel->getText() == utils::translate(style::strings::common::Wednesday)) {
            checkBox->setImageVisible(checkBoxData->getData(date::Wednesday.iso_encoding() - 1));
        }
        else if (descriptionLabel->getText() == utils::translate(style::strings::common::Thursday)) {
            checkBox->setImageVisible(checkBoxData->getData(date::Thursday.iso_encoding() - 1));
        }
        else if (descriptionLabel->getText() == utils::translate(style::strings::common::Friday)) {
            checkBox->setImageVisible(checkBoxData->getData(date::Friday.iso_encoding() - 1));
        }
        else if (descriptionLabel->getText() == utils::translate(style::strings::common::Saturday)) {
            checkBox->setImageVisible(checkBoxData->getData(date::Saturday.iso_encoding() - 1));
        }
        else if (descriptionLabel->getText() == utils::translate(style::strings::common::Sunday)) {
            checkBox->setImageVisible(checkBoxData->getData(date::Sunday.iso_encoding() - 1));
        }
    }

} /* namespace gui */