From 12834824ab77060fa4128837288f7790f4308ca5 Mon Sep 17 00:00:00 2001 From: ahsanswr Date: Sat, 13 Jun 2026 18:13:11 +0500 Subject: [PATCH] Fixes and improvements --- client/constants.h | 2 +- client/render/imgui_impl.cpp | 14 +- client/render/ui_theme.cpp | 8 +- client/render/ui_theme.h | 14 +- client/render/ui_widgets.cpp | 174 +++++++++--- client/render/ui_widgets.h | 8 +- client/scenes/lobby.h | 5 +- client/scenes/lobby_gui.cpp | 201 +++++++++----- client/scenes/lobby_gui_components.cpp | 363 ------------------------- client/scenes/lobby_gui_customize.cpp | 2 +- client/scenes/lobby_gui_theme.cpp | 122 +++++++++ 11 files changed, 432 insertions(+), 481 deletions(-) delete mode 100644 client/scenes/lobby_gui_components.cpp create mode 100644 client/scenes/lobby_gui_theme.cpp diff --git a/client/constants.h b/client/constants.h index f35738e0..10d40b93 100644 --- a/client/constants.h +++ b/client/constants.h @@ -143,7 +143,7 @@ constexpr ImVec2 window_padding = {20, 20}; constexpr float window_border_size = 2; constexpr float window_rounding = 10; -constexpr ImVec2 tooltip_padding = {5, 5}; +constexpr ImVec2 tooltip_padding = {16, 12}; constexpr float tooltip_rounding = 0; constexpr glm::vec3 tooltip_distance = {0, 0.004, 0.005}; diff --git a/client/render/imgui_impl.cpp b/client/render/imgui_impl.cpp index 2b7fd3a2..e963fea8 100644 --- a/client/render/imgui_impl.cpp +++ b/client/render/imgui_impl.cpp @@ -24,6 +24,7 @@ #include "constants.h" #include "image_loader.h" #include "openxr/openxr.h" +#include "ui_theme.h" #include "utils/mapped_file.h" #include "utils/ranges.h" #include "utils/strings.h" @@ -1280,10 +1281,14 @@ void imgui_context::tooltip(std::string_view text) viewport->Pos = ImVec2(tooltip_layer.vp_origin.x, tooltip_layer.vp_origin.y); viewport->Size = ImVec2(tooltip_layer.vp_size.x, tooltip_layer.vp_size.y); - // Draw the tooltip in the tooltip layer + // Draw the tooltip in the tooltip layer, styled to match the active theme // Clamp position to avoid overflowing on the left or the right + const wivrn::ui::theme & t = wivrn::ui::current(); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, constants::style::tooltip_padding); - ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, constants::style::tooltip_rounding); + ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, t.card_rounding); + ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, t.border_size); + ImGui::PushStyleColor(ImGuiCol_PopupBg, t.card); + ImGui::PushStyleColor(ImGuiCol_Border, t.border); auto & style = ImGui::GetStyle(); const ImVec2 text_size = ImGui::CalcTextSize(text.data(), text.data() + text.size(), true); @@ -1293,12 +1298,13 @@ void imgui_context::tooltip(std::string_view text) ImGui::SetNextWindowSizeConstraints({0, 0}, viewport->Size); if (ImGui::BeginTooltip()) { - ImGui::PushStyleColor(ImGuiCol_Text, 0xffffffff); + ImGui::PushStyleColor(ImGuiCol_Text, t.col(t.text)); ImGui::TextUnformatted(text.data(), text.data() + text.size()); ImGui::PopStyleColor(); ImGui::EndTooltip(); } - ImGui::PopStyleVar(2); + ImGui::PopStyleColor(2); + ImGui::PopStyleVar(3); viewport->Pos = pos_backup; viewport->Size = size_backup; diff --git a/client/render/ui_theme.cpp b/client/render/ui_theme.cpp index 00a87e00..0250dacf 100644 --- a/client/render/ui_theme.cpp +++ b/client/render/ui_theme.cpp @@ -56,8 +56,8 @@ static theme dark_default() t.rounding = 8; t.card_rounding = 14; t.border_size = 1; - t.font_scale = 1.0; // user multiplier; 100% maps to metrics::font_base - t.background_alpha = 0.88f; // ~ the previous hardcoded 224/255 + t.font_scale = 1.0; // user multiplier; 100% maps to metrics::font_base + t.background_alpha = 1.0f; // fully opaque panel by default return t; } @@ -128,7 +128,7 @@ static theme light() { theme t = dark_default(); t.name = "Light"; - t.background = rgb(236, 238, 242); + t.background = rgb(221, 224, 230); t.card = rgb(255, 255, 255); t.card_hovered = rgb(246, 247, 250); t.control = rgb(212, 216, 224); @@ -136,7 +136,7 @@ static theme light() t.control_active = rgb(184, 190, 201); t.text = rgb(22, 24, 30); t.text_muted = rgb(108, 114, 126); - t.border = rgb(205, 209, 217); + t.border = rgb(176, 182, 194); return t; } diff --git a/client/render/ui_theme.h b/client/render/ui_theme.h index 41558af4..d2a15f1c 100644 --- a/client/render/ui_theme.h +++ b/client/render/ui_theme.h @@ -97,18 +97,20 @@ constexpr float slider_grab_width = 14; constexpr float segmented_inset = 3; // gap around the active segment -constexpr float icon_button_glyph = 0.5; // glyph height as a fraction of the button side +constexpr float icon_button_glyph = 0.58; // glyph height as a fraction of the button side +constexpr float button_label_glyph = 1.35; // leading icon size in a labeled button, x base text size constexpr float combo_row_height = 2.2; // x frame height, big touch rows in the modal constexpr float combo_chevron = 12; // chevron size in the closed box constexpr float combo_modal_min_width = 460; // popup never narrower than this constexpr ImVec2 combo_padding = {16, 0}; // horizontal inner padding of box and rows -constexpr float list_row_box = 52; // leading icon/thumbnail size in a list row -constexpr float list_row_pad = 16; // inner padding of a list row, both axes -constexpr ImVec2 chip_padding = {12, 6}; // inner padding of a chip/badge -constexpr float input_padding_x = 14; // horizontal text padding inside inputs -constexpr float font_modal_title = 1.2; // modal heading, x base font size +constexpr float list_row_box = 52; // leading icon/thumbnail size in a list row +constexpr float list_row_pad = 12; // inner padding of a list row, both axes +constexpr ImVec2 chip_padding = {12, 6}; // inner padding of a chip/badge +constexpr float chip_pill_padding_x = 18; // roomier horizontal padding for height-override pill chips (top bar) +constexpr float input_padding_x = 14; // horizontal text padding inside inputs +constexpr float font_modal_title = 1.2; // modal heading, x base font size constexpr float label_line_gap = 5; // title to description constexpr float label_bottom_pad = 6; // breathing room below the description diff --git a/client/render/ui_widgets.cpp b/client/render/ui_widgets.cpp index 3a7a5647..46846c64 100644 --- a/client/render/ui_widgets.cpp +++ b/client/render/ui_widgets.cpp @@ -171,15 +171,25 @@ float setting_label(const std::string & title, const std::string & description, ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, {style.ItemSpacing.x, metrics::label_line_gap}); ImGui::PushTextWrapPos(start.x + text_w); ImGui::TextUnformatted(title.c_str()); + ImGui::PopTextWrapPos(); if (not description.empty()) { ImGui::PushFont(nullptr, style.FontSizeBase * metrics::font_description); ImGui::PushStyleColor(ImGuiCol_Text, t.text_muted); - ImGui::TextUnformatted(description.c_str()); + // single line, capped at half the row width and ellipsized so it never wraps or crowds the control + const float desc_w = ImMin(text_w, avail * 0.5f); + std::string text = description; + if (ImGui::CalcTextSize(text.c_str()).x > desc_w) + { + const float ell_w = ImGui::CalcTextSize("...").x; + while (not text.empty() and ImGui::CalcTextSize(text.c_str()).x + ell_w > desc_w) + text.pop_back(); + text += "..."; + } + ImGui::TextUnformatted(text.c_str()); ImGui::PopStyleColor(); ImGui::PopFont(); } - ImGui::PopTextWrapPos(); ImGui::PopStyleVar(); // right-aligned control slot, vertically centered against the label block @@ -190,6 +200,30 @@ float setting_label(const std::string & title, const std::string & description, return start.y + label_h; } +namespace +{ +struct button_colors +{ + ImVec4 bg, bg_hovered, bg_active, text; +}; + +button_colors colors_for(button_style s, const theme & t) +{ + switch (s) + { + case button_style::primary: + return {t.accent, t.accent_hovered, t.accent_active, t.on_accent}; + case button_style::secondary: + return {t.control, t.control_hovered, t.control_active, t.text}; + case button_style::danger: + return {t.danger, t.danger_hovered, t.danger, t.on_accent}; + case button_style::ghost: + return {{0, 0, 0, 0}, t.control, t.control_active, t.text}; + } + return {}; +} +} // namespace + bool button(const std::string & label, button_style s, const ImVec2 & size) { const theme & t = current(); @@ -197,33 +231,11 @@ bool button(const std::string & label, button_style s, const ImVec2 & size) // control height by default, width auto-fits the label const float h = size.y > 0 ? size.y : ImGui::GetFrameHeight() * metrics::control_height; - switch (s) - { - case button_style::primary: - ImGui::PushStyleColor(ImGuiCol_Button, t.accent); - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, t.accent_hovered); - ImGui::PushStyleColor(ImGuiCol_ButtonActive, t.accent_active); - ImGui::PushStyleColor(ImGuiCol_Text, t.on_accent); - break; - case button_style::secondary: - ImGui::PushStyleColor(ImGuiCol_Button, t.control); - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, t.control_hovered); - ImGui::PushStyleColor(ImGuiCol_ButtonActive, t.control_active); - ImGui::PushStyleColor(ImGuiCol_Text, t.text); - break; - case button_style::danger: - ImGui::PushStyleColor(ImGuiCol_Button, t.danger); - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, t.danger_hovered); - ImGui::PushStyleColor(ImGuiCol_ButtonActive, t.danger); - ImGui::PushStyleColor(ImGuiCol_Text, t.on_accent); - break; - case button_style::ghost: - ImGui::PushStyleColor(ImGuiCol_Button, ImVec4{0, 0, 0, 0}); - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, t.control); - ImGui::PushStyleColor(ImGuiCol_ButtonActive, t.control_active); - ImGui::PushStyleColor(ImGuiCol_Text, t.text); - break; - } + const button_colors c = colors_for(s, t); + ImGui::PushStyleColor(ImGuiCol_Button, c.bg); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, c.bg_hovered); + ImGui::PushStyleColor(ImGuiCol_ButtonActive, c.bg_active); + ImGui::PushStyleColor(ImGuiCol_Text, c.text); ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, t.rounding); ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, metrics::button_padding); @@ -234,6 +246,69 @@ bool button(const std::string & label, button_style s, const ImVec2 & size) return pressed; } +bool button(const char * icon, const std::string & label, button_style s, const ImVec2 & size) +{ + ImGuiWindow * window = ImGui::GetCurrentWindow(); + if (window->SkipItems) + return false; + + ImGuiContext & g = *GImGui; + const ImGuiStyle & style = g.Style; + const theme & t = current(); + + const float h = size.y > 0 ? size.y : ImGui::GetFrameHeight() * metrics::control_height; + const float glyph_size = ImGui::GetFontSize() * metrics::button_label_glyph; + const float gap = ImGui::GetFontSize() * 0.4f; + + ImGui::PushFont(nullptr, glyph_size); + const float icon_w = ImGui::CalcTextSize(icon).x; + ImGui::PopFont(); + const ImVec2 label_size = ImGui::CalcTextSize(label.c_str()); + const float content_w = icon_w + gap + label_size.x; + const float w = size.x > 0 ? size.x : content_w + metrics::button_padding.x * 2; + + const ImVec2 pos = window->DC.CursorPos; + const ImRect bb(pos, pos + ImVec2{w, h}); + ImGui::ItemSize(bb, style.FramePadding.y); + const ImGuiID id = window->GetID(label.c_str()); + if (not ImGui::ItemAdd(bb, id)) + return false; + + bool hovered, held; + const bool pressed = ImGui::ButtonBehavior(bb, id, &hovered, &held); + hover_haptic(); + + const button_colors c = colors_for(s, t); + ImVec4 bg = c.bg; + if (held) + bg = c.bg_active; + else if (hovered) + bg = c.bg_hovered; + + ImDrawList * draw = window->DrawList; + draw->AddRectFilled(bb.Min, bb.Max, t.col(bg), t.rounding); + + const ImU32 col = t.col(c.text); + const ImVec2 center = bb.GetCenter(); + float x = center.x - content_w * 0.5f; + + // icon centred vertically on its ink box, like icon_button + ImGui::PushFont(nullptr, glyph_size); + unsigned int codepoint = 0; + ImTextCharFromUtf8(&codepoint, icon, nullptr); + const ImFontGlyph * glyph = ImGui::GetFontBaked()->FindGlyph((ImWchar)codepoint); + if (glyph) + draw->AddText({x, center.y - (glyph->Y0 + glyph->Y1) * 0.5f}, col, icon); + else + draw->AddText({x, center.y - glyph_size * 0.5f}, col, icon); + ImGui::PopFont(); + + x += icon_w + gap; + draw->AddText({x, center.y - label_size.y * 0.5f}, col, label.c_str()); + + return pressed; +} + bool icon_button(const char * icon, const ImVec2 & size_arg, bool active, const std::string & tooltip) { ImGuiWindow * window = ImGui::GetCurrentWindow(); @@ -404,7 +479,11 @@ bool slider_int(const char * id, int * v, int v_min, int v_max, const char * for ImDrawList * draw = window->DrawList; draw->AddRectFilled(bb.Min, bb.Max, t.col(t.control), t.rounding); if (fraction > 0) - draw->AddRectFilled(bb.Min, {fill_x, bb.Max.y}, t.col(t.accent_active), t.rounding, ImDrawFlags_RoundCornersLeft); + { + // round the right corners too once the fill reaches the box edge, else they stay sharp over the rounded background + const ImDrawFlags fill_flags = fill_x >= bb.Max.x - t.rounding ? ImDrawFlags_RoundCornersAll : ImDrawFlags_RoundCornersLeft; + draw->AddRectFilled(bb.Min, {fill_x, bb.Max.y}, t.col(t.accent_active), t.rounding, fill_flags); + } // bright grab at the fill edge const float grab_w = metrics::slider_grab_width; const float gx = ImClamp(fill_x, bb.Min.x + grab_w * 0.5f, bb.Max.x - grab_w * 0.5f); @@ -498,6 +577,8 @@ namespace { // Where combo modals open, in imgui display coords. Set each frame by the lobby. ImVec2 popup_center = {0, 0}; +// Height of the popup layer; caps tall combo lists so they scroll. 0 = unbounded. +float popup_available_height = 0; // One selectable option inside the combo modal. A tall, full-width touch target // with the name (accent when selected) and an optional muted description. @@ -554,9 +635,10 @@ bool combo_row(const combo_item & item, bool selected) } } // namespace -void set_popup_center(const ImVec2 & center) +void set_popup_center(const ImVec2 & center, float available_height) { popup_center = center; + popup_available_height = available_height; } bool combo(const char * id, const std::string & title, const std::vector & items, int * selected, float width, const int * default_value) @@ -636,15 +718,33 @@ bool combo(const char * id, const std::string & title, const std::vector 0) + { + const float title_h = title.empty() ? 0 : ImGui::GetTextLineHeight() + style.ItemSpacing.y; + const float max_list = popup_available_height * 0.9f - 2 * metrics::card_padding.y - title_h; + list_h = ImMin(list_h, ImMax(max_list, row_h)); + } + + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, {0, 0}); + ImGui::BeginChild("##list", {0, list_h}); for (int i = 0; i < int(items.size()); ++i) { - if (combo_row(items[i], i == sel)) + const bool is_sel = i == sel; + if (combo_row(items[i], is_sel)) { *selected = i; changed = true; ImGui::CloseCurrentPopup(); } + if (is_sel and ImGui::IsWindowAppearing()) + ImGui::SetScrollHereY(0.5f); // reveal the current value when opening } + ImGui::EndChild(); + ImGui::PopStyleVar(); // click outside dismisses; AllowWhenBlockedByActiveItem so pressing a row still counts as inside if (ImGui::IsMouseClicked(ImGuiMouseButton_Left) and not ImGui::IsWindowHovered(ImGuiHoveredFlags_RootAndChildWindows | ImGuiHoveredFlags_AllowWhenBlockedByActiveItem)) @@ -703,9 +803,11 @@ void chip(const std::string & label, chip_style style, bool dot, float height) const ImVec2 ts = ImGui::CalcTextSize(label.c_str()); const ImVec2 pad = metrics::chip_padding; + // tall pill chips (height override, e.g. the top bar) get roomier sides + const float pad_x = height > 0 ? metrics::chip_pill_padding_x : pad.x; const float dot_r = ts.y * 0.26f; - const float dot_gap = dot ? dot_r * 2 + pad.x * 0.55f : 0; - const ImVec2 size = {ts.x + pad.x * 2 + dot_gap, height > 0 ? height : ts.y + pad.y * 2}; + const float dot_gap = dot ? dot_r * 2 + pad_x * 0.55f : 0; + const ImVec2 size = {ts.x + pad_x * 2 + dot_gap, height > 0 ? height : ts.y + pad.y * 2}; const ImVec2 pos = window->DC.CursorPos; const ImRect bb(pos, pos + size); @@ -716,11 +818,11 @@ void chip(const std::string & label, chip_style style, bool dot, float height) ImDrawList * draw = window->DrawList; draw->AddRectFilled(bb.Min, bb.Max, t.col(bg), size.y * 0.5f); - float tx = bb.Min.x + pad.x; + float tx = bb.Min.x + pad_x; if (dot) { draw->AddCircleFilled({tx + dot_r, bb.Min.y + size.y * 0.5f}, dot_r, t.col(fg)); - tx += dot_r * 2 + pad.x * 0.55f; + tx += dot_r * 2 + pad_x * 0.55f; } draw->AddText({tx, bb.Min.y + (size.y - ts.y) * 0.5f}, t.col(fg), label.c_str()); } diff --git a/client/render/ui_widgets.h b/client/render/ui_widgets.h index 3684948f..2abb0fb4 100644 --- a/client/render/ui_widgets.h +++ b/client/render/ui_widgets.h @@ -53,6 +53,8 @@ void row_separator(); float setting_label(const std::string & title, const std::string & description, float control_width); bool button(const std::string & label, button_style style = button_style::primary, const ImVec2 & size = {0, 0}); +// Same, with a larger leading icon glyph drawn before the label +bool button(const char * icon, const std::string & label, button_style style = button_style::primary, const ImVec2 & size = {0, 0}); // tooltip, if not empty, is shown while hovered bool icon_button(const char * icon, const ImVec2 & size = {0, 0}, bool active = false, const std::string & tooltip = {}); @@ -77,8 +79,10 @@ struct combo_item // chosen index, title labels the modal. Returns true when the selection changes. bool combo(const char * id, const std::string & title, const std::vector & items, int * selected, float width = 0, const int * default_value = nullptr); -// Centre (display coords) where combo and begin_modal popups open. Set once per frame. -void set_popup_center(const ImVec2 & center); +// Centre (display coords) where combo and begin_modal popups open, plus the height +// available on the popup layer so tall combo lists cap and scroll instead of being +// clipped. available_height of 0 leaves the list unbounded. Set once per frame. +void set_popup_center(const ImVec2 & center, float available_height = 0); // Hook fired after an interactive item, for a hover haptic. Install once. void set_hover_haptic(std::function hook); diff --git a/client/scenes/lobby.h b/client/scenes/lobby.h index afe7eafd..82aa1eca 100644 --- a/client/scenes/lobby.h +++ b/client/scenes/lobby.h @@ -56,6 +56,7 @@ class lobby : public scene_impl int add_server_window_port = wivrn::default_port; bool add_server_tcp_only = false; std::string add_server_cookie; + std::string delete_server_cookie; // server pending a delete confirmation utils::future, std::string> async_session; std::optional async_error; @@ -126,8 +127,8 @@ class lobby : public scene_impl tracking, system, customize, + theme, #if WIVRN_CLIENT_DEBUG_MENU - components, debug, #endif about, @@ -237,7 +238,7 @@ class lobby : public scene_impl void gui_system(); void gui_post_processing(); void gui_customize(XrTime predicted_display_time); - void gui_components(); + void gui_theme(); void gui_debug_node_hierarchy(entt::entity root = entt::null); void gui_debug(); void gui_about(); diff --git a/client/scenes/lobby_gui.cpp b/client/scenes/lobby_gui.cpp index 85110564..ec15275d 100644 --- a/client/scenes/lobby_gui.cpp +++ b/client/scenes/lobby_gui.cpp @@ -366,10 +366,14 @@ void scenes::lobby::gui_server_list() ui::page_header(_S("Computers"), _S("Pick a PC running the WiVRn server to stream from.")); const ImVec2 hend = ImGui::GetCursorPos(); - const std::string add_label = std::string(ICON_FA_PLUS " ") + _("Add server"); - const float add_w = ImGui::CalcTextSize(add_label.c_str()).x + ui::metrics::button_padding.x * 2; + const std::string add_label = _("Add server"); + const float font = ImGui::GetFontSize(); + ImGui::PushFont(nullptr, font * ui::metrics::button_label_glyph); + const float glyph_w = ImGui::CalcTextSize(ICON_FA_PLUS).x; + ImGui::PopFont(); + const float add_w = glyph_w + font * 0.4f + ImGui::CalcTextSize(add_label.c_str()).x + ui::metrics::button_padding.x * 2; ImGui::SetCursorPos({hstart.x + header_avail - add_w, hstart.y}); - if (ui::button(add_label, ui::button_style::primary)) + if (ui::button(ICON_FA_PLUS, add_label, ui::button_style::primary)) { add_server_cookie = ""; add_server_window_prettyname = ""; @@ -384,10 +388,10 @@ void scenes::lobby::gui_server_list() for (auto && [cookie, data]: config.servers) sorted_cookies.emplace(data.service.name, cookie); - std::string cookie_to_remove; - // deferred: the action menu runs inside the per-row id stack, but the popup is + // deferred: the action menu runs inside the per-row id stack, but the popups are // opened below in this scope so OpenPopup and begin_modal hash to the same id bool open_add_edit = false; + bool open_delete = false; ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, {12, 10}); ui::begin_card("##servers"); @@ -408,14 +412,22 @@ void scenes::lobby::gui_server_list() ui::row_separator(); first = false; - const bool available = (data.visible and data.compatible) or data.manual; + // Connect button reflects the real reachability state so a momentary + // discovery delay doesn't read as a hard failure: + // - reachable: manual server, or one discovered with a matching protocol + // - incompatible: discovered and resolved, but the protocol version differs + // - searching: not seen on the network yet (or still resolving its records) + const bool reachable = (data.visible and data.compatible) or data.manual; + const bool incompatible = data.visible and data.service.txt.contains("protocol") and not data.compatible; const float gap = ImGui::GetStyle().ItemSpacing.x; const float bh = ImGui::GetFrameHeight() * ui::metrics::control_height; const std::string sub = fmt::format("{} : {}", data.service.hostname, data.service.port); // trailing controls: [Auto chip] [Connect] [menu], measured up front so the // row body click area can exclude them - const std::string c_label = available ? std::string(ICON_FA_PLAY " ") + _("Connect") : _("Unavailable"); + const char * c_icon = reachable ? ICON_FA_PLAY : (incompatible ? ICON_FA_TRIANGLE_EXCLAMATION : ICON_FA_MAGNIFYING_GLASS); + const std::string c_label = std::string(c_icon) + " " + (reachable ? _("Connect") : (incompatible ? _("Incompatible") : _("Searching…"))); + const std::string c_tooltip = reachable ? std::string{} : (incompatible ? _("Incompatible server version") : _("Looking for this server on your network")); const float cw = ImGui::CalcTextSize(c_label.c_str()).x + ui::metrics::button_padding.x * 2; const std::string chip_label = std::string(ICON_FA_BOLT " ") + _("Auto"); const ImVec2 chip_ts = ImGui::CalcTextSize(chip_label.c_str()); @@ -453,19 +465,22 @@ void scenes::lobby::gui_server_list() open_add_edit = true; break; case 2: - cookie_to_remove = cookie; + delete_server_cookie = cookie; + open_delete = true; break; } x -= bh + gap; - // connect / unavailable + // connect / searching / incompatible ImGui::SetCursorScreenPos({x - cw, row.min.y + (row_h - bh) * 0.5f}); - ImGui::BeginDisabled(not available); - if (ui::button(c_label, available ? ui::button_style::primary : ui::button_style::secondary, {cw, 0})) + ImGui::BeginDisabled(not reachable); + if (ui::button(c_label, reachable ? ui::button_style::primary : ui::button_style::secondary, {cw, 0})) { connect(data); ImGui::OpenPopup("connecting"); } + if (not c_tooltip.empty() and ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled)) + imgui_ctx->tooltip(c_tooltip); ImGui::EndDisabled(); x -= cw + gap; @@ -485,15 +500,12 @@ void scenes::lobby::gui_server_list() } ImGui::PopStyleVar(); - if (cookie_to_remove != "") - { - config.servers.erase(cookie_to_remove); - config.save(); - } - if (open_add_edit) ImGui::OpenPopup("add or edit server"); + if (open_delete) + ImGui::OpenPopup("delete server"); + // Check if we need to report errors after a disconnect if (next_scene and next_scene->current_state() == scenes::stream::state::shutdown and not ImGui::IsPopupOpen("", ImGuiPopupFlags_AnyPopup)) ImGui::OpenPopup("disconnected"); @@ -530,6 +542,25 @@ void scenes::lobby::gui_server_list() gui_new_server(); wivrn::ui::end_modal(); } + + if (not delete_server_cookie.empty()) + { + std::string name; + if (auto it = config.servers.find(delete_server_cookie); it != config.servers.end()) + name = it->second.service.name; + + switch (wivrn::ui::confirm_modal("delete server", _("Delete server"), fmt::format(_F("Remove \"{}\" from your saved computers?"), name), _("Delete"), _("Cancel"), true)) + { + case 1: + config.servers.erase(delete_server_cookie); + config.save(); + delete_server_cookie = ""; + break; + case -1: + delete_server_cookie = ""; + break; + } + } ImGui::PopStyleVar(3); } @@ -866,46 +897,69 @@ void scenes::lobby::gui_first_run() void scenes::lobby::gui_licenses() { - ImGui::PushFont(nullptr, constants::gui::font_size_large); - ImGui::Text("%s", _("Licenses").c_str()); - ImGui::PopFont(); + namespace ui = wivrn::ui; + const auto & t = ui::current(); - const auto components = {"WiVRn", "FontAwesome", "openxr-loader", "simdjson"}; - if (not license) + ui::page_header(_S("Licenses"), _S("Open-source components bundled with WiVRn.")); + + // Components shipping a license file, probed once + static const std::vector components = [] { + std::vector v; + for (const char * c: {"WiVRn", "FontAwesome", "openxr-loader", "simdjson"}) + { + try + { + utils::mapped_file probe(std::filesystem::path("assets://licenses") / c); + v.emplace_back(c); + } + catch (...) + { + spdlog::debug("No license file for {}", c); + } + } + return v; + }(); + + if (components.empty()) + return; + + if (selected_item.empty()) + selected_item = components.front(); + + int selected = 0; + for (size_t i = 0; i < components.size(); ++i) + if (components[i] == selected_item) + selected = int(i); + + std::vector items; + for (const auto & c: components) + items.push_back({c.c_str()}); + + const float control_w = 480; + if (ui::combo("##component", _("Component"), items, &selected, control_w) or not license) { - selected_item = *components.begin(); + selected_item = components[selected]; try { license = std::make_unique(std::filesystem::path("assets://licenses") / selected_item); } catch (...) { + license.reset(); spdlog::warn("No license file for {}", selected_item); } } - if (ImGui::BeginCombo("##component", selected_item.c_str())) - { - for (const auto & component: components) - { - try - { - auto current = std::make_unique(std::filesystem::path("assets://licenses") / component); - if (ImGui::Selectable(component, component == selected_item, ImGuiSelectableFlags_SelectOnRelease)) - { - selected_item = component; - license = std::move(current); - } - } - catch (...) - { - spdlog::debug("No license file for {}", component); - } - } - ImGui::EndCombo(); - } - imgui_ctx->vibrate_on_hover(); + if (license) + { + ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, {12, 10}); + ui::begin_card("##license_text"); + ImGui::PushStyleColor(ImGuiCol_Text, t.text_muted); ImGui::TextUnformatted((const char *)license->data(), (const char *)license->data() + license->size()); + ImGui::PopStyleColor(); + ui::end_card(); + ImGui::PopStyleVar(); + } } void scenes::lobby::gui_keyboard() @@ -989,6 +1043,15 @@ std::vector> scenes::lobby::draw_gui(XrTi ImGuiStyle & style = ImGui::GetStyle(); style.FontScaleMain = wivrn::ui::current().font_scale * wivrn::ui::metrics::font_base; + // rounding follows the theme so every window/popup gets rounded corners + // (theme::apply() is never called; the widgets theme colours themselves but nothing sets rounding) + style.WindowRounding = wivrn::ui::current().card_rounding; + style.ChildRounding = wivrn::ui::current().card_rounding; + style.PopupRounding = wivrn::ui::current().card_rounding; + style.FrameRounding = wivrn::ui::current().rounding; + style.GrabRounding = wivrn::ui::current().rounding; + style.TabRounding = wivrn::ui::current().rounding; + // base text colour follows the theme so plain ImGui text is legible on light themes style.Colors[ImGuiCol_Text] = wivrn::ui::current().text; style.Colors[ImGuiCol_TextDisabled] = wivrn::ui::current().text_muted; @@ -996,7 +1059,7 @@ std::vector> scenes::lobby::draw_gui(XrTi // combo modals open centred on the popup layer const auto & ui_popup_layer = imgui_ctx->layers()[1]; const glm::vec2 ui_popup_center = ui_popup_layer.vp_origin + ui_popup_layer.vp_size / 2; - wivrn::ui::set_popup_center({ui_popup_center.x, ui_popup_center.y}); + wivrn::ui::set_popup_center({ui_popup_center.x, ui_popup_center.y}, float(ui_popup_layer.vp_size.y)); // let the themed widgets fire the hover haptic and show tooltips wivrn::ui::set_hover_haptic([this] { imgui_ctx->vibrate_on_hover(); }); @@ -1048,21 +1111,23 @@ std::vector> scenes::lobby::draw_gui(XrTi auto & config = application::get_config(); const float TopBarH = 72; - // Top bar: logo on the left, status controls on the right + // Top bar: logo on the left, status controls on the right. + // Transparent child bg so the alpha-blended window background shows through. ImGui::SetCursorPos({0, 0}); - ImGui::PushStyleColor(ImGuiCol_ChildBg, wivrn::ui::current().background); + ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4{0, 0, 0, 0}); ImGui::BeginChild("TopBar", {ImGui::GetWindowSize().x, TopBarH}, 0, ImGuiWindowFlags_NoScrollbar); { const float side = ImGui::GetFrameHeight() * wivrn::ui::metrics::control_height; const float gap = 8; - // logo + // logo: WiVRn mascot followed by the wordmark + const float logo_size = 44; + ImGui::SetCursorPos({24, (TopBarH - logo_size) * 0.5f}); + if (about_picture) + ImGui::Image(about_picture, {logo_size, logo_size}); + ImGui::SameLine(0, 12); ImGui::PushFont(nullptr, ImGui::GetStyle().FontSizeBase * 1.3f); - ImGui::SetCursorPos({24, (TopBarH - ImGui::GetFontSize()) * 0.5f}); - ImGui::PushStyleColor(ImGuiCol_Text, wivrn::ui::current().accent); - ImGui::TextUnformatted(ICON_FA_EYE); - ImGui::PopStyleColor(); - ImGui::SameLine(0, 10); + ImGui::SetCursorPosY((TopBarH - ImGui::GetFontSize()) * 0.5f); ImGui::TextUnformatted("WiVRn"); ImGui::PopFont(); @@ -1070,7 +1135,8 @@ std::vector> scenes::lobby::draw_gui(XrTi const std::string conn = _("Not connected"); const ImVec2 cts = ImGui::CalcTextSize(conn.c_str()); const float dot_r = cts.y * 0.26f; - const float chip_w = cts.x + wivrn::ui::metrics::chip_padding.x * 2.5f + dot_r * 2; + // pill: pad_x on each side + dot + 0.55 pad_x gap before the text (see ui::chip) + const float chip_w = cts.x + wivrn::ui::metrics::chip_pill_padding_x * 2.55f + dot_r * 2; // feature toggles available on this headset (mic + passthrough are always shown) const bool has_hand = system.hand_tracking_supported(); @@ -1116,7 +1182,7 @@ std::vector> scenes::lobby::draw_gui(XrTi if (*battery.charge < 0.2) battery_style = wivrn::ui::chip_style::danger; } - const float battery_w = battery_label.empty() ? 0 : gap + ImGui::CalcTextSize(battery_label.c_str()).x + wivrn::ui::metrics::chip_padding.x * 2; + const float battery_w = battery_label.empty() ? 0 : gap + ImGui::CalcTextSize(battery_label.c_str()).x + wivrn::ui::metrics::chip_pill_padding_x * 2; #else const float battery_w = 0; #endif @@ -1230,11 +1296,11 @@ std::vector> scenes::lobby::draw_gui(XrTi gui_customize(predicted_display_time); break; -#if WIVRN_CLIENT_DEBUG_MENU - case tab::components: - gui_components(); + case tab::theme: + gui_theme(); break; +#if WIVRN_CLIENT_DEBUG_MENU case tab::debug: gui_debug(); break; @@ -1265,7 +1331,9 @@ std::vector> scenes::lobby::draw_gui(XrTi ImGui::EndChild(); ImGui::PopStyleVar(2); // ImGuiStyleVar_FrameRounding, ImGuiStyleVar_WindowPadding - ImGui::PushStyleColor(ImGuiCol_ChildBg, wivrn::ui::current().card); + // Sidebar shares the same transparent background as the rest of the window; + // the sections are separated by hairline dividers drawn below. + ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4{0, 0, 0, 0}); ImGui::SetCursorPos({0, TopBarH}); { ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, {16, 16}); @@ -1293,11 +1361,11 @@ std::vector> scenes::lobby::draw_gui(XrTi current_tab = tab::system; wivrn::ui::nav_section(_S("PERSONALIZE")); - if (wivrn::ui::nav_item(ICON_FA_IMAGE, _S("Customize"), current_tab == tab::customize)) + if (wivrn::ui::nav_item(ICON_FA_IMAGE, _S("Environment"), current_tab == tab::customize)) current_tab = tab::customize; + if (wivrn::ui::nav_item(ICON_FA_PALETTE, _S("Theme"), current_tab == tab::theme)) + current_tab = tab::theme; #if WIVRN_CLIENT_DEBUG_MENU - if (wivrn::ui::nav_item(ICON_FA_PALETTE, "Components", current_tab == tab::components)) - current_tab = tab::components; if (wivrn::ui::nav_item(ICON_FA_BUG_SLASH, _S("Debug"), current_tab == tab::debug)) current_tab = tab::debug; #endif @@ -1317,6 +1385,15 @@ std::vector> scenes::lobby::draw_gui(XrTi ImGui::PopStyleVar(); // ImGuiStyleVar_WindowPadding (Tabs) } ImGui::PopStyleColor(); // ImGuiCol_ChildBg + + // hairline dividers separating the top bar, sidebar and main panel + const ImU32 divider = ImGui::GetColorU32(wivrn::ui::current().border); + const ImVec2 win_pos = ImGui::GetWindowPos(); + const ImVec2 win_size = ImGui::GetWindowSize(); + ImDrawList * dl = ImGui::GetWindowDrawList(); + dl->AddLine({win_pos.x, win_pos.y + TopBarH}, {win_pos.x + win_size.x, win_pos.y + TopBarH}, divider); + dl->AddLine({win_pos.x + TabWidth, win_pos.y + TopBarH}, {win_pos.x + TabWidth, win_pos.y + win_size.y}, divider); + ImGui::End(); ImGui::PopStyleVar(); // ImGuiStyleVar_WindowPadding } diff --git a/client/scenes/lobby_gui_components.cpp b/client/scenes/lobby_gui_components.cpp deleted file mode 100644 index ddb7e2fb..00000000 --- a/client/scenes/lobby_gui_components.cpp +++ /dev/null @@ -1,363 +0,0 @@ -/* - * WiVRn VR streaming - * Copyright (C) 2026 Guillaume Meunier - * Copyright (C) 2026 Patrick Nicolas - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#define IMGUI_DEFINE_MATH_OPERATORS - -#include "lobby.h" - -#if WIVRN_CLIENT_DEBUG_MENU - -#include "render/ui_theme.h" -#include "render/ui_widgets.h" - -#include "imgui.h" - -#include "IconsFontAwesome6.h" - -namespace ui = wivrn::ui; - -// Card title shown above the rows -static void card_title(const char * title) -{ - ImGui::PushStyleColor(ImGuiCol_Text, ui::current().text_muted); - ImGui::TextUnformatted(title); - ImGui::PopStyleColor(); - ImGui::Dummy({0, 4}); -} - -void scenes::lobby::gui_components() -{ - ui::theme & theme = ui::current(); - - ui::page_header("Components", "Live preview of the WiVRn UI kit"); - - ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, {12, 10}); - const float control_w = 480; - - // Theme - ui::begin_card("##theme"); - { - card_title("THEME"); - - // Accent - ImGui::TextUnformatted("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); - ImGui::SameLine(); - } - ImGui::NewLine(); - - ui::row_separator(); - - // Preset - static int preset = 1; // dark_default - const auto preset_list = ui::presets(); - std::vector preset_items; - for (const auto & p: preset_list) - preset_items.push_back({p.name.c_str()}); - - static const int preset_default = 1; - ui::setting_label("Preset", "Surface and background palette", control_w); - if (ui::combo("##preset", "Theme preset", preset_items, &preset, control_w, &preset_default)) - { - 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; - } - - ui::row_separator(); - - // Rounding - static const int rounding_default = 8; - int rounding = int(theme.rounding); - ui::setting_label("Rounding", "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); - - ui::row_separator(); - - static const int card_rounding_default = 14; - int card_rounding = int(theme.card_rounding); - ui::setting_label("Card rounding", "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); - - ui::row_separator(); - - // Text size, applied globally via style.FontScaleMain next frame. 100% is the - // design default; the value is a user multiplier on metrics::font_base. - static const int font_scale_default = 100; - int font_scale = int(theme.font_scale * 100); - ui::setting_label("Text size", "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; - - ui::row_separator(); - - // Panel transparency - static const int opacity_default = 88; - int opacity = int(theme.background_alpha * 100); - ui::setting_label("Panel opacity", "Opacity of the main panel background", control_w); - if (ui::slider_int("##opacity", &opacity, 20, 100, "%d%%", {control_w, 0}, &opacity_default)) - theme.background_alpha = float(opacity) / 100.f; - - ui::end_card(); - } - - // Buttons - ui::begin_card("##buttons"); - { - card_title("BUTTONS"); - - ui::button("Primary", ui::button_style::primary); - ImGui::SameLine(); - ui::button("Secondary", ui::button_style::secondary); - ImGui::SameLine(); - ui::button(ICON_FA_POWER_OFF " Disconnect", ui::button_style::danger); - ImGui::SameLine(); - ui::button("Ghost", ui::button_style::ghost); - - ui::row_separator(); - - card_title("ICON BUTTONS"); - static bool mic = true; - if (ui::icon_button(ICON_FA_MICROPHONE, {}, mic, mic ? "Mute microphone" : "Unmute microphone")) - mic = not mic; - ImGui::SameLine(); - ui::icon_button(ICON_FA_EYE_SLASH, {}, false, "Toggle passthrough"); - ImGui::SameLine(); - ui::icon_button(ICON_FA_HAND, {}, false, "Hand tracking"); - ImGui::SameLine(); - ui::icon_button(ICON_FA_ARROW_ROTATE_LEFT, {}, false, "Recenter"); - - ui::end_card(); - } - - // Toggles - ui::begin_card("##toggles"); - { - card_title("TOGGLES"); - - // room for the toggle plus a trailing reset slot - const float toggle_w = ImGui::GetFrameHeight() * ui::metrics::control_height * ui::metrics::toggle_aspect; - const float toggle_row_w = toggle_w + ImGui::GetFrameHeight() * ui::metrics::control_height + ImGui::GetStyle().ItemSpacing.x; - - static const bool spacewarp_default = false; - static bool spacewarp = true; - ui::setting_label("Application SpaceWarp", "Synthesises in-between frames so motion stays smooth", toggle_row_w); - ui::toggle("##spacewarp", &spacewarp, &spacewarp_default); - - ui::row_separator(); - - static const bool high_power_default = true; - static bool high_power = true; - ui::setting_label("High power mode", "Higher sustained clocks for steadier frames", toggle_row_w); - ui::toggle("##high_power", &high_power, &high_power_default); - - ui::end_card(); - } - - // Sliders - ui::begin_card("##sliders"); - { - card_title("SLIDERS"); - - static const int resolution_default = 100; - static int resolution = 145; - ui::setting_label("Render resolution", "Pixels rendered per eye", control_w); - ui::slider_int("##resolution", &resolution, 50, 350, "%d%%", {control_w, 0}, &resolution_default); - - ui::row_separator(); - - static const int bitrate_default = 100; - static int bitrate = 165; - ui::setting_label("Bitrate", "Video data rate", control_w); - ui::slider_int("##bitrate", &bitrate, 10, 500, "%d Mbit/s", {control_w, 0}, &bitrate_default); - - ui::end_card(); - } - - // Segmented control - ui::begin_card("##segmented"); - { - card_title("SEGMENTED CONTROL"); - - static const int refresh_default = 0; - static int refresh = 2; - static const std::vector rates = {"Auto", "72", "80", "90", "120"}; - ui::setting_label("Refresh rate", "Frames per second shown in the headset", control_w); - ui::segmented("##refresh", rates, &refresh, {control_w, 0}, &refresh_default); - - ui::end_card(); - } - - // Combo - ui::begin_card("##combo"); - { - card_title("COMBO"); - - static const std::vector codecs = { - {"Automatic", "Picks the best codec your PC supports"}, - {"H.264", "Lowest latency, widest support"}, - {"HEVC (H.265)", "Better quality per bit"}, - {"AV1", "Best efficiency, newest GPUs only"}, - }; - static const int codec_default = 0; - static int selected = 2; - - ui::setting_label("Video codec", "How video is compressed and sent to the headset", control_w); - ui::combo("##codec", "Video codec", codecs, &selected, control_w, &codec_default); - - ui::end_card(); - } - - // Navigation (sidebar styling) - ui::begin_card("##nav"); - { - card_title("NAVIGATION"); - - static int nav = 2; - int row = 0; - - if (ui::nav_item(ICON_FA_COMPUTER, "Computers", nav == row)) - nav = row; - ++row; - - ui::nav_section("SETTINGS"); - for (const auto & [icon, label]: { - std::pair{ICON_FA_GAUGE_HIGH, "Performance"}, - std::pair{ICON_FA_TOWER_BROADCAST, "Streaming"}, - std::pair{ICON_FA_CROP, "Field of view"}, - std::pair{ICON_FA_VOLUME_HIGH, "Audio"}, - std::pair{ICON_FA_LOCATION_CROSSHAIRS, "Tracking"}, - std::pair{ICON_FA_GEARS, "System"}, - }) - { - if (ui::nav_item(icon, label, nav == row)) - nav = row; - ++row; - } - - ui::nav_section("PERSONALIZE"); - if (ui::nav_item(ICON_FA_IMAGE, "Customize", nav == row)) - nav = row; - ++row; - - ui::end_card(); - } - - // Chips - ui::begin_card("##chips"); - { - card_title("CHIPS"); - - ui::chip(ICON_FA_BOLT " Auto", ui::chip_style::accent); - ImGui::SameLine(); - ui::chip(ICON_FA_BATTERY_HALF " 38%", ui::chip_style::success); - ImGui::SameLine(); - ui::chip("Connected", ui::chip_style::success, true); - ImGui::SameLine(); - ui::chip("Not connected", ui::chip_style::muted, true); - ImGui::SameLine(); - ui::chip("Unavailable", ui::chip_style::muted); - ImGui::SameLine(); - ui::chip("Beta", ui::chip_style::warning); - - ui::end_card(); - } - - // Text & number inputs - ui::begin_card("##inputs"); - { - card_title("INPUTS"); - - static std::string name, address; - static int port = 9757; - - ui::setting_label("Name", "Friendly label for the server", control_w); - ui::input_text("##name", name, "My gaming PC", control_w); - - ui::row_separator(); - - ui::setting_label("Address", "Hostname or IP of the PC", control_w); - ui::input_text("##address", address, "192.168.1.10 or host.local", control_w); - - ui::row_separator(); - - ui::setting_label("Port", "TCP/UDP port the server listens on", control_w); - ui::input_int("##port", &port, 1, 1, 65535, control_w); - - ui::end_card(); - } - - // Dialog - ui::begin_card("##dialog"); - { - card_title("DIALOG"); - - if (ui::button("Add server")) - ImGui::OpenPopup("##add_server_demo"); - - static std::string d_name, d_address; - static int d_port = 9757; - if (ui::begin_modal("##add_server_demo", "Add server", 620)) - { - const float w = ImGui::GetContentRegionAvail().x; - ImGui::TextUnformatted("Name"); - ui::input_text("##d_name", d_name, "My gaming PC", w); - ImGui::Dummy({0, 4}); - ImGui::TextUnformatted("Address"); - ui::input_text("##d_address", d_address, "192.168.1.10 or host.local", w); - ImGui::Dummy({0, 4}); - ImGui::TextUnformatted("Port"); - ui::input_int("##d_port", &d_port, 1, 1, 65535, w); - - ImGui::Dummy({0, 12}); - - // right-aligned footer - const float gap = ImGui::GetStyle().ItemSpacing.x; - const float cancel_w = ImGui::CalcTextSize("Cancel").x + ui::metrics::button_padding.x * 2; - const float save_w = ImGui::CalcTextSize("Save").x + ui::metrics::button_padding.x * 2; - ImGui::SetCursorPosX(ImGui::GetCursorPosX() + ImGui::GetContentRegionAvail().x - cancel_w - save_w - gap); - - if (ui::button("Cancel", ui::button_style::secondary)) - ImGui::CloseCurrentPopup(); - ImGui::SameLine(); - if (ui::button("Save", ui::button_style::primary)) - ImGui::CloseCurrentPopup(); - - ui::end_modal(); - } - - ui::end_card(); - } - - ImGui::PopStyleVar(); // ImGuiStyleVar_ItemSpacing -} - -#endif // WIVRN_CLIENT_DEBUG_MENU diff --git a/client/scenes/lobby_gui_customize.cpp b/client/scenes/lobby_gui_customize.cpp index a42935c8..a5441c5b 100644 --- a/client/scenes/lobby_gui_customize.cpp +++ b/client/scenes/lobby_gui_customize.cpp @@ -651,7 +651,7 @@ void scenes::lobby::gui_customize(XrTime predicted_display_time) namespace ui = wivrn::ui; - ui::page_header(_S("Customize"), _S("Choose the environment your panels float in.")); + ui::page_header(_S("Environment"), _S("Choose the environment your panels float in.")); ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, {12, 10}); diff --git a/client/scenes/lobby_gui_theme.cpp b/client/scenes/lobby_gui_theme.cpp new file mode 100644 index 00000000..2cfcf12f --- /dev/null +++ b/client/scenes/lobby_gui_theme.cpp @@ -0,0 +1,122 @@ +/* + * WiVRn VR streaming + * Copyright (C) 2026 Guillaume Meunier + * Copyright (C) 2026 Patrick Nicolas + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#define IMGUI_DEFINE_MATH_OPERATORS + +#include "lobby.h" + +#include "render/ui_theme.h" +#include "render/ui_widgets.h" +#include "utils/i18n.h" + +#include "imgui.h" + +#include +#include + +namespace ui = wivrn::ui; + +void scenes::lobby::gui_theme() +{ + ui::theme & theme = ui::current(); + + ui::page_header(_S("Theme"), _S("Accent color, palette and sizing of the interface.")); + + ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, {12, 10}); + const float control_w = 480; + + ui::begin_card("##theme"); + { + // Accent + ImGui::TextUnformatted(_S("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); + ImGui::SameLine(); + } + ImGui::NewLine(); + + ui::row_separator(); + + // Preset + static int preset = 1; // dark_default + const auto preset_list = ui::presets(); + std::vector preset_items; + for (const auto & p: preset_list) + preset_items.push_back({p.name.c_str()}); + + static const int preset_default = 1; + ui::setting_label(_S("Preset"), _S("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; + } + + ui::row_separator(); + + // Rounding + static const int rounding_default = 8; + int rounding = int(theme.rounding); + ui::setting_label(_S("Rounding"), _S("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); + + ui::row_separator(); + + static const int card_rounding_default = 14; + int card_rounding = int(theme.card_rounding); + ui::setting_label(_S("Card rounding"), _S("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); + + ui::row_separator(); + + // Text size, applied globally via style.FontScaleMain next frame. 100% is the + // design default; the value is a user multiplier on metrics::font_base. + static const int font_scale_default = 100; + int font_scale = int(theme.font_scale * 100); + ui::setting_label(_S("Text size"), _S("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; + + ui::row_separator(); + + // Panel transparency + static const int opacity_default = 100; + int opacity = int(theme.background_alpha * 100); + ui::setting_label(_S("Panel opacity"), _S("Opacity of the main panel background"), control_w); + if (ui::slider_int("##opacity", &opacity, 20, 100, "%d%%", {control_w, 0}, &opacity_default)) + theme.background_alpha = float(opacity) / 100.f; + + ui::end_card(); + } + + ImGui::PopStyleVar(); // ImGuiStyleVar_ItemSpacing +}