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/module.hpp"
11#include "../GFX/module.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 keyboard_bindings;
24
28public:
29 static inline os_handle instance;
30
33
34 thread_id const thread_id;
35
38 observer<std::string> selected_theme = "default";
39
49
50 virtual ~gui_system();
51
52 gui_system(const gui_system&) = delete;
53 gui_system& operator=(const gui_system&) = delete;
54 gui_system(gui_system&&) = delete;
55 gui_system& operator=(gui_system&&) = delete;
56
57 void set_delegate(std::weak_ptr<gui_system_delegate> delegate) noexcept
58 {
59 _delegate = std::move(delegate);
60 }
61
63
73 template<typename WidgetType, typename... Args>
74 std::pair<std::shared_ptr<gui_window>, WidgetType&> make_window(hi::label const& label, Args&&...args)
75 {
76 hi_axiom(loop::main().on_thread());
77
78 auto widget = std::make_unique<WidgetType>(label, std::forward<Args>(args)...);
79 auto widget_ptr = widget.get();
80
81#if HI_OPERATING_SYSTEM == HI_OS_WINDOWS
82 auto window = std::make_shared<gui_window_win32>(*this, std::move(widget), label);
83#else
84#error "Not implemented"
85#endif
86 widget_ptr->set_window(*window);
87
88 return {add_window(std::move(window)), *widget_ptr};
89 }
90
93 void request_reconstrain() noexcept;
94
95protected:
96 std::weak_ptr<gui_system_delegate> _delegate;
97
99 std::unique_ptr<gfx_system> gfx,
101 std::weak_ptr<gui_system_delegate> delegate = {}) noexcept;
102
103private:
104 decltype(selected_theme)::callback_token _selected_theme_cbt;
105 os_settings::callback_token _os_settings_cbt;
106};
107
108} // 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:27
std::pair< std::shared_ptr< gui_window >, WidgetType & > make_window(hi::label const &label, Args &&...args)
Create a new window with an embedded widget.
Definition gui_system.hpp:74
static std::unique_ptr< gui_system > make_unique(std::weak_ptr< gui_system_delegate > delegate={}) noexcept
Make a gui_system instance.
void request_reconstrain() noexcept
Request all windows to constrain.
Definition gui_system_delegate.hpp:12
Definition keyboard_bindings.hpp:16
A label consisting of localizable text and an icon.
Definition label.hpp:114
A observer pointing to the whole or part of a observable.
Definition observer.hpp:22
T move(T... args)