From 3dc154772109f7e0373dddf7118bb3d2608c276c Mon Sep 17 00:00:00 2001 From: Guillaume Meunier Date: Sun, 26 Jul 2026 14:42:23 +0200 Subject: [PATCH] Allow setting the theme from the stream scene --- client/scenes/gui_settings.cpp | 118 +++++++++++++++++++++++++ client/scenes/gui_settings.h | 1 + client/scenes/lobby_gui_settings.cpp | 5 ++ client/scenes/lobby_gui_theme.cpp | 124 --------------------------- client/scenes/stream.h | 1 + client/scenes/stream_gui.cpp | 4 + 6 files changed, 129 insertions(+), 124 deletions(-) diff --git a/client/scenes/gui_settings.cpp b/client/scenes/gui_settings.cpp index c603b32e..c3b4eadd 100644 --- a/client/scenes/gui_settings.cpp +++ b/client/scenes/gui_settings.cpp @@ -745,4 +745,122 @@ void settings_system(const settings_context & ctx) render_settings(ctx, "##system", list); } +void settings_theme(const settings_context & ctx) +{ + ui::theme & theme = ui::current(); + auto & config = ctx.config; + + ui::page_header(_cS("page header title", "Theme"), _cS("page header subtitle", "Accent color, palette and sizing of the interface.")); + + ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ui::metrics::card_item_spacing); + const float control_w = ui::metrics::setting_control_width; + + ui::begin_card("##theme"); + { + // Accent + ImGui::TextUnformatted(_cS("setting name", "Accent color")); + ImGui::Dummy({0, 2}); + for (const auto & swatch: ui::accent_swatches()) + { + const bool selected = theme.accent.x == swatch.base.x and theme.accent.y == swatch.base.y and theme.accent.z == swatch.base.z; + const auto flags = ImGuiColorEditFlags_NoTooltip | ImGuiColorEditFlags_NoBorder | (selected ? 0 : ImGuiColorEditFlags_NoDragDrop); + if (ImGui::ColorButton(swatch.name, swatch.base, flags, {ImGui::GetFrameHeight() * 1.4f, ImGui::GetFrameHeight() * 1.4f})) + { + ui::set_accent(swatch); + config.theme_accent = swatch.name; + config.save(); + } + ImGui::SameLine(); + } + ImGui::NewLine(); + + ui::row_separator(); + + // Preset + const auto preset_list = ui::presets(); + std::vector preset_items; + for (const auto & p: preset_list) + preset_items.push_back({p.localized_name.c_str()}); + + // seed the selection from the saved preset so the box matches what is applied + static int preset = [&] { + for (int i = 0; i < int(preset_list.size()); ++i) + if (preset_list[i].name == config.theme_preset) + return i; + return 1; // dark_default + }(); + + static const int preset_default = 1; + ui::setting_label(_cS("setting name", "Preset"), _cS("setting description", "Surface and background palette"), control_w); + if (ui::combo("##preset", _("Theme preset"), preset_items, &preset, control_w, &preset_default)) + { + // keep the accent across a preset change, only the surfaces swap + const ImVec4 keep_accent = theme.accent; + const ImVec4 keep_hover = theme.accent_hovered; + const ImVec4 keep_active = theme.accent_active; + ui::set_theme(preset_list[preset]); + theme.accent = keep_accent; + theme.accent_hovered = keep_hover; + theme.accent_active = keep_active; + config.theme_preset = preset_list[preset].name; + config.save(); + } + + ui::row_separator(); + + // Rounding + static const int rounding_default = 8; + int rounding = int(theme.rounding); + ui::setting_label(_cS("setting label", "Rounding"), _cS("setting description", "Corner radius of controls"), control_w); + if (ui::slider_int("##rounding", &rounding, 0, 20, "%d px", {control_w, 0}, &rounding_default)) + { + theme.rounding = float(rounding); + config.theme_rounding = theme.rounding; + config.save(); + } + + ui::row_separator(); + + static const int card_rounding_default = 14; + int card_rounding = int(theme.card_rounding); + ui::setting_label(_cS("setting label", "Card rounding"), _cS("setting description", "Corner radius of panels"), control_w); + if (ui::slider_int("##card_rounding", &card_rounding, 0, 28, "%d px", {control_w, 0}, &card_rounding_default)) + { + theme.card_rounding = float(card_rounding); + config.theme_card_rounding = theme.card_rounding; + config.save(); + } + + ui::row_separator(); + + // global font scale, 100% is the design default + static const int font_scale_default = 100; + int font_scale = int(theme.font_scale * 100); + ui::setting_label(_cS("setting name", "Text size"), _cS("setting description", "Global font scale"), control_w); + if (ui::slider_int("##font_scale", &font_scale, 60, 140, "%d%%", {control_w, 0}, &font_scale_default)) + { + theme.font_scale = float(font_scale) / 100.f; + config.theme_font_scale = theme.font_scale; + config.save(); + } + + ui::row_separator(); + + // Panel transparency, independent of the selected preset + static const int opacity_default = 90; + int opacity = int(ui::background_alpha() * 100); + ui::setting_label(_cS("setting name", "Panel opacity"), _cS("setting description", "Opacity of the panel and card backgrounds"), control_w); + if (ui::slider_int("##opacity", &opacity, 20, 100, "%d%%", {control_w, 0}, &opacity_default)) + { + ui::background_alpha() = float(opacity) / 100.f; + config.theme_background_alpha = ui::background_alpha(); + config.save(); + } + + ui::end_card(); + } + + ImGui::PopStyleVar(); // ImGuiStyleVar_ItemSpacing +} + } // namespace wivrn::gui diff --git a/client/scenes/gui_settings.h b/client/scenes/gui_settings.h index 3cc0e6ca..dda2a2a7 100644 --- a/client/scenes/gui_settings.h +++ b/client/scenes/gui_settings.h @@ -67,5 +67,6 @@ void settings_audio(const settings_context &); void settings_devices(const settings_context &); bool settings_tracking(const settings_context &); void settings_system(const settings_context &); +void settings_theme(const settings_context &); } // namespace wivrn::gui diff --git a/client/scenes/lobby_gui_settings.cpp b/client/scenes/lobby_gui_settings.cpp index 962ac8ae..65e88201 100644 --- a/client/scenes/lobby_gui_settings.cpp +++ b/client/scenes/lobby_gui_settings.cpp @@ -76,3 +76,8 @@ void scenes::lobby::gui_system() { wivrn::gui::settings_system(lobby_settings_context(instance, session, system, *imgui_ctx, stream_view, server_hid_forwarding)); } + +void scenes::lobby::gui_theme() +{ + wivrn::gui::settings_theme(lobby_settings_context(instance, session, system, *imgui_ctx, stream_view, server_hid_forwarding)); +} diff --git a/client/scenes/lobby_gui_theme.cpp b/client/scenes/lobby_gui_theme.cpp index 88a22526..6ddab650 100644 --- a/client/scenes/lobby_gui_theme.cpp +++ b/client/scenes/lobby_gui_theme.cpp @@ -24,13 +24,7 @@ #include "application.h" #include "configuration.h" #include "render/ui_theme.h" -#include "render/ui_widgets.h" -#include "utils/i18n.h" - -#include "imgui.h" - #include -#include namespace ui = wivrn::ui; @@ -63,121 +57,3 @@ void scenes::lobby::apply_theme_settings() theme.font_scale = config.theme_font_scale; ui::background_alpha() = config.theme_background_alpha; } - -void scenes::lobby::gui_theme() -{ - ui::theme & theme = ui::current(); - auto & config = application::get_config(); - - ui::page_header(_cS("page header title", "Theme"), _cS("page header subtitle", "Accent color, palette and sizing of the interface.")); - - ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ui::metrics::card_item_spacing); - const float control_w = ui::metrics::setting_control_width; - - ui::begin_card("##theme"); - { - // Accent - ImGui::TextUnformatted(_cS("setting name", "Accent color")); - ImGui::Dummy({0, 2}); - for (const auto & swatch: ui::accent_swatches()) - { - const bool selected = theme.accent.x == swatch.base.x and theme.accent.y == swatch.base.y and theme.accent.z == swatch.base.z; - const auto flags = ImGuiColorEditFlags_NoTooltip | ImGuiColorEditFlags_NoBorder | (selected ? 0 : ImGuiColorEditFlags_NoDragDrop); - if (ImGui::ColorButton(swatch.name, swatch.base, flags, {ImGui::GetFrameHeight() * 1.4f, ImGui::GetFrameHeight() * 1.4f})) - { - ui::set_accent(swatch); - config.theme_accent = swatch.name; - config.save(); - } - ImGui::SameLine(); - } - ImGui::NewLine(); - - ui::row_separator(); - - // Preset - const auto preset_list = ui::presets(); - std::vector preset_items; - for (const auto & p: preset_list) - preset_items.push_back({p.localized_name.c_str()}); - - // seed the selection from the saved preset so the box matches what is applied - static int preset = [&] { - for (int i = 0; i < int(preset_list.size()); ++i) - if (preset_list[i].name == config.theme_preset) - return i; - return 1; // dark_default - }(); - - static const int preset_default = 1; - ui::setting_label(_cS("setting name", "Preset"), _cS("setting description", "Surface and background palette"), control_w); - if (ui::combo("##preset", _("Theme preset"), preset_items, &preset, control_w, &preset_default)) - { - // keep the accent across a preset change, only the surfaces swap - const ImVec4 keep_accent = theme.accent; - const ImVec4 keep_hover = theme.accent_hovered; - const ImVec4 keep_active = theme.accent_active; - ui::set_theme(preset_list[preset]); - theme.accent = keep_accent; - theme.accent_hovered = keep_hover; - theme.accent_active = keep_active; - config.theme_preset = preset_list[preset].name; - config.save(); - } - - ui::row_separator(); - - // Rounding - static const int rounding_default = 8; - int rounding = int(theme.rounding); - ui::setting_label(_cS("setting label", "Rounding"), _cS("setting description", "Corner radius of controls"), control_w); - if (ui::slider_int("##rounding", &rounding, 0, 20, "%d px", {control_w, 0}, &rounding_default)) - { - theme.rounding = float(rounding); - config.theme_rounding = theme.rounding; - config.save(); - } - - ui::row_separator(); - - static const int card_rounding_default = 14; - int card_rounding = int(theme.card_rounding); - ui::setting_label(_cS("setting label", "Card rounding"), _cS("setting description", "Corner radius of panels"), control_w); - if (ui::slider_int("##card_rounding", &card_rounding, 0, 28, "%d px", {control_w, 0}, &card_rounding_default)) - { - theme.card_rounding = float(card_rounding); - config.theme_card_rounding = theme.card_rounding; - config.save(); - } - - ui::row_separator(); - - // global font scale, 100% is the design default - static const int font_scale_default = 100; - int font_scale = int(theme.font_scale * 100); - ui::setting_label(_cS("setting name", "Text size"), _cS("setting description", "Global font scale"), control_w); - if (ui::slider_int("##font_scale", &font_scale, 60, 140, "%d%%", {control_w, 0}, &font_scale_default)) - { - theme.font_scale = float(font_scale) / 100.f; - config.theme_font_scale = theme.font_scale; - config.save(); - } - - ui::row_separator(); - - // Panel transparency, independent of the selected preset - static const int opacity_default = 90; - int opacity = int(ui::background_alpha() * 100); - ui::setting_label(_cS("setting name", "Panel opacity"), _cS("setting description", "Opacity of the panel and card backgrounds"), control_w); - if (ui::slider_int("##opacity", &opacity, 20, 100, "%d%%", {control_w, 0}, &opacity_default)) - { - ui::background_alpha() = float(opacity) / 100.f; - config.theme_background_alpha = ui::background_alpha(); - config.save(); - } - - ui::end_card(); - } - - ImGui::PopStyleVar(); // ImGuiStyleVar_ItemSpacing -} diff --git a/client/scenes/stream.h b/client/scenes/stream.h index 5a54e956..0cf6be0a 100644 --- a/client/scenes/stream.h +++ b/client/scenes/stream.h @@ -151,6 +151,7 @@ private: audio, devices, tracking, + theme, system, }; settings_page current_settings_page = settings_page::performance; diff --git a/client/scenes/stream_gui.cpp b/client/scenes/stream_gui.cpp index da022513..ee302a02 100644 --- a/client/scenes/stream_gui.cpp +++ b/client/scenes/stream_gui.cpp @@ -448,6 +448,9 @@ void scenes::stream::gui_settings(float) case settings_page::system: wivrn::gui::settings_system(ctx); break; + case settings_page::theme: + wivrn::gui::settings_theme(ctx); + break; } } @@ -984,6 +987,7 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte settings_item(ICON_FA_KEYBOARD, _cS("tab label", "Devices"), settings_page::devices); settings_item(ICON_FA_LOCATION_CROSSHAIRS, _cS("tab label", "Tracking"), settings_page::tracking); settings_item(ICON_FA_GEARS, _cS("tab label", "System"), settings_page::system); + settings_item(ICON_FA_PALETTE, _cS("tab label", "Theme"), settings_page::theme); // pinned to the bottom wivrn::ui::sidebar_footer();