~aleteoryx/muditaos

ref: c8e65453c5b2ce03a7f87609ed1a729dddc470de muditaos/module-gui/gui/widgets/Spinner.hpp -rw-r--r-- 1.5 KiB
c8e65453 — Mateusz Piesta [BH-891] Alarm popup fix 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
// 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 "TextFixedSize.hpp"

namespace gui
{
    class Spinner : public TextFixedSize
    {
      public:
        using OnUpdateCallback = std::function<void(int _currentValue)>;
        Spinner(int minValue, int maxValue, int step, Boundaries boundaries, OnUpdateCallback cb = nullptr);

        void setCurrentValue(int newCurrent);
        void setFixedFieldWidth(unsigned char newFixedFieldWidth);

        void setMinValue(int newMinValue);
        void setMaxValue(int newMaxValue);
        void setFocusEdges(RectangleEdge edges);

        [[nodiscard]] int getCurrentValue() const noexcept;
        [[nodiscard]] unsigned char getFixedFieldWidth() const noexcept;

        void stepUp();
        void stepDown();

        // virtual methods from Item
        bool onInput(const InputEvent &inputEvent) override;
        bool onFocus(bool state) override;

      private:
        int minValue;
        int maxValue;
        int step;
        int currentValue;
        Boundaries boundaries         = Boundaries::Continuous;
        unsigned char fixedFieldWidth = 0; ///< defines number of chars always displayed,
        ///< if current < fixedFieldWidth Label will be filled with 0
        ///< value of 0 means no fixed width.
        RectangleEdge focusEdges = RectangleEdge::Bottom;
        void updateSpinner();

        OnUpdateCallback onUpdate{nullptr};
    };
} // namespace gui