ReXGlue SDK
Loading...
Searching...
No Matches
ui_system.h
Go to the documentation of this file.
1
14
15#pragma once
16
17#include <filesystem>
18#include <memory>
19#include <span>
20#include <string>
21#include <string_view>
22#include <vector>
23
24#include <rex/platform.h>
25#include <rex/input_keys.h>
26#include <rex/module.h>
27#include <rex/ui/dialog.h>
29#include <rex/ui/window.h>
30#include <rex/ui/ui_event.h>
31#include <rex/utility.h>
32#include <rex/result.h>
33#include <rex/setting.h>
35#include <rex/title.h>
36#include <rex/types.h>
38
39struct ImGuiIO;
40
41namespace rex::ui {
42
47class IDialog {
48 public:
49 virtual ~IDialog() = default;
50
55 virtual bool Draw(ImGuiIO& io) = 0;
56
58 virtual void OnClose() = 0;
59
65 virtual bool NeedsContinuousPaint() const = 0;
66
72 virtual bool WantsExclusiveInput() const = 0;
73
74 virtual void OnShow() = 0;
75
81 virtual bool OnToggle() = 0;
82};
83
85class DialogBase : public IDialog {
86 public:
87 void OnClose() override {}
88
89 bool NeedsContinuousPaint() const override { return true; }
90
91 bool WantsExclusiveInput() const override { return false; }
92
93 void OnShow() override {}
94
95 bool OnToggle() override { return false; }
96};
97
98} // namespace rex::ui
99
100struct ImDrawData;
101struct ImFontAtlas;
102struct ImGuiIO;
103struct ImGuiStyle;
104
105namespace rex::ui {
106
107class IUISystem;
108struct Style;
109
112 std::string_view name;
115 std::unique_ptr<ui::IDialog> (*create)(IUISystem& ui);
116};
117
118class REX_UI_API UISettings final : public SettingOwner {
119 public:
120 UISettings();
121
122 REX_SETTING(std::string, driver, "sdl3",
123 "UI driver, none for headless in an app that does not require a UI", kStartupOnly);
124 REX_SETTING(std::string, title, "", "Window title, the app name when empty");
125 REX_SETTING(i32, window_width, 0, "Window width, 0 for the video mode width", Range{0, 16384});
126 REX_SETTING(i32, window_height, 0, "Window height, 0 for the video mode height", Range{0, 16384});
127 REX_SETTING(bool, fullscreen, true, "Fullscreen");
128 REX_SETTING(bool, fullscreen_exclusive, false, "Exclusive fullscreen");
129 REX_SETTING(i32, monitor, 0, "Display to open on", Range{0, 16});
130 REX_SETTING(i32, min_width, 0, "Smallest window width", Range{0, 16384});
131 REX_SETTING(i32, min_height, 0, "Smallest window height", Range{0, 16384});
132 REX_SETTING(std::string, aspect_ratio, "stretch", "Window shape",
133 Allowed("stretch", "4:3", "5:4", "3:2", "16:10", "16:9", "21:9", "32:9"));
134 REX_SETTING(std::string, resolution, "",
135 "Video mode preset or WxH, empty to use the ui.video_mode_* settings");
136 REX_SETTING(i32, video_mode_width, 1280, "Video mode width the title sees", Range{640, 4095},
137 kRestart);
138 REX_SETTING(i32, video_mode_height, 720, "Video mode height the title sees", Range{480, 4095},
139 kRestart);
140 REX_SETTING(f64, video_mode_refresh_rate, 60.0, "Refresh rate the title sees", Range{24.0, 240.0},
141 kRestart);
142 REX_SETTING(f64, cursor_timeout, 0.0, "Seconds before an idle cursor hides, 0 never hides",
143 Range{0.0, 3600.0});
144};
145
156 virtual UISettings& GetSettings() = 0;
157
163 virtual bool IsHeadless() const = 0;
164
166 virtual bool HasWindow() const = 0;
167
173 virtual bool IsFocused() const = 0;
174
176 virtual VideoMode GetVideoMode() const = 0;
177
182 [[nodiscard]] virtual Result<NativeWindow> GetNativeWindow() const = 0;
183
184 virtual void RaiseWindow() = 0;
185
187 virtual bool IsUIThread() const = 0;
188
190 virtual void PostTask(MoveOnlyFunction<void()> fn) = 0;
191
197 [[nodiscard]] virtual bool RunSynchronous(MoveOnlyFunction<void()> fn) = 0;
198
205 [[nodiscard]] virtual ScopeGuard AddEventListener(IUIEventListener& listener) = 0;
206
208 virtual ImFontAtlas& GetFonts() = 0;
209
213 virtual ImGuiStyle& GetImGuiStyle() = 0;
214
218 virtual ImGuiIO& GetImGuiIO() = 0;
219
223 virtual ui::Style& GetStyle() = 0;
224
230 [[nodiscard]] virtual Result<void> AddOverlays(std::span<const OverlayConfig> overlays) = 0;
231
232 virtual void ShowOverlay(std::string_view name, bool visible) = 0;
233
234 virtual void ToggleOverlay(std::string_view name) = 0;
235
239 [[nodiscard]] virtual Result<ui::IDialog*> GetOverlay(std::string_view name) = 0;
240
242 virtual bool IsAnyOverlayVisible() const = 0;
243
251 [[nodiscard]] virtual ScopeGuard AddDialog(ui::IDialog& dialog) = 0;
252
256 virtual void AddDialog(std::unique_ptr<ui::IDialog> dialog) = 0;
257
259 virtual bool HasDialogs() const = 0;
260
265 virtual void DrawOverlays(IOverlayRenderer& renderer) = 0;
266
273 virtual void ShowMessage(MessageType type, std::string_view heading, std::string_view body) = 0;
274
281 [[nodiscard]] virtual Result<u32> ShowChoice(const ui::ChoiceConfig& config) = 0;
282
289 [[nodiscard]] virtual Result<std::vector<std::filesystem::path>> ShowFileDialog(
290 const ui::FileDialogConfig& config) = 0;
291
299 virtual void ShowPrompt(ui::PromptConfig config,
300 MoveOnlyFunction<void(ui::PromptResult)> done) = 0;
301
303 virtual void CancelPrompts() = 0;
304
308 virtual std::vector<ui::Monitor> GetDisplays() = 0;
309
315 virtual std::vector<ui::HostLocale> GetPreferredLocales() = 0;
316};
317
318} // namespace rex::ui
Definition overlay_renderer.h:18
Definition utility.h:305
SettingOwner(std::string_view scope)
Definition ui_system.h:85
bool NeedsContinuousPaint() const override
Definition ui_system.h:89
void OnClose() override
Definition ui_system.h:87
bool WantsExclusiveInput() const override
Definition ui_system.h:91
bool OnToggle() override
Definition ui_system.h:95
Definition ui_system.h:47
virtual void OnClose()=0
virtual bool Draw(ImGuiIO &io)=0
virtual bool OnToggle()=0
virtual bool WantsExclusiveInput() const =0
virtual bool NeedsContinuousPaint() const =0
Definition ui_event.h:184
Definition ui_system.h:154
Definition ui_system.h:118
Interfaces, factory and module declaration.
#define REX_DECLARE_INTERFACE(Name, version)
Definition module.h:114
typename detail::MoveOnlyFunctionFor< Signature >::type MoveOnlyFunction
Definition utility.h:254
std::expected< T, Error > Result
Definition result.h:98
MessageType
Definition process.h:182
Platform flags, packing macros and export markers.
#define REX_UI_API
Definition platform.h:262
Typed settings and the owners that declare them.
The registry of every registered setting.
Definition setting.h:84
Definition input_keys.h:554
Definition native_window.h:17
Definition setting.h:78
Definition title.h:26
Definition dialog.h:22
Definition dialog.h:61
Definition window.h:60
Definition window.h:42
Definition ui_system.h:111
std::unique_ptr< ui::IDialog >(*) create(IUISystem &ui)
Definition ui_system.h:115
std::string_view name
Definition ui_system.h:112
KeyChord default_key
Definition ui_system.h:113
Definition dialog.h:31
Definition dialog.h:45
Definition style.h:360
Integer types, byte order wrappers and size literals.
Move only function, const propagating pointer and scope guard.