~aleteoryx/muditaos

ref: e8fd36cdae716250db936b165fd657c065a7a3da muditaos/module-apps/application-meditation/widgets/IntervalBox.hpp -rw-r--r-- 1.9 KiB
e8fd36cd — Paweł Joński [BH-936] Add Polish translation to Bell 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// 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 <gui/widgets/BoxLayout.hpp>
#include <gui/widgets/Image.hpp>
#include <gui/widgets/Label.hpp>

#include <list>
#include <chrono>

namespace gui
{
    class TimerProperty;

    class IntervalBox : public BoxLayout
    {
        class ChimeIntervalList
        {
            std::vector<std::chrono::minutes> intervals;
            std::vector<std::chrono::minutes>::const_iterator current;

          public:
            enum class Direction
            {
                Next,
                Previous
            };

            ChimeIntervalList();

            [[nodiscard]] std::chrono::minutes getCurrent() const noexcept
            {
                return *current;
            }

            bool moveToNext(Direction dir, std::chrono::minutes meditationTime) noexcept;
            [[nodiscard]] bool hasNext(Direction dir, std::chrono::minutes meditationTime) const noexcept;

            [[nodiscard]] static std::string toPrintableInterval(std::chrono::minutes time);
        } chimeIntervals;

        TimerProperty *timerSetter = nullptr;
        Label *bottomLabel      = nullptr;
        Image *leftSwitchArrow  = nullptr;
        Image *rightSwitchArrow = nullptr;

        std::chrono::minutes intervalValue{0};

        void build();
        void updateIntervals(ChimeIntervalList::Direction dir);
        void rescaleIntervals();

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

        bool onFocus(bool isFocused) final;
        bool onInput(const InputEvent &inputEvent) final;
        [[nodiscard]] std::chrono::seconds getIntervalValue() const noexcept
        {
            return std::chrono::seconds{intervalValue};
        }
    };
} // namespace gui