Code cleanup

This commit is contained in:
ahsanswr
2026-07-26 17:24:36 +02:00
committed by Guillaume Meunier
parent 5e359fe983
commit 80ee73128d
18 changed files with 159 additions and 207 deletions
+3 -6
View File
@@ -39,9 +39,8 @@ static const float max_default_rate = 100;
namespace
{
// Plain scalar settings whose JSON load/save is purely mechanical (key <-> member).
// Settings needing validation, optionals, enums, nested objects or maps are handled
// explicitly in the constructor and save() below.
// scalar settings with a mechanical key <-> member mapping
// everything else is handled explicitly in the constructor and save() below
using config_member = std::variant<
bool configuration::*,
float configuration::*,
@@ -239,11 +238,10 @@ configuration::configuration(xr::system & system, xr::session & session)
servers.emplace(data.service.txt["cookie"], data);
}
// plain scalar settings
for (const auto & f: scalar_fields())
load_field(root, *this, f);
// settings that need more than a mechanical key <-> member mapping
// settings with non-mechanical encoding
if (auto val = root["preferred_refresh_rate"]; val.is_double())
{
float f = val.get_double();
@@ -362,7 +360,6 @@ void configuration::save()
json << "{\"servers\":[" << servers_str << "]";
// plain scalar settings
for (const auto & f: scalar_fields())
save_field(json, *this, f);
+1 -1
View File
@@ -82,7 +82,7 @@ public:
bool app_list_view = false;
uint32_t app_icon_size = 0;
// Interface theme; defaults match the built-in "Dark" preset / "Blue" accent
// interface theme, defaults match the built-in "Dark" preset and "Blue" accent
std::string theme_preset = "Dark";
std::string theme_accent = "Blue";
float theme_rounding = 8;
+2 -2
View File
@@ -65,10 +65,10 @@ constexpr float pointer_fading_distance = 40;
constexpr uint32_t pointer_color = 0x40ffffff;
constexpr uint32_t pointer_color_border = 0xff000000;
// Offset of a popup composition layer in front of its main GUI panel, so combos/modals pop out
// offset of a popup layer in front of its main GUI panel
constexpr glm::vec3 popup_position = {0, 0, 0.05};
// Color scale/bias applied to the main GUI panel while a modal popup is shown, so it dims behind the popup
// scale/bias dimming the main GUI panel behind a popup
constexpr XrColor4f popup_dimming_scale = {0.5, 0.5, 0.5, 1};
constexpr XrColor4f popup_dimming_bias = {0.25, 0.25, 0.25, 0};
} // namespace constants::gui
+4 -6
View File
@@ -1278,7 +1278,7 @@ void imgui_context::tooltip(std::string_view text, std::optional<ImVec2> anchor)
assert(std::ranges::contains(layers_, true, &viewport::tooltip_viewport));
auto & tooltip_layer = *std::ranges::find(layers_, true, &viewport::tooltip_viewport);
// Anchor above the given display point, or above the last item's rect (top center)
// anchor above the given display point, or above the last item's rect (top center)
ImVec2 item_position = anchor.value_or(ImVec2{
(ImGui::GetItemRectMin().x + ImGui::GetItemRectMax().x) / 2,
ImGui::GetItemRectMin().y,
@@ -1289,7 +1289,7 @@ void imgui_context::tooltip(std::string_view text, std::optional<ImVec2> anchor)
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, styled to match the active theme
// Draw the tooltip in the tooltip layer, themed
// 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);
@@ -1343,15 +1343,13 @@ void ScrollWhenDragging()
static int active_id;
static ImVec2 cumulated_delta;
// Don't start a drag while a popup is open or just closed: in VR the ray snaps back
// and can synthesise a click that would scroll right after picking a combo value.
// don't drag while a popup is open or just closed: the ray snaps back and synthesises a click
static bool popup_was_open;
const bool popup_open = ImGui::IsPopupOpen(nullptr, ImGuiPopupFlags_AnyPopupId | ImGuiPopupFlags_AnyPopupLevel);
bool HoveredIdAllowOverlap_backup = std::exchange(g.HoveredIdAllowOverlap, true);
bool ActiveIdAllowOverlap_backup = std::exchange(g.ActiveIdAllowOverlap, true);
// Start only over this window or a child panel with no active widget. ChildWindows
// lets it work over cards; the ActiveId guard keeps controls from scrolling the page.
// start only over this window or a child card, and only with no active widget
const bool over = ImGui::IsWindowHovered(ImGuiHoveredFlags_ChildWindows);
if (active_id == 0 and g.ActiveId == 0 and not popup_open and not popup_was_open and over and ImGui::IsMouseClicked(mouse_button, ImGuiInputFlags_None, /*id*/ ImGuiKeyOwner_Any))
{
+2 -4
View File
@@ -226,8 +226,7 @@ public:
return layers_;
}
// Place a satellite layer (popup, keyboard, …) relative to a base layer: same
// orientation as the base (optionally post-rotated), offset in the base's local frame.
// place a satellite layer at base orientation (optionally post-rotated), offset in the base's local frame
void place_layer_relative(size_t layer, size_t base, glm::vec3 offset, glm::quat extra_rotation = glm::quat(1, 0, 0, 0));
std::vector<window_viewport> windows();
@@ -255,8 +254,7 @@ public:
void vibrate_on_hover();
void set_hovered_item();
void set_controllers_enabled(bool value);
// anchor, if set, positions the tooltip above that display point (e.g. the mouse)
// instead of above the last item's rect
// anchor, if set, positions the tooltip above that display point instead of above the last item's rect
void tooltip(std::string_view text, std::optional<ImVec2> anchor = std::nullopt);
std::array<bool, 2> is_aim_interaction() const
{
+1 -1
View File
@@ -56,7 +56,7 @@ 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.font_scale = 1.0; // user multiplier, 100% maps to metrics::font_base
return t;
}
+12 -16
View File
@@ -62,8 +62,7 @@ struct theme
float font_scale; // global text size multiplier
// Convert to packed color, applying the current global alpha so widgets drawn
// through the draw list dim with ImGui::BeginDisabled() (and any pushed alpha).
// packed color with the current global alpha applied, so draw-list widgets dim with BeginDisabled()
ImU32 col(const ImVec4 & c) const
{
ImVec4 v = c;
@@ -71,23 +70,22 @@ struct theme
return ImGui::ColorConvertFloat4ToU32(v);
}
// Push colors and metrics into the global ImGui style
// push colors and metrics into the global ImGui style
void apply() const;
};
// Fixed design tokens shared by the widgets
// fixed design tokens shared by the widgets
namespace metrics
{
constexpr float font_base = 0.765; // design default text scale, i.e. what the user-facing 100% maps to
constexpr float font_base = 0.765; // user-facing 100% text scale
constexpr float font_title = 1.7; // page header, x base font size
constexpr float font_description = 0.82; // muted secondary text, x base font size
constexpr ImVec2 button_padding = {26, 14};
constexpr ImVec2 card_padding = {28, 22}; // regular cards (settings, etc.)
constexpr ImVec2 list_card_padding = {18, 18}; // cards holding a list of rows (server list)
constexpr ImVec2 card_padding = {28, 22}; // regular cards
constexpr ImVec2 list_card_padding = {18, 18}; // cards holding a list of rows
// Shared height of every full-width control (slider, segmented, combo, input)
// so they line up in a setting row, in multiples of ImGui::GetFrameHeight()
// shared height of every full-width control so they line up in a setting row, x frame height
constexpr float control_height = 1.65;
constexpr float toggle_aspect = 1.9; // track width / height
@@ -109,7 +107,7 @@ constexpr float list_row_box = 52; // leading icon/thumbnail size in a li
constexpr float list_row_box_large = 80; // min thumbnail size for full-height list rows
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 chip_pill_padding_x = 18; // roomier horizontal padding for top-bar pill chips
constexpr float input_padding_x = 14; // horizontal text padding inside inputs
constexpr float font_modal_title = 1.2; // modal heading, x base font size
@@ -120,13 +118,12 @@ constexpr float nav_section_gap = 18; // space above a sidebar section header
constexpr ImVec2 card_item_spacing = {12, 10}; // ItemSpacing pushed around a card section
constexpr float setting_control_width = 480; // width of the control in a setting row
// Application shell (top bar + navigation sidebar + content panel), shared by the lobby
// and the in-stream window
// application shell: top bar, sidebar, content panel, shared by lobby and in-stream window
constexpr float sidebar_width = 300;
constexpr float top_bar_height = 72;
constexpr float content_margin = 20; // gap around the main content panel
// Application launcher grid
// application launcher grid
constexpr float app_icon_small = 120;
constexpr float app_icon_medium = 176;
constexpr float app_icon_large = 240;
@@ -137,12 +134,11 @@ constexpr float app_spinner_radius = 110; // app-starting spinner
constexpr float app_spinner_thickness = 22;
} // namespace metrics
// Theme in effect, call current().apply() after mutating
// theme in effect, call current().apply() after mutating
theme & current();
void set_theme(const theme & t);
// Opacity of the panel and card backgrounds, 0..1. Kept separate from the theme
// presets so switching palette never resets the user's transparency.
// panel and card background opacity, 0..1, kept out of the presets so switching palette keeps it
float & background_alpha();
std::vector<theme> presets();
+52 -43
View File
@@ -34,6 +34,9 @@
#include <unordered_map>
#include <vector>
// drag-to-scroll helper, defined in imgui_impl.cpp
void ScrollWhenDragging();
namespace wivrn::ui
{
@@ -41,6 +44,9 @@ namespace
{
std::function<void()> hover_haptic_hook;
std::function<void(const char *)> tooltip_hook;
// height reserved for the pinned sidebar footer, set by begin_sidebar
float sidebar_footer_height = 0;
} // namespace
void set_hover_haptic(std::function<void()> hook)
@@ -53,15 +59,14 @@ void set_tooltip_hook(std::function<void(const char *)> hook)
tooltip_hook = std::move(hook);
}
// Fire the hover haptic for the last submitted item, if a hook is installed.
// The hook itself checks whether that item is actually hovered.
// fire the hover haptic for the last submitted item, hook checks if it is hovered
static void hover_haptic()
{
if (hover_haptic_hook)
hover_haptic_hook();
}
// Show a tooltip for the last item; caller ensures it is hovered
// show a tooltip for the last item, caller ensures it is hovered
static void show_tooltip(const std::string & text)
{
if (not text.empty() and tooltip_hook)
@@ -85,8 +90,8 @@ void page_header(const std::string & title, const std::string & subtitle)
ImGui::Dummy({0, ImGui::GetStyle().ItemSpacing.y});
}
// A card is a visual rounded panel, not a child window, so the page stays one scroll
// surface. Drawn behind the content using last frame's height; pair with end_card.
// a rounded panel, not a child window, so the page stays one scroll surface, drawn behind
// the content using last frame's height, pair with end_card
namespace
{
struct card_frame
@@ -194,7 +199,7 @@ float setting_label(const std::string & title, const std::string & description,
{
ImGui::PushFont(nullptr, style.FontSizeBase * metrics::font_description);
ImGui::PushStyleColor(ImGuiCol_Text, t.text_muted);
// never wider than half the row; wrap to as many lines as needed so it shows in full
// never wider than half the row, wrap to as many lines as needed
const float desc_w = ImMin(text_w, avail * 0.5f);
ImGui::PushTextWrapPos(start.x + desc_w);
ImGui::TextUnformatted(description.c_str());
@@ -343,7 +348,7 @@ bool button(const char * icon, const std::string & label, button_style s, const
ImGui::PushFont(nullptr, glyph_size);
unsigned int codepoint = 0;
ImTextCharFromUtf8(&codepoint, icon, nullptr);
const ImFontGlyph * glyph = ImGui::GetFontBaked()->FindGlyph((ImWchar)codepoint);
const ImFontGlyph * glyph = ImGui::GetFontBaked()->FindGlyph(ImWchar(codepoint));
if (glyph)
draw->AddText({x, center.y - (glyph->Y0 + glyph->Y1) * 0.5f}, col, icon);
else
@@ -392,7 +397,7 @@ bool icon_button(const char * icon, const ImVec2 & size_arg, bool active, const
ImDrawList * draw = window->DrawList;
draw->AddRectFilled(bb.Min, bb.Max, t.col(bg), t.rounding);
// centre the glyph on its ink box, not CalcTextSize (which includes bearing/leading)
// centre the glyph on its ink box, not CalcTextSize
const float glyph_size = size.y * metrics::icon_button_glyph;
ImGui::PushFont(nullptr, glyph_size);
const ImU32 col = t.col(active ? t.on_accent : t.text);
@@ -400,7 +405,7 @@ bool icon_button(const char * icon, const ImVec2 & size_arg, bool active, const
unsigned int codepoint = 0;
ImTextCharFromUtf8(&codepoint, icon, nullptr);
const ImFontGlyph * glyph = ImGui::GetFontBaked()->FindGlyph((ImWchar)codepoint);
const ImFontGlyph * glyph = ImGui::GetFontBaked()->FindGlyph(ImWchar(codepoint));
if (glyph)
draw->AddText({center.x - (glyph->X0 + glyph->X1) * 0.5f, center.y - (glyph->Y0 + glyph->Y1) * 0.5f}, col, icon);
else
@@ -458,7 +463,7 @@ bool cancel_progress_button(const char * id, float fraction, const ImVec2 & size
else
{
// indeterminate: a rotating quarter arc
const float a0 = (float)g.Time * 3.5f;
const float a0 = float(g.Time) * 3.5f;
draw->PathArcTo(center, radius, a0, a0 + IM_PI * 0.5f, 24);
draw->PathStroke(accent, ImDrawFlags_None, thickness);
}
@@ -469,7 +474,7 @@ bool cancel_progress_button(const char * id, float fraction, const ImVec2 & size
const ImU32 col = t.col(hovered or held ? t.text : t.text_muted);
unsigned int codepoint = 0;
ImTextCharFromUtf8(&codepoint, ICON_FA_STOP, nullptr);
const ImFontGlyph * glyph = ImGui::GetFontBaked()->FindGlyph((ImWchar)codepoint);
const ImFontGlyph * glyph = ImGui::GetFontBaked()->FindGlyph(ImWchar(codepoint));
if (glyph)
draw->AddText({center.x - (glyph->X0 + glyph->X1) * 0.5f, center.y - (glyph->Y0 + glyph->Y1) * 0.5f}, col, ICON_FA_STOP);
ImGui::PopFont();
@@ -483,8 +488,7 @@ float reset_slot_width()
return ImGui::GetFrameHeight() * metrics::control_height + ImGui::GetStyle().ItemSpacing.x;
}
// Trailing reset button on a value control's row; empty slot when show is false so the
// right edge stays put. Returns true when tapped.
// trailing reset button on a value control's row, empty slot when not shown so the right edge stays put
static bool reset_slot(const char * id, bool show)
{
const float side = ImGui::GetFrameHeight() * metrics::control_height;
@@ -509,7 +513,7 @@ bool toggle(const char * id, bool * v, const bool * default_value)
const theme & t = current();
const ImGuiStyle & style = ImGui::GetStyle();
// match the height of the other controls (sliders, combo, ...)
// match the height of the other controls
const float height = ImGui::GetFrameHeight() * metrics::control_height;
const float width = height * metrics::toggle_aspect;
const float radius = height * 0.5f;
@@ -591,7 +595,7 @@ bool slider_int(const char * id, int * v, int v_min, int v_max, const char * for
draw->AddRectFilled(bb.Min, bb.Max, t.col(t.control), t.rounding);
if (fraction > 0)
{
// round the right corners too once the fill reaches the box edge, else they stay sharp over the rounded background
// round the right corners too once the fill reaches the box edge
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);
}
@@ -686,13 +690,12 @@ bool segmented(const char * id, const std::vector<std::string> & options, int *
namespace
{
// Where combo modals open, in imgui display coords. Set each frame by the lobby.
// 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.
// 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 and an optional muted description.
// one selectable option inside the combo modal, tall full-width touch target with an optional description
bool combo_row(const combo_item & item, bool selected)
{
ImGuiWindow * window = ImGui::GetCurrentWindow();
@@ -829,11 +832,9 @@ bool combo(const char * id, const std::string & title, const std::vector<combo_i
ImGui::Dummy({0, style.ItemSpacing.y});
}
// cap the list height so a long list scrolls inside the modal rather than
// overflowing the popup layer, which would clip the top and bottom rows
// cap the list height so a long list scrolls inside the modal instead of clipping
const float row_h = ImGui::GetFrameHeight() * metrics::combo_row_height;
// rows are separated by ItemSpacing.y, so the real content is taller than the
// row heights alone; include the gaps or a scrollbar shows even when it all fits
// include the inter-row gaps or a scrollbar shows even when it all fits
float list_h = int(items.size()) * row_h + ImMax(0, int(items.size()) - 1) * style.ItemSpacing.y;
if (popup_available_height > 0)
{
@@ -859,7 +860,7 @@ bool combo(const char * id, const std::string & title, const std::vector<combo_i
ImGui::EndChild();
ImGui::PopStyleVar();
// click outside dismisses; AllowWhenBlockedByActiveItem so pressing a row still counts as inside
// 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))
ImGui::CloseCurrentPopup();
@@ -916,7 +917,7 @@ 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
// tall pill chips (height override) 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;
@@ -982,16 +983,14 @@ bool nav_item(const char * icon, const std::string & label, bool selected)
const float lum = t.background.x * 0.299f + t.background.y * 0.587f + t.background.z * 0.114f;
if (selected)
{
// Pure accent fill for the active tab.
// accent fill for the active tab
draw->AddRectFilled(bb.Min, bb.Max, t.col(t.accent), t.rounding);
}
else if (hovered)
{
// Subtle lighten on dark themes, darken on light ones. The framebuffer
// blends in linear light, so a fixed alpha would look far stronger on a
// dark surface than a light one. Solve for the alpha that yields a constant
// *perceived* (gamma-space) step instead.
const float step = lum < 0.5f ? 0.10f : 0.06f; // perceptual lightness delta; stronger on dark
// lighten on dark themes, darken on light ones, the framebuffer blends in linear
// light, so solve for the alpha that yields a constant perceived (gamma-space) step
const float step = lum < 0.5f ? 0.10f : 0.06f; // perceptual lightness delta, stronger on dark
auto to_linear = [](float c) { return c <= 0.04045f ? c / 12.92f : std::pow((c + 0.055f) / 1.055f, 2.4f); };
const float overlay = lum < 0.5f ? 1.f : 0.f; // lighten vs darken
const float ys = to_linear(lum);
@@ -1023,8 +1022,7 @@ static int input_text_resize(ImGuiInputTextCallbackData * data)
return 0;
}
// Common frame styling for the input widgets, control height. Returns the count of
// style colors / vars pushed so the caller can pop them.
// common frame styling for the input widgets, paired with pop_input_style
static void push_input_style(float height)
{
const theme & t = current();
@@ -1194,8 +1192,7 @@ list_row_result begin_list_row(const char * id, const char * icon, ImTextureID i
const ImVec2 p0 = window->DC.CursorPos;
const float avail = ImGui::GetContentRegionAvail().x;
// non-interactive rows (the body does nothing, only trailing controls act) just reserve
// layout space -- no click area and no hover highlight on the row itself
// non-interactive rows just reserve layout space, no click area and no hover highlight
bool clicked = false;
if (interactive)
{
@@ -1211,12 +1208,11 @@ list_row_result begin_list_row(const char * id, const char * icon, ImTextureID i
ImDrawList * draw = window->DrawList;
const ImRect bb(p0, p0 + ImVec2(avail, row_h));
// No tinted background for the selected row -- callers indicate the active item with a
// chip instead. Still show the hover highlight.
// no tinted background for the selected row, callers mark the active item with a chip
if (hovered)
draw->AddRectFilled(bb.Min, bb.Max, t.col(t.control), t.card_rounding);
// leading thumbnail or icon box; large_thumb spans the full row height
// leading thumbnail or icon box, large_thumb spans the full row height
const float thumb = large_thumb ? row_h - 2 * pad : box;
const ImVec2 box_min = {p0.x + pad, p0.y + (row_h - thumb) * 0.5f};
const ImVec2 box_max = box_min + ImVec2(thumb, thumb);
@@ -1322,7 +1318,7 @@ int action_menu(const char * id, const char * icon, const std::vector<action_ite
ImGui::PopID();
}
// click outside dismisses; AllowWhenBlockedByActiveItem so pressing a row still counts as inside
// 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))
ImGui::CloseCurrentPopup();
@@ -1376,20 +1372,33 @@ void top_bar(float height, ImTextureID logo, const std::vector<top_bar_item> & r
ImGui::PopStyleColor();
}
void begin_sidebar(float top_bar_h, float tab_width)
void begin_sidebar(float top_bar_h, float tab_width, int footer_items)
{
// shares the transparent window background; sections separated by shell_dividers
// shares the transparent window background, sections separated by shell_dividers
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4{0, 0, 0, 0});
ImGui::SetCursorPos({0, top_bar_h});
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, {16, 16});
ImGui::BeginChild("Tabs", {tab_width, ImGui::GetWindowSize().y - top_bar_h}, ImGuiChildFlags_AlwaysUseWindowPadding);
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, {0, 4});
// nav list scrolls in a child that fills the rest, footer stays pinned in footer_items rows
const float row_h = ImGui::GetFrameHeight() * metrics::control_height + ImGui::GetStyle().ItemSpacing.y;
sidebar_footer_height = footer_items > 0 ? footer_items * row_h : 0;
ImGui::BeginChild("TabsScroll", {0, ImGui::GetContentRegionAvail().y - sidebar_footer_height});
}
void sidebar_footer()
{
::ScrollWhenDragging(); // drag to scroll the nav list, like the rest of the GUI
ImGui::EndChild(); // TabsScroll
// pin the footer to the bottom of the sidebar
ImGui::SetCursorPosY(ImGui::GetContentRegionMax().y - sidebar_footer_height);
}
void end_sidebar()
{
ImGui::PopStyleVar(); // ImGuiStyleVar_ItemSpacing
ImGui::EndChild();
ImGui::PopStyleVar(); // ImGuiStyleVar_ItemSpacing
ImGui::EndChild(); // Tabs
ImGui::PopStyleVar(); // ImGuiStyleVar_WindowPadding
ImGui::PopStyleColor(); // ImGuiCol_ChildBg
}
+43 -57
View File
@@ -24,8 +24,8 @@
#include <string>
#include <vector>
// Themed, reusable UI widgets. Colors and metrics come from wivrn::ui::current().
// Display text is taken by const std::string &; ids and icon glyphs stay const char *.
// Themed, reusable UI widgets, colors and metrics from wivrn::ui::current()
// Display text takes const std::string &, ids and icon glyphs stay const char *
namespace wivrn::ui
{
@@ -42,49 +42,44 @@ void page_header(const std::string & title, const std::string & subtitle = {});
// Rounded panel, pair with end_card
bool begin_card(const char * id, const ImVec2 & size = {0, 0});
// Same, but with tighter padding for cards that hold a list of rows
// Tighter padding, for cards holding a list of rows
bool begin_list_card(const char * id);
void end_card();
// Full-width divider between rows of a card
void row_separator();
// Title and wrapped muted description on the left, control_width reserved on the right.
// Returns the window-local y of the label bottom, so the caller can keep the row tall
// enough for a multi-line label.
// Title and wrapped muted description on the left, control_width reserved on the right
// Returns the window-local y of the label bottom, to keep the row tall enough for a multi-line label
float setting_label(const std::string & title, const std::string & description, float control_width);
// "<icon> <label>" with the standard two-space gap, for chips and text buttons that
// take a single label string with an embedded glyph.
// "<icon> <label>" with the standard two-space gap
std::string icon_label(const char * icon, const std::string & label);
// Auto-fit width of a button, matching what button() lays out when size.x is left at 0.
// Use to reserve/right-align a button before drawing it. The icon overload accounts for
// the leading glyph drawn at metrics::button_label_glyph.
// Auto-fit width of a button, as laid out when size.x is 0
float button_width(const std::string & label);
float button_width(const char * icon, const std::string & label);
// Footprint of a chip() with standard padding (no dot, no height override).
// Footprint of a chip() with standard padding, no dot, no height override
ImVec2 chip_size(const std::string & label);
// Exact layout width of a chip(), accounting for the optional status dot and the roomier
// padding used when height > 0 (the tall pill chips in the top bar).
// Exact layout width of a chip(), accounting for the optional dot and the height override padding
float chip_width(const std::string & label, bool dot = false, float height = 0);
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
// Same, with a larger leading icon glyph
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 = {});
// Circular download-progress indicator with a cancel (stop) glyph in the centre.
// fraction in [0,1] draws a determinate ring; < 0 draws an indeterminate spinner.
// Returns true when clicked (i.e. cancel requested). Sized like icon_button by default.
// Circular download-progress indicator with a centred cancel glyph
// fraction in [0,1] draws a determinate ring, < 0 an indeterminate spinner
// Returns true when cancel is clicked
bool cancel_progress_button(const char * id, float fraction, const ImVec2 & size = {0, 0}, const std::string & tooltip = {});
bool toggle(const char * id, bool * v, const bool * default_value = nullptr);
// Width a trailing reset slot consumes (gap + square), for laying out toggles
// Width a trailing reset slot consumes, gap + square
float reset_slot_width();
// The value controls below draw a reset button when the value differs from default_value
@@ -99,19 +94,17 @@ struct combo_item
const char * description = nullptr;
};
// Combo box whose options open in a modal list on the popup layer. *selected is the
// chosen index, title labels the modal. Returns true when the selection changes.
// Combo box whose options open in a modal list, *selected is the chosen index, title labels the modal
bool combo(const char * id, const std::string & title, const std::vector<combo_item> & items, int * selected, float width = 0, const int * default_value = nullptr);
// 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.
// Centre (display coords) where combo and begin_modal popups open, plus the popup-layer height
// 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.
// hover-haptic hook, fired after an interactive item
void set_hover_haptic(std::function<void()> hook);
// Hook to show a tooltip for the last item. Install once.
// tooltip hook for the last item
void set_tooltip_hook(std::function<void(const char *)> hook);
enum class chip_style
@@ -123,24 +116,24 @@ enum class chip_style
warning,
danger,
};
// Status badge. label may include a leading icon glyph; dot draws a status dot.
// height overrides the pill height (default sizes to the text + padding)
// Status badge, label may include a leading icon glyph, dot draws a status dot
// height overrides the pill height, default sizes to text + padding
void chip(const std::string & label, chip_style style = chip_style::neutral, bool dot = false, float height = 0);
// Muted sidebar group header
void nav_section(const std::string & label);
// Sidebar entry: icon + label, highlighted when selected. Returns true when clicked
// sidebar entry: icon + label, highlighted when selected, returns true when clicked
bool nav_item(const char * icon, const std::string & label, bool selected);
// Single-line text field at control height; hint is optional placeholder text
// Single-line text field at control height, hint is optional placeholder text
bool input_text(const char * id, std::string & text, const char * hint = nullptr, float width = 0);
// Number field with - / + stepper buttons. Returns true when the value changes
// number field with -/+ steppers, returns true on change
bool input_int(const char * id, int * v, int step = 1, int v_min = 0, int v_max = 0, float width = 0);
// Centred modal on the popup layer. Open with ImGui::OpenPopup(id), dismiss with
// ImGui::CloseCurrentPopup(); pair with end_modal only when this returns true.
// Centred modal on the popup layer, open with ImGui::OpenPopup(id), dismiss with ImGui::CloseCurrentPopup()
// Pair with end_modal only when this returns true
bool begin_modal(const char * id, const std::string & title, float width = 0);
void end_modal();
@@ -152,7 +145,7 @@ struct action_item
bool checked = false;
};
// Overflow button: an icon button opening a popup of actions. Returns the picked index, or -1
// overflow icon button opening a popup of actions, returns the picked index or -1
int action_menu(const char * id, const char * icon, const std::vector<action_item> & items);
struct list_row_result
@@ -160,51 +153,44 @@ struct list_row_result
ImVec2 min, max; // row rect (screen) for right-aligning trailing controls
bool clicked; // the row body was clicked
// Screen position for a trailing control of the given size, right-aligned to right_x
// and vertically centred in the row. Feed to ImGui::SetCursorScreenPos.
// Screen position for a size trailing control, right-aligned to right_x and vertically centred
ImVec2 trailing(float right_x, const ImVec2 & size) const
{
return {right_x - size.x, min.y + (max.y - min.y - size.y) * 0.5f};
}
};
// List row: leading thumbnail (image, if non-zero) or icon box, title and muted subtitle.
// trailing_width reserves space on the right for trailing controls and excludes it from
// the row's click area. Place controls right-aligned at .max with SetCursorScreenPos,
// then call end_list_row().
// large_thumb makes the leading thumbnail/icon box span the full row height (icon boxes
// keep their background at that same size).
// interactive=false reserves layout only -- no row-body click area and no hover highlight,
// for rows whose body does nothing (only trailing controls act).
// List row: leading thumbnail (image, if non-zero) or icon box, title and muted subtitle
// trailing_width reserves right-side space for trailing controls, excluded from the click area
// large_thumb spans the leading thumbnail/icon box across the full row height
// interactive=false reserves layout only, no row-body click area or hover highlight
list_row_result begin_list_row(const char * id, const char * icon, ImTextureID image, const std::string & title, const std::string & subtitle, bool selected = false, float trailing_width = 0, float height = 0, bool large_thumb = false, bool interactive = true);
void end_list_row();
// Confirmation dialog (open with ImGui::OpenPopup(id)). Returns 1 if confirmed, -1 if
// cancelled or dismissed, 0 otherwise. danger styles the confirm button as destructive.
// confirmation dialog, open with ImGui::OpenPopup(id), returns 1 confirmed / -1 cancelled / 0 otherwise
// danger styles the confirm button as destructive
int confirm_modal(const char * id, const std::string & title, const std::string & message, const std::string & confirm_label, const std::string & cancel_label, bool danger = false);
// --- Shared window shell: top bar, sidebar and dividers used by the lobby and the
// in-stream GUI so the two screens stay identical. Call inside the main window.
// shared window shell: top bar, sidebar and dividers, called inside the main window
// One slot in the top bar's right-aligned cluster. width is the slot's layout width
// (use chip_width() for chips, the control side for icon buttons); draw() renders it at
// the cursor, vertically centred, at the standard control height.
// One slot in the top bar's right-aligned cluster, width is the slot's layout width
// draw() renders it at the cursor, vertically centred, at the standard control height
struct top_bar_item
{
float width;
std::function<void()> draw;
};
// Top bar: WiVRn logo + wordmark on the left, right_items right-aligned. Manages its own
// child window; height is the bar height in pixels.
// Top bar: WiVRn logo + wordmark on the left, right_items right-aligned, height in pixels
void top_bar(float height, ImTextureID logo, const std::vector<top_bar_item> & right_items);
// Sidebar nav frame at the standard width/offset. Fill with nav_section()/nav_item()
// between the calls; pair begin_sidebar with end_sidebar.
void begin_sidebar(float top_bar_h, float tab_width);
// sidebar nav frame: scrolling top section, footer_items rows pinned at the bottom
// always pair: begin_sidebar -> sidebar_footer -> end_sidebar
void begin_sidebar(float top_bar_h, float tab_width, int footer_items = 0);
void sidebar_footer();
void end_sidebar();
// Hairline dividers separating the top bar, sidebar and content, dimmed with the panel.
// Hairline dividers separating the top bar, sidebar and content, dimmed with the panel
void shell_dividers(float top_bar_h, float tab_width);
} // namespace wivrn::ui
+4 -7
View File
@@ -42,7 +42,7 @@ namespace ui = wivrn::ui;
namespace
{
// target grid icon size for the small/medium/large setting; tiles stretch from this to fill the row
// target grid icon size per small/medium/large setting, tiles stretch from this to fill the row
float grid_image_size(uint32_t size)
{
switch (size)
@@ -174,8 +174,7 @@ app_launcher::clicked app_launcher::draw_gui(imgui_context & imgui_ctx, const st
const float size_w = ui::metrics::app_size_toggle_width;
const float disconnect_w = ui::button_width(cancel);
// title row stays fixed: view/size toggles then disconnect, right-aligned and
// top-aligned with the title. Disconnect stays enabled even while an app starts.
// title row stays fixed: view/size toggles then disconnect, right-aligned, disconnect stays enabled while an app starts
const float right = ImGui::GetContentRegionMax().x;
ImGui::SetCursorPos({right - disconnect_w, header_top});
if (ui::button(cancel, ui::button_style::danger))
@@ -214,7 +213,7 @@ app_launcher::clicked app_launcher::draw_gui(imgui_context & imgui_ctx, const st
}
else
{
// only the grid/list scrolls; flush to the header edge with no extra inset
// only the grid/list scrolls, flush to the header edge with no extra inset
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, {0, 0});
ImGui::BeginChild("applist", {0, 0});
@@ -231,9 +230,7 @@ app_launcher::clicked app_launcher::draw_gui(imgui_context & imgui_ctx, const st
}
else
{
// justified grid: as many columns as fit at the chosen icon size, then stretch
// every tile to divide the row exactly so there is no trailing gap; rows use the
// same gap as columns
// justified grid: as many columns as fit, tiles stretched to divide the row exactly so there is no trailing gap
const float tile_margin = ui::metrics::app_tile_margin;
const float target = grid_image_size(config.app_icon_size) + tile_margin * 2;
const float avail = ImGui::GetContentRegionAvail().x;
+2 -3
View File
@@ -58,15 +58,14 @@ bool post_processing(
float toggle_width();
// Battery pill shown in the top bar: the icon+percent label and the threshold colour.
// top-bar battery pill: icon+percent label and threshold colour
struct battery_indicator
{
std::string label;
wivrn::ui::chip_style style;
};
// Current headset battery as a top-bar pill, or nullopt when unavailable (always nullopt
// off Android). now drives the charging animation. Shared by the lobby and in-stream GUI.
// headset battery as a top-bar pill, nullopt when unavailable, now drives the charging animation
std::optional<battery_indicator> battery_status_indicator(XrTime now);
} // namespace gui
+5 -13
View File
@@ -17,14 +17,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
// The settings screens are drawn procedurally: each page builds a list of `setting`
// descriptors that reference the existing configuration members, and render_settings()
// renders the matching ui:: widget for each. Gating is done by conditionally adding a
// descriptor; the disabled-but-shown case uses the `enabled` predicate. Descriptors are
// rebuilt every frame, so dynamic options and descriptions just work.
//
// The same pages serve the lobby and the in-stream window, where in_game disables the
// connection-time settings and shows the in-stream controls.
// each page builds a list of `setting` descriptors, render_settings() draws the matching
// ui:: widget for each, rebuilt every frame so dynamic options/descriptions just work
// same pages serve the lobby and the in-stream window, gated by ctx.in_game
#include "scenes/gui_common.h"
#define IMGUI_DEFINE_MATH_OPERATORS
@@ -76,9 +71,7 @@ enum class ui_kind
button,
};
// One declarative setting. Numeric controls (slider/segmented/combo) use get_int/set_int;
// segmented/combo indices map through `options`. Strings are owned so localized text stays
// valid. `enabled` greys the row out without hiding it.
// one declarative setting, `enabled` greys the row out without hiding it
struct setting
{
const char * id; // stable imgui id
@@ -168,8 +161,7 @@ void render_settings(const wivrn::gui::settings_context & ctx, const char * card
ImGui::EndDisabled();
// keep the row tall enough for a multi-line description and add breathing room
// below. Reserve with Dummy (SetCursorPos would not grow the content size).
// reserve row height for a multi-line description plus padding, Dummy grows content size
const float pad = std::max(label_bottom - ImGui::GetCursorPosY(), 0.f) + ui::metrics::label_bottom_pad;
ImGui::Dummy({0, pad});
+13 -23
View File
@@ -120,7 +120,7 @@ void scenes::lobby::gui_connecting(locked_notifiable<pin_request_data> & pin_req
if (async_error)
close_button_label = _("Close");
// keep a sensible minimum width as the status text changes between stages
// minimum width as the status text changes between stages
ImGui::Dummy({420, 0});
ImGui::PushFont(nullptr, style.FontSizeBase * ui::metrics::font_modal_title);
@@ -390,8 +390,7 @@ void scenes::lobby::gui_server_list()
for (auto && [cookie, data]: config.servers)
sorted_cookies.emplace(data.service.name, cookie);
// 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
// open below at this scope so OpenPopup and begin_modal hash to the same id
bool open_add_edit = false;
bool open_delete = false;
@@ -414,19 +413,15 @@ void scenes::lobby::gui_server_list()
ui::row_separator();
first = false;
// 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)
// reachable: manual or discovered with matching protocol
// incompatible: discovered but protocol version differs, otherwise still searching
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
// trailing controls [Auto chip] [Connect] [menu], measured up front to exclude from the row click area
const char * c_icon = reachable ? ICON_FA_PLAY : (incompatible ? ICON_FA_TRIANGLE_EXCLAMATION : ICON_FA_MAGNIFYING_GLASS);
const std::string c_label = ui::icon_label(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"));
@@ -477,8 +472,7 @@ void scenes::lobby::gui_server_list()
if (ui::button(c_label, reachable ? ui::button_style::primary : ui::button_style::secondary, {cw, 0}))
{
connect(data);
// connecting popup is opened at window scope below (NOT here:
// inside begin_card PushID the id would not match BeginPopupModal -> orphaned popup)
// popup opened at window scope below, outside begin_card's PushID so the id matches BeginPopupModal
}
if (not c_tooltip.empty() and ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled))
imgui_ctx->tooltip(c_tooltip);
@@ -1035,7 +1029,6 @@ std::vector<std::pair<int, XrCompositionLayerQuad>> scenes::lobby::draw_gui(XrTi
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;
@@ -1043,7 +1036,7 @@ std::vector<std::pair<int, XrCompositionLayerQuad>> scenes::lobby::draw_gui(XrTi
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
// base text colour follows the theme so plain ImGui text stays legible
style.Colors[ImGuiCol_Text] = wivrn::ui::current().text;
style.Colors[ImGuiCol_TextDisabled] = wivrn::ui::current().text_muted;
@@ -1101,11 +1094,11 @@ std::vector<std::pair<int, XrCompositionLayerQuad>> scenes::lobby::draw_gui(XrTi
auto & config = application::get_config();
const float TopBarH = wivrn::ui::metrics::top_bar_height;
// Top bar: logo left; feature toggles, battery and connection status right.
// Top bar: logo left, feature toggles / battery / connection status right
const float side = ImGui::GetFrameHeight() * wivrn::ui::metrics::control_height;
std::vector<wivrn::ui::top_bar_item> top_items;
// feature toggle slot: reads its state and toggles on click (mic + passthrough always shown)
// feature toggle slot: reads its state, toggles on click
auto toggle_item = [&](const char * icon, const std::string & label, feature f) {
top_items.push_back({side, [icon, label, f] {
const float s = ImGui::GetFrameHeight() * wivrn::ui::metrics::control_height;
@@ -1146,8 +1139,7 @@ std::vector<std::pair<int, XrCompositionLayerQuad>> scenes::lobby::draw_gui(XrTi
wivrn::ui::top_bar(TopBarH, about_picture, top_items);
// content area: content_margin from the sidebar on the left; the panel runs all the way
// to the window's right edge so the scrollbar sits at the edge (no margin beside it).
// content area: content_margin from the sidebar, panel runs to the window's right edge so the scrollbar sits at the edge
const float content_margin = wivrn::ui::metrics::content_margin;
ImGui::SetCursorPos({TabWidth + content_margin, TopBarH});
@@ -1155,8 +1147,7 @@ std::vector<std::pair<int, XrCompositionLayerQuad>> scenes::lobby::draw_gui(XrTi
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, {content_margin, 20});
ImGui::BeginChild("Main", ImVec2(ImGui::GetWindowSize().x - ImGui::GetCursorPosX(), 0), 0);
// The scrollbar is wide (30px); WindowPadding alone leaves the content cramped against it.
// Pull the work area in on the right so the content keeps a clear gap from the scrollbar.
// pull the work area in on the right to keep a gap from the wide scrollbar
{
ImGuiWindow * main_child = ImGui::GetCurrentWindow();
main_child->WorkRect.Max.x -= content_margin;
@@ -1241,7 +1232,7 @@ std::vector<std::pair<int, XrCompositionLayerQuad>> scenes::lobby::draw_gui(XrTi
ImGui::EndChild();
ImGui::PopStyleVar(2); // ImGuiStyleVar_FrameRounding, ImGuiStyleVar_WindowPadding
wivrn::ui::begin_sidebar(TopBarH, TabWidth);
wivrn::ui::begin_sidebar(TopBarH, TabWidth, 3);
{
if (wivrn::ui::nav_item(ICON_FA_COMPUTER, _S("Computers"), current_tab == tab::server_list))
current_tab = tab::server_list;
@@ -1273,8 +1264,7 @@ std::vector<std::pair<int, XrCompositionLayerQuad>> scenes::lobby::draw_gui(XrTi
#endif
// pinned to the bottom
const float item_h = ImGui::GetFrameHeight() * wivrn::ui::metrics::control_height + ImGui::GetStyle().ItemSpacing.y;
ImGui::SetCursorPosY(ImGui::GetContentRegionMax().y - 3 * item_h - ImGui::GetStyle().WindowPadding.y);
wivrn::ui::sidebar_footer();
if (wivrn::ui::nav_item(ICON_FA_CIRCLE_INFO, _S("About"), current_tab == tab::about))
current_tab = tab::about;
if (wivrn::ui::nav_item(ICON_FA_SCALE_BALANCED, _S("Licenses"), current_tab == tab::licenses))
+2 -3
View File
@@ -456,7 +456,7 @@ scenes::lobby::environment_item_action scenes::lobby::environment_item(environme
action = environment_item_action::delete_model;
}
// surface download errors the way the original did
// surface download errors
if (handle)
{
if (handle->get_state() == libcurl::state::error)
@@ -674,8 +674,7 @@ void scenes::lobby::gui_customize(XrTime predicted_display_time)
ui::end_card();
}
// OpenPopup must run at the same ID-stack level as BeginPopupModal below;
// begin_card pushes an ID, so defer the call until after end_card.
// deferred past end_card so OpenPopup hashes at the same id-stack level as BeginPopupModal
if (open_download_popup)
ImGui::OpenPopup("download environment model");
+2 -3
View File
@@ -38,7 +38,7 @@ void scenes::lobby::apply_theme_settings()
{
auto & config = application::get_config();
// preset by name; surfaces only, the accent is applied separately below
// preset by name, surfaces only, accent applied separately below
for (const auto & p: ui::presets())
{
if (p.name == config.theme_preset)
@@ -152,8 +152,7 @@ void scenes::lobby::gui_theme()
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.
// 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(_S("Text size"), _S("Global font scale"), control_w);
+1 -3
View File
@@ -523,9 +523,7 @@ void scenes::stream::on_focused()
.tooltip_viewport = true,
},
{
// Pop up window: combos and modals float just in front of the main panel.
// Position and orientation track the main panel each frame. Same pixel
// density as the main panel (1500 px/m) so text matches.
// popup window for combos and modals, tracks the main panel each frame at the same pixel density
.space = xr::spaces::world,
.size = {1.2, 0.6666},
.vp_origin = {1800, 0},
+1 -1
View File
@@ -142,7 +142,7 @@ private:
static bool is_interactable(stream_tab);
bool is_gui_interactable() const;
// settings sub-page, client-only: the wire stream_tab stays `settings`
// settings sub-page, client-only: the wire stream_tab stays settings
enum class settings_page
{
performance,
+9 -15
View File
@@ -574,7 +574,7 @@ void scenes::stream::gui_applications()
wivrn::ui::row_separator();
first = false;
// overlays and the active app aren't selectable; only their stop button acts
// overlays and the active app aren't selectable, only their stop button acts
const bool interactive = not(app.active or app.overlay);
const float trailing = stop_w + (app.active ? gap + active_sz.x : 0) + wivrn::ui::metrics::list_row_pad;
const auto row = wivrn::ui::begin_list_row("##row", ICON_FA_CUBE, 0, app.name, {}, app.active, trailing, 0, false, interactive);
@@ -748,8 +748,7 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte
}
}
// The popup layer floats just in front of the main panel so combos and modals pop
// out as their own quad, like the lobby (see set_popup_center below).
// popup layer floats in front of the main panel so combos and modals pop as their own quad
imgui_ctx->place_layer_relative(2, 0, constants::gui::popup_position);
const float tab_width = wivrn::ui::metrics::sidebar_width;
@@ -760,8 +759,7 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte
ImGuiStyle & style = ImGui::GetStyle();
imgui_ctx->new_frame(predicted_display_time);
// theme the shared cards like the lobby
// the widget hooks are global, re-point them at this scene's context
// theme the shared cards like the lobby, widget hooks are global so re-point at this scene
style.FontScaleMain = wivrn::ui::current().font_scale * wivrn::ui::metrics::font_base;
style.WindowRounding = wivrn::ui::current().card_rounding;
style.ChildRounding = wivrn::ui::current().card_rounding;
@@ -918,8 +916,7 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte
if (display_tabs)
{
// top bar: logo left; battery, connection status and window controls right
// (close/disconnect have no quick-toggles: those only apply on connection)
// top bar: logo left, battery/connection status/window controls right
const float side = ImGui::GetFrameHeight() * wivrn::ui::metrics::control_height;
std::vector<wivrn::ui::top_bar_item> top_items;
if (auto bat = wivrn::gui::battery_status_indicator(instance.now()))
@@ -934,7 +931,7 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte
if (wivrn::ui::button(ICON_FA_XMARK, close_label, wivrn::ui::button_style::secondary, {0, side}))
next_gui_status = stream_tab::hidden;
}});
// disconnect asks for confirmation; OpenPopup/confirm_modal share the window id stack
// disconnect asks for confirmation, OpenPopup/confirm_modal share the window id stack
bool request_disconnect = false;
const std::string disconnect_label = _S("Disconnect");
top_items.push_back({wivrn::ui::button_width(ICON_FA_DOOR_OPEN, disconnect_label),
@@ -949,8 +946,8 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte
if (wivrn::ui::confirm_modal("confirm disconnect", _("Disconnect"), _("Disconnect from the server and return to the lobby?"), _("Disconnect"), _("Cancel"), true) == 1)
exit();
// navigation sidebar; the settings items swap the page but keep the coarse `settings` tab
wivrn::ui::begin_sidebar(top_bar_h, tab_width);
// navigation sidebar, the settings items swap the page but keep the coarse settings tab
wivrn::ui::begin_sidebar(top_bar_h, tab_width, 2);
{
wivrn::ui::nav_section(_S("STREAM"));
if (wivrn::ui::nav_item(ICON_FA_LIST, _S("Applications"), gui_status == stream_tab::applications))
@@ -984,9 +981,7 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte
settings_item(ICON_FA_GEARS, _S("System"), settings_page::system);
// pinned to the bottom
const float item_h = ImGui::GetFrameHeight() * wivrn::ui::metrics::control_height + ImGui::GetStyle().ItemSpacing.y;
ImGui::SetCursorPosY(ImGui::GetContentRegionMax().y - 2 * item_h - ImGui::GetStyle().WindowPadding.y);
wivrn::ui::sidebar_footer();
if (wivrn::ui::nav_item(ICON_FA_CHART_LINE, _S("Statistics overlay"), false))
next_gui_status = stream_tab::overlay_only;
if (wivrn::ui::nav_item(ICON_FA_MINIMIZE, _S("Compact view"), false))
@@ -1081,8 +1076,7 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte
}
}
// Add the layer with the GUI. While a modal popup is shown, dim the main panel (the
// first layer) behind it like the lobby; the popup quad itself stays bright.
// add the GUI layers, dim the main panel behind a modal popup, popup quad stays bright
bool dim_main = imgui_ctx->is_modal_popup_shown() and composition_layer_color_scale_bias_supported;
for (auto [_, layer]: layers)
{