~aleteoryx/muditaos

ref: sign_test muditaos/module-gui/gui/widgets/NavBar.hpp -rw-r--r-- 2.4 KiB
a217eeb3 — Dawid Wojtas [BH-2024] Fix lack of alarm directory after updating software 1 year, 5 months 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
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include <ThreeBox.hpp>
#include <Label.hpp>
#include <utf8/UTF8.hpp>

namespace gui::nav_bar
{
    enum class Side
    {
        Left,
        Center,
        Right
    };

    /// Footer for most design windows
    ///
    /// Consists of 3 areas right now `[ left  ] [ center ] [ right ]`
    /// these areas most of times inform user about possibility to execute action with keys
    /// left is left action key, center describes center (enter) key, and right right action key
    /// depending on screen selected elements will be visible
    /// @note when in Text widget it will show input mode if enabled in [ left ] area
    class NavBar : public HThreeBox<HBox, HBox, HBox>
    {
      protected:
        struct Cache
        {
          private:
            struct
            {
                bool isVisible = false;
                UTF8 text;
                bool stored = false;
            } left, center, right;

          public:
            auto get(Side side) -> auto &
            {
                switch (side) {
                case Side::Left:
                    return left;
                case Side::Right:
                    return right;
                case Side::Center:
                    return center;
                }
                return left;
            }
        } cache;

        Label *left   = nullptr;
        Label *center = nullptr;
        Label *right  = nullptr;
        void createLabels();

        void setLeftSideWidth(Length width);
        void setRightSideWidth(Length width);
        bool checkSideOccupied(nav_bar::Side side);
        Length outerSideUsedWidth(nav_bar::Side side);
        void applyOuterSidesWidth(nav_bar::Side side, const UTF8 &str);
        Label *getSide(nav_bar::Side side);

      public:
        NavBar(Item *parent, uint32_t x, uint32_t y, uint32_t w, uint32_t h);

        void setActive(nav_bar::Side side, bool active);
        bool isActive(nav_bar::Side side);
        void setText(nav_bar::Side side, const UTF8 &str, bool active = true);
        UTF8 getText(nav_bar::Side side);
        void setFont(Side side, const UTF8 &fontName);

        void store();
        void store(Side side);
        void restore();
        void restore(Side side);

        void accept(GuiVisitor &visitor) override;
    };

} // namespace gui::nav_bar