~aleteoryx/muditaos

ref: sign_test muditaos/module-gui/gui/widgets/Window.hpp -rw-r--r-- 3.0 KiB
a217eeb3 — Dawid Wojtas [BH-2024] Fix lack of alarm directory after updating software 1 year, 5 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
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// 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 <list>
#include "Item.hpp"
#include "Common.hpp"
#include "SwitchData.hpp"

namespace gui
{
    /// Base window for all UI windows
    ///
    /// It consists of:
    /// 1. StatusBar
    /// 2. Header
    /// 3. Body
    /// 4. NavBar
    /// More in WINDOW.md
    ///
    /// All window switches are done based on Window::name and SwitchData
    /// All windows are statically build at start of application, and removed on application end
    /// To rebuild window one have to:
    ///     1. set navigationItem to nullptr (othervise window will crash trying to execute focus callback on reomved
    ///     element)
    ///     2. Remove elements
    ///     3. Add elements anew
    /// or:
    ///     2. handle elements update
    class Window : public Item
    {
      protected:
        /// name of window used for windows switching
        std::string name;

      public:
        enum class CloseReason
        {
            ApplicationClose,
            WindowSwitch,
            PhoneLock,
            Popup
        };

        Window() = delete;
        explicit Window(std::string name);

        /// run every time in Application prior to showing window, except for when we came back to first window with no
        /// switch data to show
        /// @note this is most likely being duplicated by handleSwitchData
        virtual void onBeforeShow(ShowMode mode, SwitchData *data);
        virtual void onClose(CloseReason reason);
        virtual void getRefreshArea(uint16_t &x, uint16_t &y, uint16_t &w, uint16_t &h);

        /// run prior to onBeforeShow
        /// @note this is most likely duplicate of onBeforeShow
        virtual bool handleSwitchData(SwitchData *data);

        /// This method rebuilds window using updated phone's settings. Internal state must be preserved.
        virtual void rebuild() = 0;
        /// Method to build window's interface
        virtual void buildInterface() = 0;
        /// Method to remove window's interface
        virtual void destroyInterface() = 0;

        // virtual methods from Item
        bool onInput(const InputEvent &inputEvent) override;
        void accept(GuiVisitor &visitor) override;

        void buildDrawListImplementation(std::list<Command> &commands) override;

        /// used for window switching purposes
        std::string getName()
        {
            return name;
        };

        /// function to set name - some windows have different name set in
        /// - builder
        /// - actual window name
        [[deprecated]] void setName(const std::string &name)
        {
            this->name = name;
        }

        /// used for fetching unique name of window
        virtual std::string getUniqueName()
        {
            return name;
        }

        /// used for get info about any unsaved user data changes
        virtual bool isAnyUnsavedUserDataInWindow() const
        {
            return false;
        }
    };
} /* namespace gui */