~aleteoryx/muditaos

ref: 52ca291b30c634cee5286a5fa2b3febd0685fec4 muditaos/module-apps/windows/OptionSetting.cpp -rw-r--r-- 2.4 KiB
52ca291b — Lucjan Bryndza [EGD-5097] Fix minor issues with littlefs fuse 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
62
63
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "OptionSetting.hpp"
#include "widgets/ButtonOnOff.hpp"

namespace gui
{
    auto OptionSettings::build() const -> Item *
    {
        auto optionBodyHBox = new HBox(nullptr, 0, 0, style::window::default_body_width, style::window::label::big_h);
        optionBodyHBox->setAlignment(Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Center));
        optionBodyHBox->activatedCallback    = activatedCallback;
        optionBodyHBox->focusChangedCallback = focusCb;
        style::window::decorate(optionBodyHBox);

        auto optionNameLabel =
            new Label(optionBodyHBox, indent ? style::window::default_left_margin : 0, 0, 0, 0, text);
        optionNameLabel->setEdges(RectangleEdge::None);
        optionNameLabel->setAlignment(Alignment(gui::Alignment::Horizontal::Left, gui::Alignment::Vertical::Center));
        optionNameLabel->setFont(style::window::font::big);

        std::string imageName;
        int optionRightItemWidth = 0;

        switch (rightItem) {
        case RightItem::ArrowBlack:
            imageName = "right_label_arrow";
            break;
        case RightItem::ArrowWhite:
            imageName = "right_label_arrow_border";
            break;
        case RightItem::On:
            new ButtonOnOff(optionBodyHBox, ButtonState::On);
            optionRightItemWidth = style::buttonOnOff::w;
            break;
        case RightItem::Off:
            new ButtonOnOff(optionBodyHBox, ButtonState::Off);
            optionRightItemWidth = style::buttonOnOff::w;
            break;
        case RightItem::Bt:
            imageName = "bt";
            break;
        case RightItem::Checked:
            imageName = "small_tick_W_M";
            break;
        default:
            break;
        }

        if (!imageName.empty()) {
            auto image           = new gui::Image(optionBodyHBox, 0, 0, 0, 0, imageName);
            optionRightItemWidth = image->getWidth();
        }
        if (indent) {
            optionRightItemWidth += style::window::default_left_margin;
        }

        optionNameLabel->setMinimumSize(style::window::default_body_width - optionRightItemWidth,
                                        style::window::label::big_h);
        return optionBodyHBox;
    }
} // namespace gui