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 "widget_intf.hpp"
11#include "../unicode/module.hpp"
12#include "../GFX/module.hpp"
13#include "../utility/module.hpp"
14#include "../observer/module.hpp"
15#include <span>
16#include <memory>
17#include <mutex>
18#include <thread>
19#include <vector>
20#include <concepts>
21#include <utility>
22
23namespace hi::inline v1 {
24class gfx_system;
25class vertical_sync;
26class theme_book;
27class keyboard_bindings;
28
32public:
33 static inline os_handle instance;
34
38
39 thread_id const thread_id;
40
43 observer<std::string> selected_theme = "default";
44
54
55 virtual ~gui_system();
56
57 gui_system(const gui_system&) = delete;
58 gui_system& operator=(const gui_system&) = delete;
59 gui_system(gui_system&&) = delete;
60 gui_system& operator=(gui_system&&) = delete;
61
65 virtual void init() noexcept
66 {
67 if (auto delegate = _delegate.lock()) {
68 delegate->init(*this);
69 }
70 }
71
72 virtual void deinit() noexcept
73 {
74 if (auto delegate = _delegate.lock()) {
75 delegate->deinit(*this);
76 }
77 }
78
79 void set_delegate(std::weak_ptr<gui_system_delegate> delegate) noexcept
80 {
81 _delegate = std::move(delegate);
82 }
83
85
93 {
94 hi_axiom(loop::main().on_thread());
95
96 // XXX abstract away the _win32 part.
97 return add_window(std::make_shared<gui_window_win32>(*this, std::move(widget)));
98 }
99
108 template<std::derived_from<widget_intf> Widget, typename... Args>
109 [[nodiscard]] std::pair<std::shared_ptr<gui_window>, Widget&> make_window(Args&&...args)
110 {
111 auto widget = std::make_unique<Widget>(std::forward<Args>(args)...);
112 auto& widget_ref = *widget;
113
114 return {make_window_with_widget(std::move(widget)), widget_ref};
115 }
116
119 void request_reconstrain() noexcept;
120
121protected:
123 std::unique_ptr<gfx_system> gfx,
124 std::unique_ptr<hi::theme_book> theme_book,
126 std::weak_ptr<gui_system_delegate> delegate = {}) noexcept;
127
128private:
130
134 hi::theme const *_theme = nullptr;
135};
136
137} // namespace hi::inline v1
#define hi_axiom(expression,...)
Specify an axiom; an expression that is true.
Definition assert.hpp:253
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:31
std::pair< std::shared_ptr< gui_window >, Widget & > make_window(Args &&...args)
Create a new window.
Definition gui_system.hpp:109
static std::unique_ptr< gui_system > make_unique(std::weak_ptr< gui_system_delegate > delegate={}) noexcept
Make a gui_system instance.
std::shared_ptr< gui_window > make_window_with_widget(std::unique_ptr< widget_intf > widget)
Create a new window with the specified managing widget.
Definition gui_system.hpp:92
virtual void init() noexcept
Initialize after construction.
Definition gui_system.hpp:65
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)