~aleteoryx/muditaos

ref: 661d20329730b1399e4aab17c4619076cb6e229a muditaos/module-gui/gui/widgets/TopBar.hpp -rw-r--r-- 3.5 KiB
661d2032 — Marcin Smoczyński add changelog for v0.54.2 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
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
117
118
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#ifndef MODULE_GUI_GUI_WIDGETS_TOPBAR_HPP_
#define MODULE_GUI_GUI_WIDGETS_TOPBAR_HPP_

#include "Image.hpp"
#include "Label.hpp"
#include "Rect.hpp"
#include "TopBar/SIM.hpp"
#include <common_data/EventStore.hpp>
#include <map>

namespace gui
{

    static const uint32_t batteryBarsCount  = 6;
    static const uint32_t signalImgCount    = 6;

    /// Header of most of design Windows
    ///
    /// Provides way to show:
    ///    0. Window title
    ///    1. battery state
    ///    2. signal
    ///    3. time
    ///    4. sim state
    /// in separate areas, when enabled
    ///
    ///              [time]
    /// [signal]    [title ] [sim] [battery]
    class TopBar : public Rect
    {
        static const uint32_t signalOffset;
        static const uint32_t batteryOffset;

      public:
        enum class Elements
        {
            SIGNAL = 0x01,
            LOCK,
            BATTERY,
            TIME,
            SIM,
            NETWORK_ACCESS_TECHNOLOGY
        };
        enum class TimeMode
        {
            TIME_12H,
            TIME_24H
        };
        static uint32_t time;

      protected:
        Label *timeLabel                    = nullptr;
        Label *networkAccessTechnologyLabel = nullptr;
        Image *signal[static_cast<size_t>(Store::RssiBar::noOfSupprtedBars)];
        Image *lock;
        std::array<Image *, batteryBarsCount> batteryBars               = {nullptr};
        std::map<const Store::Battery::State, Image *> batteryChargings = {
            {Store::Battery::State::Charging, nullptr}, {Store::Battery::State::PluggedNotCharging, nullptr}};
        gui::SIM *sim = nullptr;
        void prepareWidget();
        static TimeMode timeMode;

        /// show bars in number - 0 bars, 1 bar, 2 bars...
        void batteryShowBars(uint32_t val);

        /// elements shown on TopBar
        struct
        {
            bool signal : 1;
            bool lock : 1;
            bool battery : 1;
            bool time : 1;
            bool sim : 1;
            bool networkAccessTechnology : 1;
        } elements = {false, false, false, false, true, true};

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

        /**
         * @brief Hides or shows images.
         * @note LOCK and TIME are located in the same place so only 1 can be active at the same time.
         */
        void setActive(TopBar::Elements element, bool active);
        void setActive(std::list<std::pair<TopBar::Elements, bool>> elements);
        /**
         * @brief Sets charge level of the battery based on percent value. This will cause appropriate image to be
         * displayed.
         * @return if display should be refreshed or not
         */
        bool updateBattery(uint32_t percent);
        bool updateBattery(bool plugged);
        void showBattery(bool shown);

        /**
         * @brief updates signal strength. This will cause appropriate image to be displayed.
         */
        bool updateSignalStrength();

        bool updateNetworkAccessTechnology();

        void simSet();
        void setTime(const UTF8 &time);
        void setTime(const uint32_t &time, bool mode24H);
        UTF8 getTimeString();
        uint32_t getTime()
        {
            return time;
        };
        void accept(GuiVisitor &visitor) override;
    };

} /* namespace gui */

#endif /* MODULE_GUI_GUI_WIDGETS_TOPBAR_HPP_ */