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 "widget.hpp"
14#include "../GFX/module.hpp"
15#include "../geometry/module.hpp"
16#include "../chrono.hpp"
17#include "../label.hpp"
18#include "../animator.hpp"
19#include <unordered_set>
20#include <memory>
21#include <mutex>
22
23namespace hi::inline v1 {
24class gfx_device;
25class gfx_system;
26class gfx_surface;
27class gui_system;
28class keyboard_bindings;
29
36public:
37 gui_system& gui;
38
42
44
46
56 aarectangle rectangle;
57
65 mouse_cursor current_mouse_cursor = mouse_cursor::None;
66
71 bool resizing = false;
72
76 bool active = false;
77
82 float dpi = 72.0;
83
86 extent2 widget_size;
87
92
93 gui_window(gui_system& gui, std::unique_ptr<hi::widget> widget, label const& title) noexcept;
94
95 virtual ~gui_window();
96
97 gui_window(gui_window const&) = delete;
98 gui_window& operator=(gui_window const&) = delete;
99 gui_window(gui_window&&) = delete;
100 gui_window& operator=(gui_window&&) = delete;
101
102 void set_device(gfx_device *device) noexcept;
103
106 hi::keyboard_bindings const& keyboard_bindings() const noexcept;
107
111 virtual void render(utc_nanoseconds displayTimePoint);
112
115 virtual void set_cursor(mouse_cursor cursor) = 0;
116
119 virtual void close_window() = 0;
120
126 virtual void set_size_state(gui_window_size state) noexcept = 0;
127
130 virtual aarectangle workspace_rectangle() const noexcept = 0;
131
134 virtual aarectangle fullscreen_rectangle() const noexcept = 0;
135
136 virtual hi::subpixel_orientation subpixel_orientation() const noexcept = 0;
137
140 gui_window_size size_state() const noexcept
141 {
142 return _size_state;
143 }
144
149 virtual void open_system_menu() = 0;
150
153 virtual void set_window_size(extent2 extent) = 0;
154
155 void update_mouse_target(widget_id new_target_widget, point2 position = {}) noexcept;
156
163 void update_keyboard_target(widget_id widget, keyboard_focus_group group = keyboard_focus_group::normal) noexcept;
164
173 void update_keyboard_target(widget_id widget, keyboard_focus_group group, keyboard_focus_direction direction) noexcept;
174
183
191 [[nodiscard]] virtual std::optional<hi::text> get_text_from_clipboard() const noexcept = 0;
192
198 virtual void put_text_on_clipboard(hi::text text) const noexcept = 0;
199
200 [[nodiscard]] translate2 window_to_screen() const noexcept
201 {
202 return translate2{rectangle.left(), rectangle.bottom()};
203 }
204
205 [[nodiscard]] translate2 screen_to_window() const noexcept
206 {
207 return ~window_to_screen();
208 }
209
218 bool process_event(gui_event const& event) noexcept;
219
220protected:
221 static constexpr std::chrono::nanoseconds _animation_duration = std::chrono::milliseconds(150);
222
223 box_constraints _widget_constraints = {};
224
225 std::atomic<aarectangle> _redraw_rectangle = aarectangle{};
226 std::atomic<bool> _relayout = false;
227 std::atomic<bool> _reconstrain = false;
228 std::atomic<bool> _resize = false;
229
232 gui_window_size _size_state = gui_window_size::normal;
233
236 aarectangle _restore_rectangle;
237
245 utc_nanoseconds last_forced_redraw = {};
246
249 animator<float> _animated_active = _animation_duration;
250
251private:
252 notifier<>::callback_token _setting_change_token;
253 observer<std::string>::callback_token _selected_theme_token;
254
259 widget_id _mouse_target_id;
260
264 widget_id _keyboard_target_id;
265
274 bool send_events_to_widget(widget_id target_widget, std::vector<gui_event> const& events) noexcept;
275
276 friend class widget;
277};
278
279} // namespace hi::inline v1
Functionality for labels, text and icons.
Definition of GUI event types.
@ title
Format a heading Often in bold, larger font and on a line by itself.
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 rectangle / parallelogram in 3D space.
Definition rectangle.hpp:20
Definition translate.hpp:15
Definition gfx_device.hpp:20
Graphics system.
Definition gui_system.hpp:27
Definition gui_window.hpp:35
hi::keyboard_bindings const & keyboard_bindings() const noexcept
Get the keyboard binding.
std::unique_ptr< widget > widget
The widget covering the complete window.
Definition gui_window.hpp:41
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.
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.
aarectangle rectangle
The current rectangle of the window relative to the screen.
Definition gui_window.hpp:56
extent2 widget_size
The size of the widget.
Definition gui_window.hpp:86
notifier< void()> closing
Notifier used when the window is closing.
Definition gui_window.hpp:91
virtual void set_window_size(extent2 extent)=0
Ask the operating system to set the size of this window.
bool process_event(gui_event const &event) noexcept
Process the event.
virtual std::optional< hi::text > get_text_from_clipboard() const noexcept=0
Get text from the clipboard.
A label consisting of localizable text and an icon.
Definition label.hpp:114
A notifier which can be used to call a set of registered callbacks.
Definition notifier.hpp:25