ReXGlue SDK
Loading...
Searching...
No Matches
style.h
Go to the documentation of this file.
1
10
11#pragma once
12
13#include <array>
14#include <imgui.h>
15#include <algorithm>
16
17#include <rex/math.h>
19#include <rex/types.h>
20#include <rex/platform.h>
21
22namespace rex::ui {
23
24namespace detail {
25
26constexpr u32 ColorByte(f32 channel) {
27 const f32 scaled = std::clamp(channel, 0.0f, 1.0f) * 255.0f;
28 const u32 whole = static_cast<u32>(scaled);
29 return whole + ((scaled - static_cast<f32>(whole)) >= 0.5f ? 1u : 0u);
30}
31
32} // namespace detail
33
35struct Color {
36 f32 r = 0;
37 f32 g = 0;
38 f32 b = 0;
39 f32 a = 1;
40
46 static constexpr Color FromRGBA(f32 r, f32 g, f32 b, f32 a = 1) { return Color{r, g, b, a}; }
47
53 static constexpr Color FromRGB8(u32 rrggbb, f32 a = 1) {
54 return Color{static_cast<f32>((rrggbb >> 16) & 0xFFu) / 255.0f,
55 static_cast<f32>((rrggbb >> 8) & 0xFFu) / 255.0f,
56 static_cast<f32>(rrggbb & 0xFFu) / 255.0f, a};
57 }
58
67 static constexpr Color FromRGBA8(u8 r, u8 g, u8 b, u8 a = 255) {
68 return Color{static_cast<f32>(r) / 255.0f, static_cast<f32>(g) / 255.0f,
69 static_cast<f32>(b) / 255.0f, static_cast<f32>(a) / 255.0f};
70 }
71
77 static constexpr Color FromARGB8(u32 argb) {
78 return FromRGBA8(static_cast<u8>(argb >> 16), static_cast<u8>(argb >> 8), static_cast<u8>(argb),
79 static_cast<u8>(argb >> 24));
80 }
81
83 constexpr Color WithAlpha(f32 alpha) const { return Color{r, g, b, alpha}; }
84
90 constexpr Color Scaled(f32 factor) const { return Color{r * factor, g * factor, b * factor, a}; }
91
98 static constexpr Color Lerp(Color from, Color to, f32 t) {
99 const f32 inverse = 1.0f - t;
100 return Color{inverse * from.r + t * to.r, inverse * from.g + t * to.g,
101 inverse * from.b + t * to.b, inverse * from.a + t * to.a};
102 }
103
108 constexpr u32 ToRGBA8() const {
109 return detail::ColorByte(r) | (detail::ColorByte(g) << 8) | (detail::ColorByte(b) << 16) |
110 (detail::ColorByte(a) << 24);
111 }
112
117 constexpr u32 ToARGB8() const {
118 return (detail::ColorByte(a) << 24) | (detail::ColorByte(r) << 16) |
119 (detail::ColorByte(g) << 8) | detail::ColorByte(b);
120 }
121
122 constexpr bool operator==(const Color& other) const = default;
123};
124
125namespace colors {
126
127inline constexpr Color kWhite = Color::FromRGBA(1, 1, 1);
128inline constexpr Color kBlack = Color::FromRGBA(0, 0, 0);
129inline constexpr Color kTransparent = Color::FromRGBA(0, 0, 0, 0);
130
131} // namespace colors
132
133} // namespace rex::ui
134
135namespace rex::ui {
136
137namespace detail {
138
139inline constexpr Color kSuccess = Color::FromRGBA(0.40f, 1.00f, 0.40f);
140inline constexpr Color kWarning = Color::FromRGBA(1.00f, 0.80f, 0.20f);
141inline constexpr Color kError = Color::FromRGBA(1.00f, 0.40f, 0.40f);
142inline constexpr Color kInfo = Color::FromRGBA(0.60f, 0.85f, 1.00f);
143inline constexpr Color kMuted = Color::FromRGBA(1.00f, 1.00f, 1.00f, 0.50f);
144
145} // namespace detail
146
150 Color frame = Color::FromRGBA(0.80f, 0.80f, 0.80f, 0.30f);
151 Color frame_hovered = Color::FromRGBA(0.90f, 0.80f, 0.80f, 0.40f);
152 Color frame_active = Color::FromRGBA(0.90f, 0.65f, 0.65f, 0.45f);
154 Color title = Color::FromRGBA(0.00f, 0.40f, 0.00f, 1.00f);
155 Color title_collapsed = Color::FromRGBA(0.00f, 0.33f, 0.00f, 1.00f);
156 Color title_active = Color::FromRGBA(0.16f, 0.65f, 0.00f, 1.00f);
157 Color menu_bar = Color::FromRGBA(0.00f, 0.35f, 0.00f, 1.00f);
159 Color scrollbar = Color::FromRGBA(0.00f, 0.40f, 0.11f, 0.59f);
161 Color scrollbar_grab = Color::FromRGBA(0.00f, 0.68f, 0.00f, 0.68f);
162 Color scrollbar_grab_hovered = Color::FromRGBA(0.00f, 1.00f, 0.15f, 0.62f);
163 Color scrollbar_grab_active = Color::FromRGBA(0.00f, 0.91f, 0.09f, 0.40f);
164 Color check_mark = Color::FromRGBA(0.74f, 0.90f, 0.72f, 0.50f);
166 Color slider_grab = Color::FromRGBA(1.00f, 1.00f, 1.00f, 0.30f);
167 Color slider_grab_active = Color::FromRGBA(0.34f, 0.75f, 0.11f, 1.00f);
169 Color header = Color::FromRGBA(0.00f, 0.40f, 0.00f, 0.71f);
170 Color header_hovered = Color::FromRGBA(0.00f, 0.60f, 0.26f, 0.80f);
171 Color header_active = Color::FromRGBA(0.00f, 0.75f, 0.00f, 0.80f);
172 Color separator = Color::FromRGBA(0.00f, 0.35f, 0.00f, 1.00f);
173 Color separator_hovered = Color::FromRGBA(0.36f, 0.89f, 0.38f, 1.00f);
174 Color separator_active = Color::FromRGBA(0.13f, 0.50f, 0.11f, 1.00f);
175 Color resize_grip = Color::FromRGBA(1.00f, 1.00f, 1.00f, 0.30f);
176 Color resize_grip_hovered = Color::FromRGBA(1.00f, 1.00f, 1.00f, 0.60f);
177 Color resize_grip_active = Color::FromRGBA(1.00f, 1.00f, 1.00f, 0.90f);
178 Color tab = Color::FromRGBA(0.15f, 0.56f, 0.11f, 0.60f);
179 Color tab_hovered = Color::FromRGBA(0.19f, 0.72f, 0.09f, 1.00f);
180 Color tab_active = Color::FromRGBA(0.19f, 0.60f, 0.09f, 1.00f);
181 Color tab_unfocused = Color::FromRGBA(0.80f, 0.80f, 0.80f, 0.30f);
182 Color tab_unfocused_active = Color::FromRGBA(0.90f, 0.80f, 0.80f, 0.40f);
183 Color plot_lines = Color::FromRGBA(1.00f, 1.00f, 1.00f, 1.00f);
184 Color plot_lines_hovered = Color::FromRGBA(0.90f, 0.70f, 0.00f, 1.00f);
186 Color plot_histogram = Color::FromRGBA(0.90f, 0.70f, 0.00f, 1.00f);
187 Color plot_histogram_hovered = Color::FromRGBA(1.00f, 0.60f, 0.00f, 1.00f);
189 Color selection = Color::FromRGBA(0.00f, 1.00f, 0.00f, 0.21f);
191 Color table_header = Color::FromRGBA(0.19f, 0.19f, 0.20f, 1.00f);
193 Color table_border_strong = Color::FromRGBA(0.31f, 0.31f, 0.35f, 1.00f);
195 Color table_border_light = Color::FromRGBA(0.23f, 0.23f, 0.25f, 1.00f);
197 Color table_row = Color::FromRGBA(0.00f, 0.00f, 0.00f, 0.00f);
199 Color table_row_alt = Color::FromRGBA(1.00f, 1.00f, 1.00f, 0.06f);
201 Color text_link = Color::FromRGBA(0.26f, 0.59f, 0.98f, 1.00f);
203 Color tree_lines = Color::FromRGBA(0.43f, 0.43f, 0.50f, 0.50f);
205 Color nav_cursor = Color::FromRGBA(0.26f, 0.59f, 0.98f, 1.00f);
207 Color nav_windowing_highlight = Color::FromRGBA(1.00f, 1.00f, 1.00f, 0.70f);
209 Color nav_windowing_dim = Color::FromRGBA(0.80f, 0.80f, 0.80f, 0.20f);
210
212 bool operator==(const ControlPalette& other) const = default;
213};
214
219struct Palette {
221 Color accent = Color::FromRGBA(0.15f, 0.56f, 0.11f);
223 f32 button_alpha = 0.60f;
224 Color accent_hovered = Color::FromRGBA(0.19f, 0.72f, 0.09f);
225 Color accent_active = Color::FromRGBA(0.19f, 0.60f, 0.09f);
227 Color panel = Color::FromRGBA(0.00f, 0.06f, 0.00f);
229 Color panel_popup = Color::FromRGBA(0.20f, 0.20f, 0.20f, 0.99f);
230 Color text = Color::FromRGBA(0.89f, 0.90f, 0.90f);
231 Color text_muted = detail::kMuted;
232 Color text_disabled = Color::FromRGBA(0.60f, 0.60f, 0.60f);
233 Color border = Color::FromRGBA(0.00f, 0.35f, 0.00f);
234 Color success = detail::kSuccess;
235 Color warning = detail::kWarning;
236 Color error = detail::kError;
237 Color info = detail::kInfo;
239 Color highlight = Color::FromRGBA(0.90f, 0.70f, 0.00f);
241 Color shadow = Color::FromRGBA(0.00f, 0.00f, 0.00f, 0.00f);
243 Color overlay_dim = Color::FromRGBA(0.20f, 0.20f, 0.20f, 0.35f);
244 ControlPalette controls;
245
247 bool operator==(const Palette& other) const = default;
248};
249
253 f32 overlay = 0.92f;
255 f32 panel = 0.85f;
257 f32 toast = 0.88f;
259 f32 hud = 0.5f;
260
262 bool operator==(const WindowAlpha& other) const = default;
263};
264
265struct Metrics {
266 f32 window_rounding = 0;
268 f32 rounding = 0;
269 f32 frame_rounding = 0;
276 f32 border = 1;
277 Vec2 window_padding{8, 8};
278 Vec2 item_spacing{8, 4};
279 Vec2 frame_padding{4, 3};
280 f32 icon_size = 44;
283 f32 toast_rounding = 6;
286 f32 toast_width = 320;
287 f32 toast_height = 70;
294 f32 button_width = 140;
295 f32 value_width = 160;
296 WindowAlpha window_alpha;
297
298 bool operator==(const Metrics& other) const = default;
299};
300
302 Color unlocked_title = Color::FromRGBA(0.45f, 1.00f, 0.55f, 1.00f);
303 Color unlocked_desc = Color::FromRGBA(0.70f, 0.85f, 0.72f, 1.00f);
304 Color locked_title = Color::FromRGBA(0.78f, 0.80f, 0.84f, 1.00f);
305 Color locked_desc = Color::FromRGBA(0.50f, 0.52f, 0.56f, 1.00f);
306 Color badge_gamerscore = Color::FromRGBA(1.00f, 0.82f, 0.30f, 1.00f);
308 Color row_unlocked_bg = Color::FromRGBA(0.16f, 0.30f, 0.18f, 0.55f);
310 Color header_text = detail::kInfo;
311 Color progress_bar = Color::FromRGBA(0.30f, 0.80f, 0.40f, 1.00f);
312 Color unlocked_icon_tint = colors::kWhite;
313 Color locked_icon_tint = Color::FromRGBA(0.45f, 0.45f, 0.45f, 0.80f);
314 Vec2 window_padding{14.0f, 12.0f};
315 Vec2 item_spacing{8.0f, 6.0f};
316};
317
321 Color text = colors::kWhite;
323 Color title = Color::FromRGBA(1.00f, 0.85f, 0.20f, 1.00f);
324};
325
328 std::array<Color, rex::log::kMessageLevelCount> level = {{
329 Color::FromRGBA(0.5f, 0.5f, 0.5f, 1.0f),
330 Color::FromRGBA(0.8f, 0.5f, 0.9f, 1.0f),
331 Color::FromRGBA(0.4f, 0.9f, 0.9f, 1.0f),
332 colors::kWhite,
333 Color::FromRGBA(1.0f, 1.0f, 0.0f, 1.0f),
334 detail::kError,
335 Color::FromRGBA(1.0f, 0.0f, 0.0f, 1.0f),
336 }};
337 Color completion_bg = Color::FromRGBA(0.10f, 0.10f, 0.10f, 0.95f);
338 Color completion_highlight = Color::FromRGBA(0.235f, 0.353f, 0.549f, 0.784f);
339};
340
343 Color muted_text = detail::kMuted;
344};
345
348 Color warning = detail::kWarning;
350 Color lifecycle_hot_reload = detail::kSuccess;
352 Color lifecycle_restart = Color::FromRGBA(1.00f, 1.00f, 0.40f, 1.00f);
354 Color lifecycle_init_only = detail::kError;
356 Color lifecycle_unknown = colors::kWhite;
357};
358
360struct Style {
361 Palette palette;
362 Metrics metrics;
363 AchievementsStyle achievements;
364 ToastStyle toast;
365 ConsoleStyle console;
366 DebugOverlayStyle debug;
367 SettingsStyle settings;
368};
369
370} // namespace rex::ui
371
372namespace rex::ui {
373
379inline ImVec4 ToImVec4(Color color) {
380 return ImVec4(color.r, color.g, color.b, color.a);
381}
382
388inline ImU32 ToImU32(Color color) {
389 return color.ToRGBA8();
390}
391
397inline Color FromImVec4(const ImVec4& value) {
398 return Color::FromRGBA(value.x, value.y, value.z, value.w);
399}
400
402REX_UI_API void ApplyDefaultStyle(ImGuiStyle& imgui_style, const Palette& palette,
403 const Metrics& metrics);
404
405} // namespace rex::ui
Platform flags, packing macros and export markers.
#define REX_UI_API
Definition platform.h:262
Definition math.h:204
Definition style.h:301
Color row_unlocked_bg
Definition style.h:308
Color header_text
Definition style.h:310
Definition style.h:35
static constexpr Color FromRGBA(f32 r, f32 g, f32 b, f32 a=1)
Definition style.h:46
constexpr Color Scaled(f32 factor) const
Definition style.h:90
static constexpr Color FromRGBA8(u8 r, u8 g, u8 b, u8 a=255)
Definition style.h:67
constexpr u32 ToRGBA8() const
Definition style.h:108
f32 a
Definition style.h:39
constexpr Color WithAlpha(f32 alpha) const
Definition style.h:83
constexpr u32 ToARGB8() const
Definition style.h:117
static constexpr Color FromRGB8(u32 rrggbb, f32 a=1)
Definition style.h:53
static constexpr Color Lerp(Color from, Color to, f32 t)
Definition style.h:98
static constexpr Color FromARGB8(u32 argb)
Definition style.h:77
Definition style.h:326
std::array< Color, rex::log::kMessageLevelCount > level
Definition style.h:328
Definition style.h:148
Color table_header
Definition style.h:191
Color slider_grab
Definition style.h:166
Color selection
Definition style.h:189
Color header
Definition style.h:169
Color table_row_alt
Definition style.h:199
Color text_link
Definition style.h:201
Color table_border_strong
Definition style.h:193
Color title
Definition style.h:154
Color scrollbar_grab
Definition style.h:161
Color nav_windowing_highlight
Definition style.h:207
Color frame
Definition style.h:150
Color plot_histogram
Definition style.h:186
Color tree_lines
Definition style.h:203
Color nav_windowing_dim
Definition style.h:209
bool operator==(const ControlPalette &other) const =default
Color scrollbar
Definition style.h:159
Color table_row
Definition style.h:197
Color table_border_light
Definition style.h:195
Color nav_cursor
Definition style.h:205
Definition style.h:341
Color muted_text
Definition style.h:343
Definition style.h:265
f32 footer_height
Definition style.h:291
f32 popup_rounding
Definition style.h:273
f32 row_rounding
Definition style.h:282
f32 grab_rounding
Definition style.h:275
f32 side_panel_width
Definition style.h:293
f32 toast_stack_height
Definition style.h:289
f32 toast_padding
Definition style.h:285
f32 child_rounding
Definition style.h:271
f32 rounding
Definition style.h:268
Definition style.h:219
Color overlay_dim
Definition style.h:243
Color panel
Definition style.h:227
bool operator==(const Palette &other) const =default
Color shadow
Definition style.h:241
f32 button_alpha
Definition style.h:223
Color panel_popup
Definition style.h:229
Color highlight
Definition style.h:239
Color accent
Definition style.h:221
Definition style.h:346
Color warning
Definition style.h:348
Color lifecycle_unknown
Definition style.h:356
Color lifecycle_hot_reload
Definition style.h:350
Color lifecycle_restart
Definition style.h:352
Color lifecycle_init_only
Definition style.h:354
Definition style.h:360
Definition style.h:319
Color title
Definition style.h:323
Color text
Definition style.h:321
Definition style.h:251
f32 toast
Definition style.h:257
f32 overlay
Definition style.h:253
bool operator==(const WindowAlpha &other) const =default
f32 panel
Definition style.h:255
f32 hud
Definition style.h:259
REX_UI_API void ApplyDefaultStyle(ImGuiStyle &imgui_style, const Palette &palette, const Metrics &metrics)
Color FromImVec4(const ImVec4 &value)
Definition style.h:397
ImU32 ToImU32(Color color)
Definition style.h:388
ImVec4 ToImVec4(Color color)
Definition style.h:379
Integer types, byte order wrappers and size literals.