~aleteoryx/muditaos

ref: 8e6490863a74d30442b434f91b90a2f07095e2d3 muditaos/module-gui/gui/widgets/TextSpinner.hpp -rw-r--r-- 1.4 KiB
8e649086 — Mateusz Grzegorzek [BH-395] Librarize application-settings 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 "Text.hpp"

#include <string>
#include <vector>

namespace gui
{
    class TextSpinner : public Text
    {
      public:
        using TextRange = std::vector<std::string>;
        using Position  = std::uint32_t;
        using Range     = std::pair<Position, Position>;

        TextSpinner() = delete;
        TextSpinner(const TextRange &range, Boundaries boundaries);

        /// Sets range of strings to spin over
        void setTextRange(const TextRange &range);
        /// Sets current position. Must be within valid @ref Range that can be checked by @ref getValidRange
        void setCurrentPosition(Position pos);

        [[nodiscard]] std::string getCurrentText() const noexcept;
        [[nodiscard]] Range getValidRange() const noexcept;

        void stepUp();
        void stepDown();

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

      private:
        TextRange textRange;
        Position currentPosition = 0;
        Boundaries boundaries    = Boundaries::Continuous;

        void update();
        Position getRangeUpLimit() const;
        Position getRangeDownLimit() const;
    };
} // namespace gui