~aleteoryx/muditaos

ref: 4f7ec2efd387c6195288fa9086069c4b30e37aac muditaos/module-apps/application-meditation/widgets/TimerProperty.hpp -rw-r--r-- 1.9 KiB
4f7ec2ef — Lukasz Mastalerz [CP-1831] Editing contact which is deleted via Center can still be saved but with incomplete data 2 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
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include <gui/widgets/Circle.hpp>
#include <gui/widgets/text/Label.hpp>
#include <gui/widgets/Rect.hpp>
#include <gui/widgets/BoxLayout.hpp>

#include <chrono>

namespace gui
{
    class TimerProperty : public Rect
    {
        class State
        {
            static constexpr int counterMaxDigits             = 2;
            static constexpr int minimalValue                 = 1;
            static constexpr int maximalValue                 = 99;
            static constexpr int defaultMeditationTime        = 15;
            static constexpr std::array<const int, 4> timeArr = {15, 30, 60, 90};

            bool resetValueOnNumeric = true;
            int timeInMinutes        = defaultMeditationTime;

          public:
            [[nodiscard]] std::chrono::minutes getTime() const noexcept
            {
                return std::chrono::minutes{timeInMinutes};
            }
            void checkBounds() noexcept;
            void putNumericValue(int digit) noexcept;
            void delNumericValue() noexcept;
            void increment() noexcept;
            void decrement() noexcept;
            void onFocus() noexcept
            {
                resetValueOnNumeric = true;
                checkBounds();
            }
        } state;

        Circle *circle       = nullptr;
        VBox *centerBody     = nullptr;
        Label *timeLabel     = nullptr;
        Rect *divRect        = nullptr;
        Label *timeUnitLabel = nullptr;

        void build();
        void setMeditationTime();

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

        bool onFocus(bool isFocused) final;
        bool onInput(const InputEvent &inputEvent) final;
        [[nodiscard]] std::chrono::minutes getTime() noexcept;
    };

} // namespace gui