ReXGlue SDK
Toggle main menu visibility
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
>
18
#include <
rex/logging/log_category.h
>
19
#include <
rex/types.h
>
20
#include <
rex/platform.h
>
21
22
namespace
rex::ui {
23
24
namespace
detail {
25
26
constexpr
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
35
struct
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
125
namespace
colors {
126
127
inline
constexpr
Color kWhite =
Color::FromRGBA
(1, 1, 1);
128
inline
constexpr
Color kBlack =
Color::FromRGBA
(0, 0, 0);
129
inline
constexpr
Color kTransparent =
Color::FromRGBA
(0, 0, 0, 0);
130
131
}
// namespace colors
132
133
}
// namespace rex::ui
134
135
namespace
rex::ui {
136
137
namespace
detail {
138
139
inline
constexpr
Color kSuccess =
Color::FromRGBA
(0.40f, 1.00f, 0.40f);
140
inline
constexpr
Color kWarning =
Color::FromRGBA
(1.00f, 0.80f, 0.20f);
141
inline
constexpr
Color kError =
Color::FromRGBA
(1.00f, 0.40f, 0.40f);
142
inline
constexpr
Color kInfo =
Color::FromRGBA
(0.60f, 0.85f, 1.00f);
143
inline
constexpr
Color kMuted =
Color::FromRGBA
(1.00f, 1.00f, 1.00f, 0.50f);
144
145
}
// namespace detail
146
148
struct
ControlPalette
{
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
219
struct
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
251
struct
WindowAlpha
{
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
265
struct
Metrics
{
266
f32 window_rounding = 0;
268
f32
rounding
= 0;
269
f32 frame_rounding = 0;
271
f32
child_rounding
= 0;
273
f32
popup_rounding
= 0;
275
f32
grab_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;
282
f32
row_rounding
= 3;
283
f32 toast_rounding = 6;
285
f32
toast_padding
= 16;
286
f32 toast_width = 320;
287
f32 toast_height = 70;
289
f32
toast_stack_height
= 80;
291
f32
footer_height
= 30;
293
f32
side_panel_width
= 160;
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
301
struct
AchievementsStyle
{
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
319
struct
ToastStyle
{
321
Color
text
= colors::kWhite;
323
Color
title
=
Color::FromRGBA
(1.00f, 0.85f, 0.20f, 1.00f);
324
};
325
326
struct
ConsoleStyle
{
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
341
struct
DebugOverlayStyle
{
343
Color
muted_text
= detail::kMuted;
344
};
345
346
struct
SettingsStyle
{
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
360
struct
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
372
namespace
rex::ui {
373
379
inline
ImVec4
ToImVec4
(
Color
color) {
380
return
ImVec4(color.r, color.g, color.b, color.
a
);
381
}
382
388
inline
ImU32
ToImU32
(
Color
color) {
389
return
color.
ToRGBA8
();
390
}
391
397
inline
Color
FromImVec4
(
const
ImVec4& value) {
398
return
Color::FromRGBA
(value.x, value.y, value.z, value.w);
399
}
400
402
REX_UI_API
void
ApplyDefaultStyle
(ImGuiStyle& imgui_style,
const
Palette
& palette,
403
const
Metrics
& metrics);
404
405
}
// namespace rex::ui
log_category.h
math.h
platform.h
Platform flags, packing macros and export markers.
REX_UI_API
#define REX_UI_API
Definition
platform.h:262
rex::Vec2
Definition
math.h:204
rex::ui::AchievementsStyle
Definition
style.h:301
rex::ui::AchievementsStyle::row_unlocked_bg
Color row_unlocked_bg
Definition
style.h:308
rex::ui::AchievementsStyle::header_text
Color header_text
Definition
style.h:310
rex::ui::Color
Definition
style.h:35
rex::ui::Color::FromRGBA
static constexpr Color FromRGBA(f32 r, f32 g, f32 b, f32 a=1)
Definition
style.h:46
rex::ui::Color::Scaled
constexpr Color Scaled(f32 factor) const
Definition
style.h:90
rex::ui::Color::FromRGBA8
static constexpr Color FromRGBA8(u8 r, u8 g, u8 b, u8 a=255)
Definition
style.h:67
rex::ui::Color::ToRGBA8
constexpr u32 ToRGBA8() const
Definition
style.h:108
rex::ui::Color::a
f32 a
Definition
style.h:39
rex::ui::Color::WithAlpha
constexpr Color WithAlpha(f32 alpha) const
Definition
style.h:83
rex::ui::Color::ToARGB8
constexpr u32 ToARGB8() const
Definition
style.h:117
rex::ui::Color::FromRGB8
static constexpr Color FromRGB8(u32 rrggbb, f32 a=1)
Definition
style.h:53
rex::ui::Color::Lerp
static constexpr Color Lerp(Color from, Color to, f32 t)
Definition
style.h:98
rex::ui::Color::FromARGB8
static constexpr Color FromARGB8(u32 argb)
Definition
style.h:77
rex::ui::ConsoleStyle
Definition
style.h:326
rex::ui::ConsoleStyle::level
std::array< Color, rex::log::kMessageLevelCount > level
Definition
style.h:328
rex::ui::ControlPalette
Definition
style.h:148
rex::ui::ControlPalette::table_header
Color table_header
Definition
style.h:191
rex::ui::ControlPalette::slider_grab
Color slider_grab
Definition
style.h:166
rex::ui::ControlPalette::selection
Color selection
Definition
style.h:189
rex::ui::ControlPalette::header
Color header
Definition
style.h:169
rex::ui::ControlPalette::table_row_alt
Color table_row_alt
Definition
style.h:199
rex::ui::ControlPalette::text_link
Color text_link
Definition
style.h:201
rex::ui::ControlPalette::table_border_strong
Color table_border_strong
Definition
style.h:193
rex::ui::ControlPalette::title
Color title
Definition
style.h:154
rex::ui::ControlPalette::scrollbar_grab
Color scrollbar_grab
Definition
style.h:161
rex::ui::ControlPalette::nav_windowing_highlight
Color nav_windowing_highlight
Definition
style.h:207
rex::ui::ControlPalette::frame
Color frame
Definition
style.h:150
rex::ui::ControlPalette::plot_histogram
Color plot_histogram
Definition
style.h:186
rex::ui::ControlPalette::tree_lines
Color tree_lines
Definition
style.h:203
rex::ui::ControlPalette::nav_windowing_dim
Color nav_windowing_dim
Definition
style.h:209
rex::ui::ControlPalette::operator==
bool operator==(const ControlPalette &other) const =default
rex::ui::ControlPalette::scrollbar
Color scrollbar
Definition
style.h:159
rex::ui::ControlPalette::table_row
Color table_row
Definition
style.h:197
rex::ui::ControlPalette::table_border_light
Color table_border_light
Definition
style.h:195
rex::ui::ControlPalette::nav_cursor
Color nav_cursor
Definition
style.h:205
rex::ui::DebugOverlayStyle
Definition
style.h:341
rex::ui::DebugOverlayStyle::muted_text
Color muted_text
Definition
style.h:343
rex::ui::Metrics
Definition
style.h:265
rex::ui::Metrics::footer_height
f32 footer_height
Definition
style.h:291
rex::ui::Metrics::popup_rounding
f32 popup_rounding
Definition
style.h:273
rex::ui::Metrics::row_rounding
f32 row_rounding
Definition
style.h:282
rex::ui::Metrics::grab_rounding
f32 grab_rounding
Definition
style.h:275
rex::ui::Metrics::side_panel_width
f32 side_panel_width
Definition
style.h:293
rex::ui::Metrics::toast_stack_height
f32 toast_stack_height
Definition
style.h:289
rex::ui::Metrics::toast_padding
f32 toast_padding
Definition
style.h:285
rex::ui::Metrics::child_rounding
f32 child_rounding
Definition
style.h:271
rex::ui::Metrics::rounding
f32 rounding
Definition
style.h:268
rex::ui::Palette
Definition
style.h:219
rex::ui::Palette::overlay_dim
Color overlay_dim
Definition
style.h:243
rex::ui::Palette::panel
Color panel
Definition
style.h:227
rex::ui::Palette::operator==
bool operator==(const Palette &other) const =default
rex::ui::Palette::shadow
Color shadow
Definition
style.h:241
rex::ui::Palette::button_alpha
f32 button_alpha
Definition
style.h:223
rex::ui::Palette::panel_popup
Color panel_popup
Definition
style.h:229
rex::ui::Palette::highlight
Color highlight
Definition
style.h:239
rex::ui::Palette::accent
Color accent
Definition
style.h:221
rex::ui::SettingsStyle
Definition
style.h:346
rex::ui::SettingsStyle::warning
Color warning
Definition
style.h:348
rex::ui::SettingsStyle::lifecycle_unknown
Color lifecycle_unknown
Definition
style.h:356
rex::ui::SettingsStyle::lifecycle_hot_reload
Color lifecycle_hot_reload
Definition
style.h:350
rex::ui::SettingsStyle::lifecycle_restart
Color lifecycle_restart
Definition
style.h:352
rex::ui::SettingsStyle::lifecycle_init_only
Color lifecycle_init_only
Definition
style.h:354
rex::ui::Style
Definition
style.h:360
rex::ui::ToastStyle
Definition
style.h:319
rex::ui::ToastStyle::title
Color title
Definition
style.h:323
rex::ui::ToastStyle::text
Color text
Definition
style.h:321
rex::ui::WindowAlpha
Definition
style.h:251
rex::ui::WindowAlpha::toast
f32 toast
Definition
style.h:257
rex::ui::WindowAlpha::overlay
f32 overlay
Definition
style.h:253
rex::ui::WindowAlpha::operator==
bool operator==(const WindowAlpha &other) const =default
rex::ui::WindowAlpha::panel
f32 panel
Definition
style.h:255
rex::ui::WindowAlpha::hud
f32 hud
Definition
style.h:259
rex::ui::ApplyDefaultStyle
REX_UI_API void ApplyDefaultStyle(ImGuiStyle &imgui_style, const Palette &palette, const Metrics &metrics)
rex::ui::FromImVec4
Color FromImVec4(const ImVec4 &value)
Definition
style.h:397
rex::ui::ToImU32
ImU32 ToImU32(Color color)
Definition
style.h:388
rex::ui::ToImVec4
ImVec4 ToImVec4(Color color)
Definition
style.h:379
types.h
Integer types, byte order wrappers and size literals.
rex
ui
style.h
Generated by
1.18.0