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"
19#include "../chrono.hpp"
20#include "../label.hpp"
21#include "../animator.hpp"
22#include <unordered_set>
23#include <memory>
24#include <mutex>
25
26namespace hi::inline v1 {
27class gfx_device;
28class gfx_system;
29class gfx_surface;
30class gui_system;
31class keyboard_bindings;
32
39public:
40 gui_system& gui;
41
43
53 aarectanglei rectangle;
54
62 mouse_cursor current_mouse_cursor = mouse_cursor::None;
63
68 bool resizing = false;
69
73 bool active = false;
74
75 label title;
76
81 float dpi = 72.0;
82
86 hi::theme theme = {};
87
90 extent2i widget_size;
91
95
100
101 gui_window(gui_system& gui, label const& title) noexcept;
102
103 virtual ~gui_window();
104
105 gui_window(gui_window const&) = delete;
106 gui_window& operator=(gui_window const&) = delete;
107 gui_window(gui_window&&) = delete;
108 gui_window& operator=(gui_window&&) = delete;
109
116 virtual void init();
117
118 void set_device(gfx_device *device) noexcept;
119
122 hi::keyboard_bindings const& keyboard_bindings() const noexcept;
123
127 virtual void render(utc_nanoseconds displayTimePoint);
128
133 [[nodiscard]] grid_widget& content() noexcept
134 {
135 hi_axiom(loop::main().on_thread());
136 hi_assert_not_null(widget);
137 return widget->content();
138 }
139
144 [[nodiscard]] toolbar_widget& toolbar() noexcept
145 {
146 hi_axiom(loop::main().on_thread());
147 hi_assert_not_null(widget);
148 return widget->toolbar();
149 }
150
153 virtual void set_cursor(mouse_cursor cursor) = 0;
154
157 virtual void close_window() = 0;
158
164 virtual void set_size_state(gui_window_size state) noexcept = 0;
165
168 virtual aarectanglei workspace_rectangle() const noexcept = 0;
169
172 virtual aarectanglei fullscreen_rectangle() const noexcept = 0;
173
174 virtual hi::subpixel_orientation subpixel_orientation() const noexcept = 0;
175
178 gui_window_size size_state() const noexcept
179 {
180 return _size_state;
181 }
182
187 virtual void open_system_menu() = 0;
188
191 virtual void set_window_size(extent2i extent) = 0;
192
193 void update_mouse_target(hi::widget const *new_target_widget, point2i position = {}) noexcept;
194
201 void update_keyboard_target(hi::widget const *widget, keyboard_focus_group group = keyboard_focus_group::normal) noexcept;
202
211 void
213
222
230 [[nodiscard]] virtual std::optional<std::string> get_text_from_clipboard() const noexcept = 0;
231
237 virtual void put_text_on_clipboard(std::string_view text) const noexcept = 0;
238
239 [[nodiscard]] translate2i window_to_screen() const noexcept
240 {
241 return translate2i{rectangle.left(), rectangle.bottom()};
242 }
243
244 [[nodiscard]] translate2i screen_to_window() const noexcept
245 {
246 return ~window_to_screen();
247 }
248
257 bool process_event(gui_event const& event) noexcept;
258
259protected:
260 static constexpr std::chrono::nanoseconds _animation_duration = std::chrono::milliseconds(150);
261
262 box_constraints _widget_constraints = {};
263
264 std::atomic<aarectanglei> _redraw_rectangle = aarectanglei{};
265 std::atomic<bool> _relayout = false;
266 std::atomic<bool> _reconstrain = false;
267 std::atomic<bool> _resize = false;
268
271 gui_window_size _size_state = gui_window_size::normal;
272
275 aarectanglei _restore_rectangle;
276
284 utc_nanoseconds last_forced_redraw = {};
285
288 animator<float> _animated_active = _animation_duration;
289
293 virtual void create_window(extent2i new_size) = 0;
294
295private:
296 notifier<>::callback_token _setting_change_token;
297 observer<std::string>::callback_token _selected_theme_token;
298
303 std::weak_ptr<hi::widget const> _mouse_target_widget;
304
308 std::weak_ptr<hi::widget const> _keyboard_target_widget;
309
318 bool send_events_to_widget(hi::widget const *target_widget, std::vector<gui_event> const& events) noexcept;
319
320 friend class widget;
321};
322
323} // namespace hi::inline v1
#define hi_axiom(expression,...)
Specify an axiom; an expression that is true.
Definition assert.hpp:133
#define hi_assert_not_null(x,...)
Assert if an expression is not nullptr.
Definition assert.hpp:118
Functionality for labels, text and icons.
Defines toolbar_widget.
Defines window_widget.
Defines grid_widget.
Definition of GUI event types.
STL namespace.
DOXYGEN BUG.
Definition algorithm.hpp:15
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 assert.hpp:18
A rectangle / parallelogram in 3D space.
Definition rectangle.hpp:20
Definition translate.hpp:15
Definition gfx_device.hpp:22
Graphics system.
Definition gui_system.hpp:29
Definition gui_window.hpp:38
hi::keyboard_bindings const & keyboard_bindings() const noexcept
Get the keyboard binding.
void update_keyboard_target(hi::widget const *widget, keyboard_focus_group group=keyboard_focus_group::normal) noexcept
Change the keyboard focus to the given widget.
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.
virtual aarectanglei workspace_rectangle() const noexcept=0
The rectangle of the workspace of the screen where the window is currently located.
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(hi::widget const *widget, keyboard_focus_group group, keyboard_focus_direction direction) noexcept
Change the keyboard focus to the previous or next widget from the given widget.
aarectanglei rectangle
The current rectangle of the window relative to the screen.
Definition gui_window.hpp:53
virtual void set_window_size(extent2i extent)=0
Ask the operating system to set the size of this window.
toolbar_widget & toolbar() noexcept
Get a reference to window's toolbar widget.
Definition gui_window.hpp:144
virtual void set_size_state(gui_window_size state) noexcept=0
Set the size-state of the window.
virtual std::optional< std::string > get_text_from_clipboard() const noexcept=0
Get text from the clipboard.
std::shared_ptr< window_widget > widget
The widget covering the complete window.
Definition gui_window.hpp:94
virtual void init()
2 phase constructor.
notifier< void()> closing
Notifier used when the window is closing.
Definition gui_window.hpp:99
virtual void close_window()=0
Ask the operating system to close this window.
extent2i widget_size
The size of the widget.
Definition gui_window.hpp:90
bool process_event(gui_event const &event) noexcept
Process the event.
Definition theme.hpp:23
A variant of text.
Definition label.hpp:36
A label consisting of localizable text and an icon.
Definition label.hpp:124
A notifier which can be used to call a set of registered callbacks.
Definition notifier.hpp:26
An interactive graphical object as part of the user-interface.
Definition widget.hpp:46