~aleteoryx/muditaos

ref: 8370b97cba3c28d9d2c3e670916142de52d6d0d7 muditaos/module-apps/widgets/BarGraph.hpp -rw-r--r-- 1.7 KiB
8370b97c — alek [EGD-5155] Change Timers debug functionality 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
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include <BoxLayout.hpp>
#include <module-gui/gui/widgets/ProgressBar.hpp>

namespace style::bargraph
{
    constexpr inline auto rect_axis_length_sml = 8;
    constexpr inline auto rect_axis_length_lrg = 20;
    constexpr inline auto spacing              = 17;
    constexpr inline auto radius               = 4;
} // namespace style::bargraph

namespace gui
{
    class BarGraph : public Progress
    {
      protected:
        std::vector<gui::Rect *> rectangles;
        uint32_t numberOfRectangles;
        uint32_t currentLevel = 0;

      public:
        Rect *createRectangle(uint32_t width, uint32_t height);

        Rect *createSpace(uint32_t width, uint32_t height);

        void setPercentageValue(unsigned int value) override;
    };

    class VBarGraph : public VBox, public BarGraph
    {
        void incrementWith(uint32_t levels);
        void decrementWith(uint32_t levels);

      public:
        VBarGraph(Item *parent = nullptr, Position x = 0, Position y = 0, uint32_t numberOfRectangles = 0);
        void setMaximum(unsigned int value) final;
        void setValue(unsigned int value) final;
        void update(int value = 1) final;
    };

    class HBarGraph : public HBox, public BarGraph
    {
        void incrementWith(uint32_t levels);
        void decrementWith(uint32_t levels);

      public:
        HBarGraph(Item *parent = nullptr, Position x = 0, Position y = 0, uint32_t numberOfRectangles = 0);
        void setMaximum(unsigned int value) final;
        void setValue(unsigned int value) final;
        void update(int value = 1) final;
    };

} /* namespace gui */