~aleteoryx/muditaos

ref: e478d06ad1b0a4ea62bf0c34f1be4cea7fbe7e67 muditaos/module-apps/apps-common/widgets/ProgressTimer.hpp -rw-r--r-- 1.9 KiB
e478d06a — Mateusz Grzegorzek [BH-823] Pre-wake up settings - part II 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
// 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 <chrono>
#include <functional>

namespace gui
{
    class Text;
    class Progress;
} // namespace gui

namespace app
{
    class ProgressTimerUIConfigurator
    {

      public:
        virtual ~ProgressTimerUIConfigurator()       = default;
        virtual void attach(gui::Progress *progress) = 0;
        virtual void attach(gui::Text *clock)        = 0;
    };

    /** ProgressTimer provides an interface that connect Timer's features to UI representation.
     * The Timer's features consists of:
     * 1) counting time down,
     * 2) ability to perform action (via onIntervalCallback) periodically on reaching an interval
     * 3) ability to perform action (via onFinishedCallback) on reaching countdown end.
     * The UI representation consist of:
     * 1) ability to present time left on attached Text
     * 2) ability to present timer's progress on attached class realising Progress interface.
     */
    class ProgressTimer : public ProgressTimerUIConfigurator
    {
      public:
        [[nodiscard]] virtual auto isStopped() const noexcept -> bool                    = 0;
        virtual void reset(std::chrono::seconds duration,
                           std::chrono::seconds interval = std::chrono::seconds::zero()) = 0;
        virtual void start()                                                             = 0;
        virtual void stop()                                                              = 0;
        virtual void registerOnFinishedCallback(std::function<void()> cb)                = 0;
        virtual void registerOnIntervalCallback(std::function<void()> cb)                = 0;

        virtual void attach(gui::Progress *progress) = 0;
        virtual void attach(gui::Text *text)         = 0;
    };

} // namespace app