HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
gui_window.hpp
1// Copyright Take Vos 2019-2022.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7#include "gui_window_size.hpp"
8#include "mouse_cursor.hpp"
9#include "hitbox.hpp"
10#include "gui_event.hpp"
11#include "keyboard_focus_direction.hpp"
12#include "keyboard_focus_group.hpp"
13#include "theme.hpp"
14#include "widget_intf.hpp"
15#include "../unicode/module.hpp"
16#include "../GFX/module.hpp"
17#include "../geometry/module.hpp"
18#include "../time/module.hpp"
19#include "../label.hpp"
20#include "../animator.hpp"
21#include <unordered_set>
22#include <memory>
23#include <mutex>
24
25namespace hi::inline v1 {
26class gfx_device;
27class gfx_system;
28class gfx_surface;
29class gui_system;
30class keyboard_bindings;
31
38public:
39 gui_system& gui;
40
42
52 aarectangle rectangle;
53
61 mouse_cursor current_mouse_cursor = mouse_cursor::None;
62
67 bool resizing = false;
68
72 bool active = false;
73
78 float dpi = 72.0;
79
83 hi::theme theme = {};
84
87 extent2 widget_size;
88
93
94 gui_window(gui_system& gui, std::unique_ptr<widget_intf> widget) noexcept : gui(gui), _widget(std::move(widget)) {}
95
96 virtual ~gui_window();
97
98 gui_window(gui_window const&) = delete;
99 gui_window& operator=(gui_window const&) = delete;
100 gui_window(gui_window&&) = delete;
101 gui_window& operator=(gui_window&&) = delete;
102
103 void set_device(gfx_device *device) noexcept;
104
107 hi::keyboard_bindings const& keyboard_bindings() const noexcept;
108
112 virtual void render(utc_nanoseconds displayTimePoint);
113
114 template<typename Widget>
115 [[nodiscard]] Widget& widget() const noexcept
116 {
117 return up_cast<Widget>(*_widget);
118 }
119
120 virtual void set_title(label title) noexcept
121 {
122 _title = std::move(title);
123 }
124
127 virtual void set_cursor(mouse_cursor cursor) = 0;
128
131 virtual void close_window() = 0;
132
138 virtual void set_size_state(gui_window_size state) noexcept = 0;
139
142 virtual aarectangle workspace_rectangle() const noexcept = 0;
143
146 virtual aarectangle fullscreen_rectangle() const noexcept = 0;
147
148 virtual hi::subpixel_orientation subpixel_orientation() const noexcept = 0;
149
152 gui_window_size size_state() const noexcept
153 {
154 return _size_state;
155 }
156
161 virtual void open_system_menu() = 0;
162
165 virtual void set_window_size(extent2 extent) = 0;
166
167 void update_mouse_target(widget_id new_target_widget, point2 position = {}) noexcept;
168
175 void update_keyboard_target(widget_id widget, keyboard_focus_group group = keyboard_focus_group::normal) noexcept;
176
185 void update_keyboard_target(widget_id widget, keyboard_focus_group group, keyboard_focus_direction direction) noexcept;
186
195
203 [[nodiscard]] virtual std::optional<gstring> get_text_from_clipboard() const noexcept = 0;
204
210 virtual void put_text_on_clipboard(gstring_view text) const noexcept = 0;
211
212 [[nodiscard]] translate2 window_to_screen() const noexcept
213 {
214 return translate2{rectangle.left(), rectangle.bottom()};
215 }
216
217 [[nodiscard]] translate2 screen_to_window() const noexcept
218 {
219 return ~window_to_screen();
220 }
221
230 bool process_event(gui_event const& event) noexcept;
231
232protected:
233 static constexpr std::chrono::nanoseconds _animation_duration = std::chrono::milliseconds(150);
234
237 label _title;
238
242
243 box_constraints _widget_constraints = {};
244
245 std::atomic<aarectangle> _redraw_rectangle = aarectangle{};
246 std::atomic<bool> _relayout = false;
247 std::atomic<bool> _reconstrain = false;
248 std::atomic<bool> _resize = false;
249
252 gui_window_size _size_state = gui_window_size::normal;
253
256 aarectangle _restore_rectangle;
257
265 utc_nanoseconds last_forced_redraw = {};
266
269 animator<float> _animated_active = _animation_duration;
270
274 virtual void create_window(extent2 new_size) = 0;
275
276private:
281 widget_id _mouse_target_id;
282
286 widget_id _keyboard_target_id;
287
296 bool send_events_to_widget(widget_id target_widget, std::vector<gui_event> const& events) noexcept;
297
298 friend class widget;
299};
300
301} // namespace hi::inline v1
Functionality for labels, text and icons.
Definition of GUI event types.
DOXYGEN BUG.
Definition algorithm.hpp:13
subpixel_orientation
The orientation of the RGB sub-pixels of and LCD/LED panel.
Definition subpixel_orientation.hpp:18
keyboard_focus_direction
The keyboard focus group used for finding a widget that will accept a particular focus.
Definition keyboard_focus_direction.hpp:11
keyboard_focus_group
The keyboard focus group used for finding a widget that will accept a particular focus.
Definition keyboard_focus_group.hpp:11
geometry/margins.hpp
Definition cache.hpp:11
A high-level geometric point Part of the high-level vec, point, mat and color types.
Definition point2.hpp:23
Definition gfx_device.hpp:20
Graphics system.
Definition gui_system.hpp:31
Definition gui_window.hpp:37
hi::keyboard_bindings const & keyboard_bindings() const noexcept
Get the keyboard binding.
virtual void set_cursor(mouse_cursor cursor)=0
Set the mouse cursor icon.
virtual void open_system_menu()=0
Open the system menu of the window.
void update_keyboard_target(keyboard_focus_group group, keyboard_focus_direction direction) noexcept
Change the keyboard focus to the given, previous or next widget.
void update_keyboard_target(widget_id widget, keyboard_focus_group group=keyboard_focus_group::normal) noexcept
Change the keyboard focus to the given widget.
virtual std::optional< gstring > get_text_from_clipboard() const noexcept=0
Get text from the clipboard.
void update_keyboard_target(widget_id widget, keyboard_focus_group group, keyboard_focus_direction direction) noexcept
Change the keyboard focus to the previous or next widget from the given widget.
virtual void set_size_state(gui_window_size state) noexcept=0
Set the size-state of the window.
aarectangle rectangle
The current rectangle of the window relative to the screen.
Definition gui_window.hpp:52
extent2 widget_size
The size of the widget.
Definition gui_window.hpp:87
notifier< void()> closing
Notifier used when the window is closing.
Definition gui_window.hpp:92
virtual void close_window()=0
Ask the operating system to close this window.
virtual void set_window_size(extent2 extent)=0
Ask the operating system to set the size of this window.
virtual aarectangle workspace_rectangle() const noexcept=0
The rectangle of the workspace of the screen where the window is currently located.
bool process_event(gui_event const &event) noexcept
Process the event.
Definition theme.hpp:21
A variant of text.
Definition label.hpp:31
A label consisting of localizable text and an icon.
Definition label.hpp:112
A notifier which can be used to call a set of registered callbacks.
Definition notifier.hpp:25
T move(T... args)