HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
gui_system.hpp
1// Copyright Take Vos 2020-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.hpp"
8#include "gui_window_win32.hpp"
9#include "gui_system_delegate.hpp"
10#include "../unicode/unicode_bidi_class.hpp"
11#include "../GFX/gfx_device.hpp"
12#include "../thread.hpp"
13#include "../unfair_recursive_mutex.hpp"
14#include "../observer.hpp"
15#include <span>
16#include <memory>
17#include <mutex>
18#include <thread>
19#include <vector>
20
21namespace hi::inline v1 {
22class gfx_system;
23class vertical_sync;
24class font_book;
25class theme_book;
26class keyboard_bindings;
27
31public:
32 static inline os_handle instance;
33
38
39 thread_id const thread_id;
40
51 unicode_bidi_class writing_direction = unicode_bidi_class::L;
52
55 observer<std::string> selected_theme = "default";
56
66
67 virtual ~gui_system();
68
69 gui_system(const gui_system &) = delete;
70 gui_system &operator=(const gui_system &) = delete;
71 gui_system(gui_system &&) = delete;
72 gui_system &operator=(gui_system &&) = delete;
73
77 virtual void init() noexcept
78 {
79 if (auto delegate = _delegate.lock()) {
80 delegate->init(*this);
81 }
82 }
83
84 virtual void deinit() noexcept
85 {
86 if (auto delegate = _delegate.lock()) {
87 delegate->deinit(*this);
88 }
89 }
90
91 void set_delegate(std::weak_ptr<gui_system_delegate> delegate) noexcept
92 {
93 _delegate = std::move(delegate);
94 }
95
97
103 template<typename... Args>
105 {
106 hi_axiom(is_gui_thread());
107
108 // XXX abstract away the _win32 part.
109 auto window = std::make_shared<gui_window_win32>(*this, std::forward<Args>(args)...);
110 window->init();
111
112 return add_window(std::move(window));
113 }
114
117 [[nodiscard]] bool is_gui_thread() const noexcept
118 {
119 return thread_id == current_thread_id();
120 }
121
124 void request_reconstrain() noexcept;
125
126protected:
128 std::unique_ptr<gfx_system> gfx,
129 std::unique_ptr<hi::font_book> font_book,
130 std::unique_ptr<hi::theme_book> theme_book,
132 std::weak_ptr<gui_system_delegate> delegate = {}) noexcept;
133
134private:
136
140 hi::theme const *_theme = nullptr;
141};
142
143} // namespace hi::inline v1
STL namespace.
DOXYGEN BUG.
Definition algorithm.hpp:15
void * os_handle
Minimum offset between two objects to avoid false sharing.
Definition architecture.hpp:247
unicode_bidi_class
Bidirectional class Unicode Standard Annex #9: https://unicode.org/reports/tr9/.
Definition unicode_bidi_class.hpp:17
thread_id current_thread_id() noexcept
Get the current thread id.
Definition thread.hpp:39
The HikoGUI namespace.
Definition ascii.hpp:19
Graphics system.
Definition gfx_system.hpp:21
Graphics system.
Definition gui_system.hpp:30
std::shared_ptr< gui_window > make_window(Args &&...args)
Create a new window.
Definition gui_system.hpp:104
bool is_gui_thread() const noexcept
Check if this thread is the same as the gui thread.
Definition gui_system.hpp:117
static std::unique_ptr< gui_system > make_unique(std::weak_ptr< gui_system_delegate > delegate={}) noexcept
Make a gui_system instance.
virtual void init() noexcept
Initialize after construction.
Definition gui_system.hpp:77
void request_reconstrain() noexcept
Request all windows to constrain.
Definition gui_system_delegate.hpp:12
Definition keyboard_bindings.hpp:17
theme_book keeps track of multiple themes.
Definition theme_book.hpp:20
A observer pointing to the whole or part of a observable.
Definition observer.hpp:23
font_book keeps track of multiple fonts.
Definition font_book.hpp:31
T move(T... args)