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
+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