1.10
popup.h
1/*
2 * Copyright (C) 2018 Microchip Technology Inc. All rights reserved.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6#ifndef EGT_POPUP_H
7#define EGT_POPUP_H
8
14#include <egt/app.h>
15#include <egt/window.h>
16
17namespace egt
18{
19inline namespace v1
20{
21
28template <class T>
29class PopupType : public T
30{
31public:
32
37 explicit PopupType(const Size& size = {},
38 const Point& point = {}) noexcept
39 : T(size)
40 {
41 this->move(point);
42 }
43
44 explicit PopupType(Serializer::Properties& props) noexcept
45 : PopupType(props, false)
46 {
47 }
48
49protected:
50
51 explicit PopupType(Serializer::Properties& props, bool is_derived) noexcept
52 : T(props, true)
53 {
54 if (!is_derived)
55 T::deserialize_leaf(props);
56 }
57
58public:
59
66 virtual void show_centered()
67 {
68 this->zorder_top();
69
70 if (T::parent())
71 this->move_to_center(T::parent()->box().center());
72 else
73 this->move_to_center(Application::instance().screen()->box().center());
74
75 T::show();
76 }
77
84 virtual void show_modal(bool center = false)
85 {
86 if (!Application::instance().modal_window())
87 {
88 Application::instance().set_modal_window(this);
89
90 this->zorder_top();
91
92 if (center)
93 this->show_centered();
94 else
95 this->show();
96 }
97 }
98
104 void show() override
105 {
106 this->zorder_top();
107
108 T::show();
109 }
110
118 void hide() override
119 {
120 T::hide();
121
122 if (Application::instance().modal_window() == this)
123 {
124 Application::instance().set_modal_window(nullptr);
125 }
126 }
127};
128
133
134}
135}
136
137#endif
static Application & instance()
Reference to the main Application instance.
Popup window.
Definition popup.h:30
PopupType(const Size &size={}, const Point &point={}) noexcept
Definition popup.h:37
virtual void show_modal(bool center=false)
Show the window in modal mode.
Definition popup.h:84
void hide() override
Hide the Widget.
Definition popup.h:118
virtual void show_centered()
Show the window centered.
Definition popup.h:66
void show() override
Show the Widget.
Definition popup.h:104
PopupType(Serializer::Properties &props) noexcept
Definition popup.h:44
PopupType(Serializer::Properties &props, bool is_derived) noexcept
Definition popup.h:51
std::list< std::tuple< std::string, std::string, Serializer::Attributes > > Properties
Definition serialize.h:47
T & center(T &widget)
Helper to set alignment of a widget.
Definition widgetflags.h:416
EGT framework namespace.
Definition animation.h:24