~aleteoryx/muditaos

ref: 70d3ba4c03655d7b1e90cbeab88f116bd892e600 muditaos/module-apps/apps-common/popups/WindowWithTimer.hpp -rw-r--r-- 1.3 KiB
70d3ba4c — Dawid Wojtas [BH-1935] Fix the backlight in pre-wake up 1 year, 10 months 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
// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include "AppWindow.hpp"
#include <Timers/TimerHandle.hpp>

namespace gui
{
    class WindowWithTimer : public gui::AppWindow
    {
      public:
        static constexpr auto defaultTimeout  = std::chrono::seconds{3};
        static constexpr auto noTimeoutChange = std::chrono::seconds::zero();

        WindowWithTimer(app::ApplicationCommon *app,
                        const std::string &name,
                        std::chrono::milliseconds timeout = defaultTimeout);
        ~WindowWithTimer() override;

        void destroyInterface() override;
        void onBeforeShow(ShowMode mode, SwitchData *data) override;
        void onClose(CloseReason reason) override;
        bool onInput(const gui::InputEvent &inputEvent) override;

        /// Called before automatic switch to previous window at window's timer timeout.
        void setWindowTimerActionCallback(std::function<void()> &&callback);

      protected:
        void detachTimerIfExists();
        void resetTimer(std::chrono::seconds newTimeout = noTimeoutChange);

      private:
        sys::TimerHandle popupTimer;
        std::chrono::milliseconds timeout;
        std::function<void()> windowTimerActionCallback;
    };
} // namespace gui