~aleteoryx/muditaos

ref: 29f455d46bbddee9a8f0ea860e84c9b6e5ab38b5 muditaos/module-apps/apps-common/widgets/InputBox.cpp -rw-r--r-- 3.4 KiB
29f455d4 — Przemyslaw Brudny [EGD-7998] Pure image assets cleanup and update 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
// Copyright (c) 2017-2021, 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 <Image.hpp>

namespace gui
{
    constexpr uint32_t default_x = style::window::default_left_margin;
    constexpr uint32_t default_w =
        style::window_width - style::window::default_left_margin - style::window::default_right_margin;
    namespace inputHeader
    {
        constexpr uint32_t x = style::window::default_left_margin;
        constexpr uint32_t y = 127;
        constexpr uint32_t w = default_w;
        constexpr uint32_t h = 20;
    } // namespace inputHeader

    namespace horizontalBox
    {
        constexpr uint32_t x        = style::window::default_left_margin;
        constexpr uint32_t y        = 153;
        constexpr uint32_t w        = default_w;
        constexpr uint32_t h        = 34;
        constexpr uint32_t penWidth = 2;
        namespace searchTop
        {
            constexpr uint32_t x = default_w;
            constexpr uint32_t y = 1;
            constexpr uint32_t w = 32;
            constexpr uint32_t h = 32;
        } // namespace searchTop
        namespace inputField
        {
            constexpr uint32_t x = 1;
            constexpr uint32_t y = 1;
            constexpr uint32_t w = default_w - searchTop::w;
            constexpr uint32_t h = 33;
        } // namespace inputField
    }     // namespace horizontalBox
} // namespace gui

namespace gui
{

    auto inputBox(gui::Item *parent, const std::string &header, const std::string &icon) -> gui::Text *
    {
        auto inputField = new Text(nullptr,
                                   horizontalBox::inputField::x,
                                   horizontalBox::inputField::y,
                                   horizontalBox::inputField::w,
                                   horizontalBox::inputField::h);
        inputField->setTextType(TextType::SingleLine);
        inputField->setEditMode(EditMode::Edit);
        inputField->setEdges(RectangleEdge::None);
        inputField->setInputMode(new InputMode({InputMode::ABC, InputMode::abc}));
        inputField->setFont(style::window::font::mediumbold);

        auto horizontalBox = new HBox(parent, horizontalBox::x, horizontalBox::y, horizontalBox::w, horizontalBox::h);
        horizontalBox->addWidget(inputField);
        if (!icon.empty()) {
            horizontalBox->addWidget(new Image(nullptr,
                                               horizontalBox::searchTop::x,
                                               horizontalBox::searchTop::y,
                                               horizontalBox::searchTop::w,
                                               horizontalBox::searchTop::h,
                                               icon));
        }

        horizontalBox->setPenWidth(horizontalBox::penWidth);
        horizontalBox->setEdges(RectangleEdge::Bottom);

        const RectangleEdge edges = RectangleEdge::None;
        const Alignment alignment = Alignment(gui::Alignment::Horizontal::Left, gui::Alignment::Vertical::Bottom);
        auto l                    = new Label(parent, inputHeader::x, inputHeader::y, inputHeader::w, inputHeader::h);

        l->setFont(style::window::font::small);
        l->setEdges(edges);
        l->setText(header);
        l->setAlignment(alignment);

        return inputField;
    }
} // namespace gui