~aleteoryx/muditaos

ref: sign_test muditaos/module-gui/gui/widgets/ProgressBar.hpp -rw-r--r-- 3.9 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
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
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include <cstdint>

#include "Arc.hpp"
#include "Circle.hpp"
#include "Rect.hpp"

namespace gui
{
    class Progress
    {
      public:
        virtual ~Progress() noexcept = default;

        virtual void setMaximum(unsigned int value)         = 0;
        virtual auto setValue(unsigned int value) -> bool   = 0;
        virtual void setPercentageValue(unsigned int value) = 0;
        [[nodiscard]] virtual int getMaximum() const        = 0;
    };

    class ProgressBar : public Rect, public Progress
    {
      public:
        [[deprecated]] ProgressBar(Item *parent, std::uint32_t x, std::uint32_t y, std::uint32_t w, std::uint32_t h);

        void setMaximum(unsigned int value) noexcept override;
        auto setValue(unsigned int value) noexcept -> bool override;
        void setPercentageValue(unsigned int value) noexcept override;
        [[nodiscard]] int getMaximum() const noexcept override;

        void buildDrawListImplementation(std::list<Command> &commands) override;
        bool onDimensionChanged(const BoundingBox &oldDim, const BoundingBox &newDim) override;

      private:
        void createWidgets();

        unsigned int maxValue     = 0U;
        unsigned int currentValue = 0U;
        gui::Rect *fillRect       = nullptr;
    };

    class CircularProgressBar : public Circle, public Progress
    {
      public:
        CircularProgressBar(Item *parent, const Circle::ShapeParams &shape);

        void setMaximum(unsigned int value) noexcept override;
        auto setValue(unsigned int value) noexcept -> bool override;
        void setPercentageValue(unsigned int value) noexcept override;
        [[nodiscard]] int getMaximum() const noexcept override;

        void buildDrawListImplementation(std::list<Command> &commands) override;
        auto onDimensionChanged(const BoundingBox &oldDim, const BoundingBox &newDim) -> bool override;

      private:
        void createWidgets();

        auto calculateProgressIndicatorCenter() const -> Point;
        auto getPercentageValue() const -> float;

        unsigned int maxValue     = 0U;
        unsigned int currentValue = 0U;
        Arc *progressArc          = nullptr;
        Circle *progressIndicator = nullptr;
    };

    class ArcProgressBar : public Arc, public Progress
    {
      public:
        enum class ProgressDirection
        {
            Clockwise,
            CounterClockwise
        };

        enum class ProgressChange
        {
            IncrementFromZero,
            DecrementFromFull
        };

        ArcProgressBar(Item *parent,
                       const Arc::ShapeParams &shape,
                       ProgressDirection direction = ProgressDirection::Clockwise,
                       ProgressChange change       = ProgressChange::IncrementFromZero);

        void setMaximum(unsigned int value) noexcept override;
        auto setValue(unsigned int value) noexcept -> bool override;
        void setPercentageValue(unsigned int value) noexcept override;
        [[nodiscard]] int getMaximum() const noexcept override;

        void buildDrawListImplementation(std::list<Command> &commands) override;
        auto onDimensionChanged(const BoundingBox &oldDim, const BoundingBox &newDim) -> bool override;

      private:
        void createWidgets();

        auto calculateStartIndicatorCenter() const -> Point;
        auto calculateEndIndicatorCenter() const -> Point;
        auto getPercentageValue() const -> float;

        unsigned int maxValue       = 0U;
        unsigned int currentValue   = 0U;

        Arc *progressArc            = nullptr;
        Arc *progressStartIndicator = nullptr;
        Arc *progressEndIndicator   = nullptr;

        ProgressDirection direction = ProgressDirection::Clockwise;
        ProgressChange change       = ProgressChange::IncrementFromZero;
    };
} // namespace gui