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 "../utility/module.hpp"
13#include "../observer.hpp"
14#include <span>
15#include <memory>
16#include <mutex>
17#include <thread>
18#include <vector>
19
20namespace hi::inline v1 {
21class gfx_system;
22class vertical_sync;
23class theme_book;
24class keyboard_bindings;
25
29public:
30 static inline os_handle instance;
31
35
36 thread_id const thread_id;
37
40 observer<std::string> selected_theme = "default";
41
51
52 virtual ~gui_system();
53
54 gui_system(const gui_system &) = delete;
55 gui_system &operator=(const gui_system &) = delete;
56 gui_system(gui_system &&) = delete;
57 gui_system &operator=(gui_system &&) = delete;
58
62 virtual void init() noexcept
63 {
64 if (auto delegate = _delegate.lock()) {
65 delegate->init(*this);
66 }
67 }
68
69 virtual void deinit() noexcept
70 {
71 if (auto delegate = _delegate.lock()) {
72 delegate->deinit(*this);
73 }
74 }
75
76 void set_delegate(std::weak_ptr<gui_system_delegate> delegate) noexcept
77 {
78 _delegate = std::move(delegate);
79 }
80
82
88 template<typename... Args>
90 {
91 hi_axiom(loop::main().on_thread());
92
93 // XXX abstract away the _win32 part.
94 auto window = std::make_shared<gui_window_win32>(*this, std::forward<Args>(args)...);
95 window->init();
96
97 return add_window(std::move(window));
98 }
99
102 void request_reconstrain() noexcept;
103
104protected:
106 std::unique_ptr<gfx_system> gfx,
107 std::unique_ptr<hi::theme_book> theme_book,
109 std::weak_ptr<gui_system_delegate> delegate = {}) noexcept;
110
111private:
113
117 hi::theme const *_theme = nullptr;
118};
119
120} // namespace hi::inline v1
#define hi_axiom(expression,...)
Specify an axiom; an expression that is true.
Definition assert.hpp:238
STL namespace.
DOXYGEN BUG.
Definition algorithm.hpp:13
geometry/margins.hpp
Definition cache.hpp:11
Graphics system.
Definition gfx_system.hpp:20
Graphics system.
Definition gui_system.hpp:28
std::shared_ptr< gui_window > make_window(Args &&...args)
Create a new window.
Definition gui_system.hpp:89
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:62
void request_reconstrain() noexcept
Request all windows to constrain.
Definition gui_system_delegate.hpp:12
Definition keyboard_bindings.hpp:16
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:22
T move(T... args)