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 theme_book;
25class keyboard_bindings;
26
30public:
31 static inline os_handle instance;
32
36
37 thread_id const thread_id;
38
41 observer<std::string> selected_theme = "default";
42
52
53 virtual ~gui_system();
54
55 gui_system(const gui_system &) = delete;
56 gui_system &operator=(const gui_system &) = delete;
57 gui_system(gui_system &&) = delete;
58 gui_system &operator=(gui_system &&) = delete;
59
63 virtual void init() noexcept
64 {
65 if (auto delegate = _delegate.lock()) {
66 delegate->init(*this);
67 }
68 }
69
70 virtual void deinit() noexcept
71 {
72 if (auto delegate = _delegate.lock()) {
73 delegate->deinit(*this);
74 }
75 }
76
77 void set_delegate(std::weak_ptr<gui_system_delegate> delegate) noexcept
78 {
79 _delegate = std::move(delegate);
80 }
81
83
89 template<typename... Args>
91 {
92 hi_axiom(loop::main().on_thread());
93
94 // XXX abstract away the _win32 part.
95 auto window = std::make_shared<gui_window_win32>(*this, std::forward<Args>(args)...);
96 window->init();
97
98 return add_window(std::move(window));
99 }
100
103 void request_reconstrain() noexcept;
104
105protected:
107 std::unique_ptr<gfx_system> gfx,
108 std::unique_ptr<hi::theme_book> theme_book,
110 std::weak_ptr<gui_system_delegate> delegate = {}) noexcept;
111
112private:
114
118 hi::theme const *_theme = nullptr;
119};
120
121} // namespace hi::inline v1
#define hi_axiom(expression,...)
Specify an axiom; an expression that is true.
Definition assert.hpp:133
STL namespace.
DOXYGEN BUG.
Definition algorithm.hpp:15
void * os_handle
Minimum offset between two objects to avoid false sharing.
Definition architecture.hpp:239
geometry/margins.hpp
Definition assert.hpp:18
Graphics system.
Definition gfx_system.hpp:21
Graphics system.
Definition gui_system.hpp:29
std::shared_ptr< gui_window > make_window(Args &&...args)
Create a new window.
Definition gui_system.hpp:90
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:63
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
T move(T... args)