~aleteoryx/muditaos

ref: 1340e6949c0762585b0de844863c91c859fb19b1 muditaos/module-apps/apps-common/widgets/InputBox.cpp -rw-r--r-- 2.8 KiB
1340e694 — Bartosz Revert "[MOS-578] Fix incorrect logic with SMS notifications" 2 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
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "InputBox.hpp"

#include <BoxLayout.hpp>
#include <Label.hpp>
#include <ImageBox.hpp>

namespace gui
{
    namespace input_Box
    {
        constexpr auto label_h = 30;
        constexpr auto text_h  = 33;
        constexpr auto h_box_h = text_h + 3;
        constexpr auto h       = label_h + style::margins::big + h_box_h;
    } // namespace input_Box

} // namespace gui

namespace gui
{
    auto inputBox(gui::Item *parent, const std::string &header, const std::string &icon) -> gui::Text *
    {
        auto verticalBox = new VBox(parent,
                                    style::window::default_left_margin,
                                    style::window::default_vertical_pos,
                                    style::window::default_body_width,
                                    input_Box::h);
        verticalBox->setEdges(RectangleEdge::None);

        auto label = new Label(verticalBox);
        label->setMinimumHeight(input_Box::label_h);
        label->setMaximumWidth(style::window::default_body_width);
        label->setFont(style::window::font::small);
        label->setEdges(RectangleEdge::None);
        label->setText(header);
        label->setAlignment(Alignment(gui::Alignment::Horizontal::Left, gui::Alignment::Vertical::Bottom));

        auto horizontalBox = new HBox(verticalBox);
        horizontalBox->setAlignment({gui::Alignment::Vertical::Top});
        horizontalBox->setMargins({0, style::margins::big, 0, 0});
        horizontalBox->setMinimumHeight(input_Box::h_box_h);
        horizontalBox->setMinimumWidth(style::window::default_body_width);
        horizontalBox->setPenWidth(style::window::default_border_rect_no_focus);
        horizontalBox->setEdges(RectangleEdge::Bottom);

        auto inputField = new TextFixedSize(horizontalBox);
        inputField->drawUnderline(false);
        inputField->setMinimumHeight(input_Box::text_h);
        inputField->setMaximumWidth(style::window::default_body_width);
        inputField->setTextType(TextType::SingleLine);
        inputField->setTextEllipsisType(TextEllipsis::Both);
        inputField->setEditMode(EditMode::Edit);
        inputField->setEdges(RectangleEdge::None);
        inputField->setInputMode(new InputMode({InputMode::Abc, InputMode::ABC, InputMode::abc}));
        inputField->setFont(style::window::font::mediumbold);

        if (!icon.empty()) {
            auto imageBox = new ImageBox(horizontalBox, new Image(icon));
            imageBox->setMinimumSizeToFitImage();
            imageBox->activeItem = false; // Prevent switching focus to the image
        }

        verticalBox->resizeItems();

        return inputField;
    }
} // namespace gui