Code cleanup
This commit is contained in:
committed by
Guillaume Meunier
parent
5e359fe983
commit
80ee73128d
@@ -39,9 +39,8 @@ static const float max_default_rate = 100;
|
|||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
// Plain scalar settings whose JSON load/save is purely mechanical (key <-> member).
|
// scalar settings with a mechanical key <-> member mapping
|
||||||
// Settings needing validation, optionals, enums, nested objects or maps are handled
|
// everything else is handled explicitly in the constructor and save() below
|
||||||
// explicitly in the constructor and save() below.
|
|
||||||
using config_member = std::variant<
|
using config_member = std::variant<
|
||||||
bool configuration::*,
|
bool configuration::*,
|
||||||
float configuration::*,
|
float configuration::*,
|
||||||
@@ -239,11 +238,10 @@ configuration::configuration(xr::system & system, xr::session & session)
|
|||||||
servers.emplace(data.service.txt["cookie"], data);
|
servers.emplace(data.service.txt["cookie"], data);
|
||||||
}
|
}
|
||||||
|
|
||||||
// plain scalar settings
|
|
||||||
for (const auto & f: scalar_fields())
|
for (const auto & f: scalar_fields())
|
||||||
load_field(root, *this, f);
|
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())
|
if (auto val = root["preferred_refresh_rate"]; val.is_double())
|
||||||
{
|
{
|
||||||
float f = val.get_double();
|
float f = val.get_double();
|
||||||
@@ -362,7 +360,6 @@ void configuration::save()
|
|||||||
|
|
||||||
json << "{\"servers\":[" << servers_str << "]";
|
json << "{\"servers\":[" << servers_str << "]";
|
||||||
|
|
||||||
// plain scalar settings
|
|
||||||
for (const auto & f: scalar_fields())
|
for (const auto & f: scalar_fields())
|
||||||
save_field(json, *this, f);
|
save_field(json, *this, f);
|
||||||
|
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ public:
|
|||||||
bool app_list_view = false;
|
bool app_list_view = false;
|
||||||
uint32_t app_icon_size = 0;
|
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_preset = "Dark";
|
||||||
std::string theme_accent = "Blue";
|
std::string theme_accent = "Blue";
|
||||||
float theme_rounding = 8;
|
float theme_rounding = 8;
|
||||||
|
|||||||
+2
-2
@@ -65,10 +65,10 @@ constexpr float pointer_fading_distance = 40;
|
|||||||
constexpr uint32_t pointer_color = 0x40ffffff;
|
constexpr uint32_t pointer_color = 0x40ffffff;
|
||||||
constexpr uint32_t pointer_color_border = 0xff000000;
|
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};
|
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_scale = {0.5, 0.5, 0.5, 1};
|
||||||
constexpr XrColor4f popup_dimming_bias = {0.25, 0.25, 0.25, 0};
|
constexpr XrColor4f popup_dimming_bias = {0.25, 0.25, 0.25, 0};
|
||||||
} // namespace constants::gui
|
} // namespace constants::gui
|
||||||
|
|||||||
@@ -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));
|
assert(std::ranges::contains(layers_, true, &viewport::tooltip_viewport));
|
||||||
auto & tooltip_layer = *std::ranges::find(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{
|
ImVec2 item_position = anchor.value_or(ImVec2{
|
||||||
(ImGui::GetItemRectMin().x + ImGui::GetItemRectMax().x) / 2,
|
(ImGui::GetItemRectMin().x + ImGui::GetItemRectMax().x) / 2,
|
||||||
ImGui::GetItemRectMin().y,
|
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->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);
|
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
|
// Clamp position to avoid overflowing on the left or the right
|
||||||
const wivrn::ui::theme & t = wivrn::ui::current();
|
const wivrn::ui::theme & t = wivrn::ui::current();
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, constants::style::tooltip_padding);
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, constants::style::tooltip_padding);
|
||||||
@@ -1343,15 +1343,13 @@ void ScrollWhenDragging()
|
|||||||
static int active_id;
|
static int active_id;
|
||||||
static ImVec2 cumulated_delta;
|
static ImVec2 cumulated_delta;
|
||||||
|
|
||||||
// Don't start a drag while a popup is open or just closed: in VR the ray snaps back
|
// don't drag while a popup is open or just closed: the ray snaps back and synthesises a click
|
||||||
// and can synthesise a click that would scroll right after picking a combo value.
|
|
||||||
static bool popup_was_open;
|
static bool popup_was_open;
|
||||||
const bool popup_open = ImGui::IsPopupOpen(nullptr, ImGuiPopupFlags_AnyPopupId | ImGuiPopupFlags_AnyPopupLevel);
|
const bool popup_open = ImGui::IsPopupOpen(nullptr, ImGuiPopupFlags_AnyPopupId | ImGuiPopupFlags_AnyPopupLevel);
|
||||||
|
|
||||||
bool HoveredIdAllowOverlap_backup = std::exchange(g.HoveredIdAllowOverlap, true);
|
bool HoveredIdAllowOverlap_backup = std::exchange(g.HoveredIdAllowOverlap, true);
|
||||||
bool ActiveIdAllowOverlap_backup = std::exchange(g.ActiveIdAllowOverlap, true);
|
bool ActiveIdAllowOverlap_backup = std::exchange(g.ActiveIdAllowOverlap, true);
|
||||||
// Start only over this window or a child panel with no active widget. ChildWindows
|
// start only over this window or a child card, and only with no active widget
|
||||||
// lets it work over cards; the ActiveId guard keeps controls from scrolling the page.
|
|
||||||
const bool over = ImGui::IsWindowHovered(ImGuiHoveredFlags_ChildWindows);
|
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))
|
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))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -226,8 +226,7 @@ public:
|
|||||||
return layers_;
|
return layers_;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Place a satellite layer (popup, keyboard, …) relative to a base layer: same
|
// place a satellite layer at base orientation (optionally post-rotated), offset in the base's local frame
|
||||||
// orientation as the base (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));
|
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();
|
std::vector<window_viewport> windows();
|
||||||
@@ -255,8 +254,7 @@ public:
|
|||||||
void vibrate_on_hover();
|
void vibrate_on_hover();
|
||||||
void set_hovered_item();
|
void set_hovered_item();
|
||||||
void set_controllers_enabled(bool value);
|
void set_controllers_enabled(bool value);
|
||||||
// anchor, if set, positions the tooltip above that display point (e.g. the mouse)
|
// anchor, if set, positions the tooltip above that display point instead of above the last item's rect
|
||||||
// instead of above the last item's rect
|
|
||||||
void tooltip(std::string_view text, std::optional<ImVec2> anchor = std::nullopt);
|
void tooltip(std::string_view text, std::optional<ImVec2> anchor = std::nullopt);
|
||||||
std::array<bool, 2> is_aim_interaction() const
|
std::array<bool, 2> is_aim_interaction() const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ static theme dark_default()
|
|||||||
t.rounding = 8;
|
t.rounding = 8;
|
||||||
t.card_rounding = 14;
|
t.card_rounding = 14;
|
||||||
t.border_size = 1;
|
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;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+12
-16
@@ -62,8 +62,7 @@ struct theme
|
|||||||
|
|
||||||
float font_scale; // global text size multiplier
|
float font_scale; // global text size multiplier
|
||||||
|
|
||||||
// Convert to packed color, applying the current global alpha so widgets drawn
|
// packed color with the current global alpha applied, so draw-list widgets dim with BeginDisabled()
|
||||||
// through the draw list dim with ImGui::BeginDisabled() (and any pushed alpha).
|
|
||||||
ImU32 col(const ImVec4 & c) const
|
ImU32 col(const ImVec4 & c) const
|
||||||
{
|
{
|
||||||
ImVec4 v = c;
|
ImVec4 v = c;
|
||||||
@@ -71,23 +70,22 @@ struct theme
|
|||||||
return ImGui::ColorConvertFloat4ToU32(v);
|
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;
|
void apply() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Fixed design tokens shared by the widgets
|
// fixed design tokens shared by the widgets
|
||||||
namespace metrics
|
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_title = 1.7; // page header, x base font size
|
||||||
constexpr float font_description = 0.82; // muted secondary text, 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 button_padding = {26, 14};
|
||||||
constexpr ImVec2 card_padding = {28, 22}; // regular cards (settings, etc.)
|
constexpr ImVec2 card_padding = {28, 22}; // regular cards
|
||||||
constexpr ImVec2 list_card_padding = {18, 18}; // cards holding a list of rows (server list)
|
constexpr ImVec2 list_card_padding = {18, 18}; // cards holding a list of rows
|
||||||
|
|
||||||
// Shared height of every full-width control (slider, segmented, combo, input)
|
// shared height of every full-width control so they line up in a setting row, x frame height
|
||||||
// so they line up in a setting row, in multiples of ImGui::GetFrameHeight()
|
|
||||||
constexpr float control_height = 1.65;
|
constexpr float control_height = 1.65;
|
||||||
|
|
||||||
constexpr float toggle_aspect = 1.9; // track width / height
|
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_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 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 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 input_padding_x = 14; // horizontal text padding inside inputs
|
||||||
constexpr float font_modal_title = 1.2; // modal heading, x base font size
|
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 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
|
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
|
// application shell: top bar, sidebar, content panel, shared by lobby and in-stream window
|
||||||
// and the in-stream window
|
|
||||||
constexpr float sidebar_width = 300;
|
constexpr float sidebar_width = 300;
|
||||||
constexpr float top_bar_height = 72;
|
constexpr float top_bar_height = 72;
|
||||||
constexpr float content_margin = 20; // gap around the main content panel
|
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_small = 120;
|
||||||
constexpr float app_icon_medium = 176;
|
constexpr float app_icon_medium = 176;
|
||||||
constexpr float app_icon_large = 240;
|
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;
|
constexpr float app_spinner_thickness = 22;
|
||||||
} // namespace metrics
|
} // namespace metrics
|
||||||
|
|
||||||
// Theme in effect, call current().apply() after mutating
|
// theme in effect, call current().apply() after mutating
|
||||||
theme & current();
|
theme & current();
|
||||||
void set_theme(const theme & t);
|
void set_theme(const theme & t);
|
||||||
|
|
||||||
// Opacity of the panel and card backgrounds, 0..1. Kept separate from the theme
|
// panel and card background opacity, 0..1, kept out of the presets so switching palette keeps it
|
||||||
// presets so switching palette never resets the user's transparency.
|
|
||||||
float & background_alpha();
|
float & background_alpha();
|
||||||
|
|
||||||
std::vector<theme> presets();
|
std::vector<theme> presets();
|
||||||
|
|||||||
@@ -34,6 +34,9 @@
|
|||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
// drag-to-scroll helper, defined in imgui_impl.cpp
|
||||||
|
void ScrollWhenDragging();
|
||||||
|
|
||||||
namespace wivrn::ui
|
namespace wivrn::ui
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -41,6 +44,9 @@ namespace
|
|||||||
{
|
{
|
||||||
std::function<void()> hover_haptic_hook;
|
std::function<void()> hover_haptic_hook;
|
||||||
std::function<void(const char *)> tooltip_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
|
} // namespace
|
||||||
|
|
||||||
void set_hover_haptic(std::function<void()> hook)
|
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);
|
tooltip_hook = std::move(hook);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fire the hover haptic for the last submitted item, if a hook is installed.
|
// fire the hover haptic for the last submitted item, hook checks if it is hovered
|
||||||
// The hook itself checks whether that item is actually hovered.
|
|
||||||
static void hover_haptic()
|
static void hover_haptic()
|
||||||
{
|
{
|
||||||
if (hover_haptic_hook)
|
if (hover_haptic_hook)
|
||||||
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)
|
static void show_tooltip(const std::string & text)
|
||||||
{
|
{
|
||||||
if (not text.empty() and tooltip_hook)
|
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});
|
ImGui::Dummy({0, ImGui::GetStyle().ItemSpacing.y});
|
||||||
}
|
}
|
||||||
|
|
||||||
// A card is a visual rounded panel, not a child window, so the page stays one scroll
|
// a rounded panel, not a child window, so the page stays one scroll surface, drawn behind
|
||||||
// surface. Drawn behind the content using last frame's height; pair with end_card.
|
// the content using last frame's height, pair with end_card
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
struct card_frame
|
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::PushFont(nullptr, style.FontSizeBase * metrics::font_description);
|
||||||
ImGui::PushStyleColor(ImGuiCol_Text, t.text_muted);
|
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);
|
const float desc_w = ImMin(text_w, avail * 0.5f);
|
||||||
ImGui::PushTextWrapPos(start.x + desc_w);
|
ImGui::PushTextWrapPos(start.x + desc_w);
|
||||||
ImGui::TextUnformatted(description.c_str());
|
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);
|
ImGui::PushFont(nullptr, glyph_size);
|
||||||
unsigned int codepoint = 0;
|
unsigned int codepoint = 0;
|
||||||
ImTextCharFromUtf8(&codepoint, icon, nullptr);
|
ImTextCharFromUtf8(&codepoint, icon, nullptr);
|
||||||
const ImFontGlyph * glyph = ImGui::GetFontBaked()->FindGlyph((ImWchar)codepoint);
|
const ImFontGlyph * glyph = ImGui::GetFontBaked()->FindGlyph(ImWchar(codepoint));
|
||||||
if (glyph)
|
if (glyph)
|
||||||
draw->AddText({x, center.y - (glyph->Y0 + glyph->Y1) * 0.5f}, col, icon);
|
draw->AddText({x, center.y - (glyph->Y0 + glyph->Y1) * 0.5f}, col, icon);
|
||||||
else
|
else
|
||||||
@@ -392,7 +397,7 @@ bool icon_button(const char * icon, const ImVec2 & size_arg, bool active, const
|
|||||||
ImDrawList * draw = window->DrawList;
|
ImDrawList * draw = window->DrawList;
|
||||||
draw->AddRectFilled(bb.Min, bb.Max, t.col(bg), t.rounding);
|
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;
|
const float glyph_size = size.y * metrics::icon_button_glyph;
|
||||||
ImGui::PushFont(nullptr, glyph_size);
|
ImGui::PushFont(nullptr, glyph_size);
|
||||||
const ImU32 col = t.col(active ? t.on_accent : t.text);
|
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;
|
unsigned int codepoint = 0;
|
||||||
ImTextCharFromUtf8(&codepoint, icon, nullptr);
|
ImTextCharFromUtf8(&codepoint, icon, nullptr);
|
||||||
const ImFontGlyph * glyph = ImGui::GetFontBaked()->FindGlyph((ImWchar)codepoint);
|
const ImFontGlyph * glyph = ImGui::GetFontBaked()->FindGlyph(ImWchar(codepoint));
|
||||||
if (glyph)
|
if (glyph)
|
||||||
draw->AddText({center.x - (glyph->X0 + glyph->X1) * 0.5f, center.y - (glyph->Y0 + glyph->Y1) * 0.5f}, col, icon);
|
draw->AddText({center.x - (glyph->X0 + glyph->X1) * 0.5f, center.y - (glyph->Y0 + glyph->Y1) * 0.5f}, col, icon);
|
||||||
else
|
else
|
||||||
@@ -458,7 +463,7 @@ bool cancel_progress_button(const char * id, float fraction, const ImVec2 & size
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// indeterminate: a rotating quarter arc
|
// 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->PathArcTo(center, radius, a0, a0 + IM_PI * 0.5f, 24);
|
||||||
draw->PathStroke(accent, ImDrawFlags_None, thickness);
|
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);
|
const ImU32 col = t.col(hovered or held ? t.text : t.text_muted);
|
||||||
unsigned int codepoint = 0;
|
unsigned int codepoint = 0;
|
||||||
ImTextCharFromUtf8(&codepoint, ICON_FA_STOP, nullptr);
|
ImTextCharFromUtf8(&codepoint, ICON_FA_STOP, nullptr);
|
||||||
const ImFontGlyph * glyph = ImGui::GetFontBaked()->FindGlyph((ImWchar)codepoint);
|
const ImFontGlyph * glyph = ImGui::GetFontBaked()->FindGlyph(ImWchar(codepoint));
|
||||||
if (glyph)
|
if (glyph)
|
||||||
draw->AddText({center.x - (glyph->X0 + glyph->X1) * 0.5f, center.y - (glyph->Y0 + glyph->Y1) * 0.5f}, col, ICON_FA_STOP);
|
draw->AddText({center.x - (glyph->X0 + glyph->X1) * 0.5f, center.y - (glyph->Y0 + glyph->Y1) * 0.5f}, col, ICON_FA_STOP);
|
||||||
ImGui::PopFont();
|
ImGui::PopFont();
|
||||||
@@ -483,8 +488,7 @@ float reset_slot_width()
|
|||||||
return ImGui::GetFrameHeight() * metrics::control_height + ImGui::GetStyle().ItemSpacing.x;
|
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
|
// trailing reset button on a value control's row, empty slot when not shown so the right edge stays put
|
||||||
// right edge stays put. Returns true when tapped.
|
|
||||||
static bool reset_slot(const char * id, bool show)
|
static bool reset_slot(const char * id, bool show)
|
||||||
{
|
{
|
||||||
const float side = ImGui::GetFrameHeight() * metrics::control_height;
|
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 theme & t = current();
|
||||||
const ImGuiStyle & style = ImGui::GetStyle();
|
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 height = ImGui::GetFrameHeight() * metrics::control_height;
|
||||||
const float width = height * metrics::toggle_aspect;
|
const float width = height * metrics::toggle_aspect;
|
||||||
const float radius = height * 0.5f;
|
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);
|
draw->AddRectFilled(bb.Min, bb.Max, t.col(t.control), t.rounding);
|
||||||
if (fraction > 0)
|
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;
|
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);
|
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
|
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};
|
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;
|
float popup_available_height = 0;
|
||||||
|
|
||||||
// One selectable option inside the combo modal. A tall, full-width touch target
|
// one selectable option inside the combo modal, tall full-width touch target with an optional description
|
||||||
// with the name and an optional muted description.
|
|
||||||
bool combo_row(const combo_item & item, bool selected)
|
bool combo_row(const combo_item & item, bool selected)
|
||||||
{
|
{
|
||||||
ImGuiWindow * window = ImGui::GetCurrentWindow();
|
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});
|
ImGui::Dummy({0, style.ItemSpacing.y});
|
||||||
}
|
}
|
||||||
|
|
||||||
// cap the list height so a long list scrolls inside the modal rather than
|
// cap the list height so a long list scrolls inside the modal instead of clipping
|
||||||
// overflowing the popup layer, which would clip the top and bottom rows
|
|
||||||
const float row_h = ImGui::GetFrameHeight() * metrics::combo_row_height;
|
const float row_h = ImGui::GetFrameHeight() * metrics::combo_row_height;
|
||||||
// rows are separated by ItemSpacing.y, so the real content is taller than the
|
// include the inter-row gaps or a scrollbar shows even when it all fits
|
||||||
// row heights alone; include the 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;
|
float list_h = int(items.size()) * row_h + ImMax(0, int(items.size()) - 1) * style.ItemSpacing.y;
|
||||||
if (popup_available_height > 0)
|
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::EndChild();
|
||||||
ImGui::PopStyleVar();
|
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))
|
if (ImGui::IsMouseClicked(ImGuiMouseButton_Left) and not ImGui::IsWindowHovered(ImGuiHoveredFlags_RootAndChildWindows | ImGuiHoveredFlags_AllowWhenBlockedByActiveItem))
|
||||||
ImGui::CloseCurrentPopup();
|
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 ts = ImGui::CalcTextSize(label.c_str());
|
||||||
const ImVec2 pad = metrics::chip_padding;
|
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 pad_x = height > 0 ? metrics::chip_pill_padding_x : pad.x;
|
||||||
const float dot_r = ts.y * 0.26f;
|
const float dot_r = ts.y * 0.26f;
|
||||||
const float dot_gap = dot ? dot_r * 2 + pad_x * 0.55f : 0;
|
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;
|
const float lum = t.background.x * 0.299f + t.background.y * 0.587f + t.background.z * 0.114f;
|
||||||
if (selected)
|
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);
|
draw->AddRectFilled(bb.Min, bb.Max, t.col(t.accent), t.rounding);
|
||||||
}
|
}
|
||||||
else if (hovered)
|
else if (hovered)
|
||||||
{
|
{
|
||||||
// Subtle lighten on dark themes, darken on light ones. The framebuffer
|
// lighten on dark themes, darken on light ones, the framebuffer blends in linear
|
||||||
// blends in linear light, so a fixed alpha would look far stronger on a
|
// light, so solve for the alpha that yields a constant perceived (gamma-space) step
|
||||||
// dark surface than a light one. Solve for the alpha that yields a constant
|
const float step = lum < 0.5f ? 0.10f : 0.06f; // perceptual lightness delta, stronger on dark
|
||||||
// *perceived* (gamma-space) step instead.
|
|
||||||
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); };
|
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 overlay = lum < 0.5f ? 1.f : 0.f; // lighten vs darken
|
||||||
const float ys = to_linear(lum);
|
const float ys = to_linear(lum);
|
||||||
@@ -1023,8 +1022,7 @@ static int input_text_resize(ImGuiInputTextCallbackData * data)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Common frame styling for the input widgets, control height. Returns the count of
|
// common frame styling for the input widgets, paired with pop_input_style
|
||||||
// style colors / vars pushed so the caller can pop them.
|
|
||||||
static void push_input_style(float height)
|
static void push_input_style(float height)
|
||||||
{
|
{
|
||||||
const theme & t = current();
|
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 ImVec2 p0 = window->DC.CursorPos;
|
||||||
const float avail = ImGui::GetContentRegionAvail().x;
|
const float avail = ImGui::GetContentRegionAvail().x;
|
||||||
|
|
||||||
// non-interactive rows (the body does nothing, only trailing controls act) just reserve
|
// non-interactive rows just reserve layout space, no click area and no hover highlight
|
||||||
// layout space -- no click area and no hover highlight on the row itself
|
|
||||||
bool clicked = false;
|
bool clicked = false;
|
||||||
if (interactive)
|
if (interactive)
|
||||||
{
|
{
|
||||||
@@ -1211,12 +1208,11 @@ list_row_result begin_list_row(const char * id, const char * icon, ImTextureID i
|
|||||||
|
|
||||||
ImDrawList * draw = window->DrawList;
|
ImDrawList * draw = window->DrawList;
|
||||||
const ImRect bb(p0, p0 + ImVec2(avail, row_h));
|
const ImRect bb(p0, p0 + ImVec2(avail, row_h));
|
||||||
// No tinted background for the selected row -- callers indicate the active item with a
|
// no tinted background for the selected row, callers mark the active item with a chip
|
||||||
// chip instead. Still show the hover highlight.
|
|
||||||
if (hovered)
|
if (hovered)
|
||||||
draw->AddRectFilled(bb.Min, bb.Max, t.col(t.control), t.card_rounding);
|
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 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_min = {p0.x + pad, p0.y + (row_h - thumb) * 0.5f};
|
||||||
const ImVec2 box_max = box_min + ImVec2(thumb, thumb);
|
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();
|
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))
|
if (ImGui::IsMouseClicked(ImGuiMouseButton_Left) and not ImGui::IsWindowHovered(ImGuiHoveredFlags_RootAndChildWindows | ImGuiHoveredFlags_AllowWhenBlockedByActiveItem))
|
||||||
ImGui::CloseCurrentPopup();
|
ImGui::CloseCurrentPopup();
|
||||||
|
|
||||||
@@ -1376,20 +1372,33 @@ void top_bar(float height, ImTextureID logo, const std::vector<top_bar_item> & r
|
|||||||
ImGui::PopStyleColor();
|
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::PushStyleColor(ImGuiCol_ChildBg, ImVec4{0, 0, 0, 0});
|
||||||
ImGui::SetCursorPos({0, top_bar_h});
|
ImGui::SetCursorPos({0, top_bar_h});
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, {16, 16});
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, {16, 16});
|
||||||
ImGui::BeginChild("Tabs", {tab_width, ImGui::GetWindowSize().y - top_bar_h}, ImGuiChildFlags_AlwaysUseWindowPadding);
|
ImGui::BeginChild("Tabs", {tab_width, ImGui::GetWindowSize().y - top_bar_h}, ImGuiChildFlags_AlwaysUseWindowPadding);
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, {0, 4});
|
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()
|
void end_sidebar()
|
||||||
{
|
{
|
||||||
ImGui::PopStyleVar(); // ImGuiStyleVar_ItemSpacing
|
ImGui::PopStyleVar(); // ImGuiStyleVar_ItemSpacing
|
||||||
ImGui::EndChild();
|
ImGui::EndChild(); // Tabs
|
||||||
ImGui::PopStyleVar(); // ImGuiStyleVar_WindowPadding
|
ImGui::PopStyleVar(); // ImGuiStyleVar_WindowPadding
|
||||||
ImGui::PopStyleColor(); // ImGuiCol_ChildBg
|
ImGui::PopStyleColor(); // ImGuiCol_ChildBg
|
||||||
}
|
}
|
||||||
|
|||||||
+43
-57
@@ -24,8 +24,8 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
// Themed, reusable UI widgets. Colors and metrics come from wivrn::ui::current().
|
// Themed, reusable UI widgets, colors and metrics from wivrn::ui::current()
|
||||||
// Display text is taken by const std::string &; ids and icon glyphs stay const char *.
|
// Display text takes const std::string &, ids and icon glyphs stay const char *
|
||||||
namespace wivrn::ui
|
namespace wivrn::ui
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -42,49 +42,44 @@ void page_header(const std::string & title, const std::string & subtitle = {});
|
|||||||
|
|
||||||
// Rounded panel, pair with end_card
|
// Rounded panel, pair with end_card
|
||||||
bool begin_card(const char * id, const ImVec2 & size = {0, 0});
|
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);
|
bool begin_list_card(const char * id);
|
||||||
void end_card();
|
void end_card();
|
||||||
|
|
||||||
// Full-width divider between rows of a card
|
// Full-width divider between rows of a card
|
||||||
void row_separator();
|
void row_separator();
|
||||||
|
|
||||||
// Title and wrapped muted description on the left, control_width reserved on the right.
|
// 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
|
// Returns the window-local y of the label bottom, to keep the row tall enough for a multi-line label
|
||||||
// enough for a multi-line label.
|
|
||||||
float setting_label(const std::string & title, const std::string & description, float control_width);
|
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
|
// "<icon> <label>" with the standard two-space gap
|
||||||
// take a single label string with an embedded glyph.
|
|
||||||
std::string icon_label(const char * icon, const std::string & label);
|
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.
|
// Auto-fit width of a button, as laid out when size.x is 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.
|
|
||||||
float button_width(const std::string & label);
|
float button_width(const std::string & label);
|
||||||
float button_width(const char * icon, 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);
|
ImVec2 chip_size(const std::string & label);
|
||||||
|
|
||||||
// Exact layout width of a chip(), accounting for the optional status dot and the roomier
|
// Exact layout width of a chip(), accounting for the optional dot and the height override padding
|
||||||
// padding used when height > 0 (the tall pill chips in the top bar).
|
|
||||||
float chip_width(const std::string & label, bool dot = false, float height = 0);
|
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});
|
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});
|
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
|
// 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 = {});
|
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.
|
// Circular download-progress indicator with a centred cancel glyph
|
||||||
// fraction in [0,1] draws a determinate ring; < 0 draws an indeterminate spinner.
|
// fraction in [0,1] draws a determinate ring, < 0 an indeterminate spinner
|
||||||
// Returns true when clicked (i.e. cancel requested). Sized like icon_button by default.
|
// 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 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);
|
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();
|
float reset_slot_width();
|
||||||
|
|
||||||
// The value controls below draw a reset button when the value differs from default_value
|
// 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;
|
const char * description = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Combo box whose options open in a modal list on the popup layer. *selected is the
|
// Combo box whose options open in a modal list, *selected is the chosen index, title labels the modal
|
||||||
// chosen index, title labels the modal. Returns true when the selection changes.
|
|
||||||
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);
|
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
|
// Centre (display coords) where combo and begin_modal popups open, plus the popup-layer height
|
||||||
// available on the popup layer so tall combo lists cap and scroll instead of being
|
// available_height of 0 leaves the list unbounded, set once per frame
|
||||||
// clipped. available_height of 0 leaves the list unbounded. Set once per frame.
|
|
||||||
void set_popup_center(const ImVec2 & center, float available_height = 0);
|
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);
|
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);
|
void set_tooltip_hook(std::function<void(const char *)> hook);
|
||||||
|
|
||||||
enum class chip_style
|
enum class chip_style
|
||||||
@@ -123,24 +116,24 @@ enum class chip_style
|
|||||||
warning,
|
warning,
|
||||||
danger,
|
danger,
|
||||||
};
|
};
|
||||||
// Status badge. label may include a leading icon glyph; dot draws a status dot.
|
// 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)
|
// 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);
|
void chip(const std::string & label, chip_style style = chip_style::neutral, bool dot = false, float height = 0);
|
||||||
|
|
||||||
// Muted sidebar group header
|
// Muted sidebar group header
|
||||||
void nav_section(const std::string & label);
|
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);
|
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);
|
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);
|
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
|
// Centred modal on the popup layer, open with ImGui::OpenPopup(id), dismiss with ImGui::CloseCurrentPopup()
|
||||||
// ImGui::CloseCurrentPopup(); pair with end_modal only when this returns true.
|
// Pair with end_modal only when this returns true
|
||||||
bool begin_modal(const char * id, const std::string & title, float width = 0);
|
bool begin_modal(const char * id, const std::string & title, float width = 0);
|
||||||
void end_modal();
|
void end_modal();
|
||||||
|
|
||||||
@@ -152,7 +145,7 @@ struct action_item
|
|||||||
bool checked = false;
|
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);
|
int action_menu(const char * id, const char * icon, const std::vector<action_item> & items);
|
||||||
|
|
||||||
struct list_row_result
|
struct list_row_result
|
||||||
@@ -160,51 +153,44 @@ struct list_row_result
|
|||||||
ImVec2 min, max; // row rect (screen) for right-aligning trailing controls
|
ImVec2 min, max; // row rect (screen) for right-aligning trailing controls
|
||||||
bool clicked; // the row body was clicked
|
bool clicked; // the row body was clicked
|
||||||
|
|
||||||
// Screen position for a trailing control of the given size, right-aligned to right_x
|
// Screen position for a size trailing control, right-aligned to right_x and vertically centred
|
||||||
// and vertically centred in the row. Feed to ImGui::SetCursorScreenPos.
|
|
||||||
ImVec2 trailing(float right_x, const ImVec2 & size) const
|
ImVec2 trailing(float right_x, const ImVec2 & size) const
|
||||||
{
|
{
|
||||||
return {right_x - size.x, min.y + (max.y - min.y - size.y) * 0.5f};
|
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.
|
// 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
|
// trailing_width reserves right-side space for trailing controls, excluded from the click area
|
||||||
// the row's click area. Place controls right-aligned at .max with SetCursorScreenPos,
|
// large_thumb spans the leading thumbnail/icon box across the full row height
|
||||||
// then call end_list_row().
|
// interactive=false reserves layout only, no row-body click area or hover highlight
|
||||||
// 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_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);
|
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();
|
void end_list_row();
|
||||||
|
|
||||||
// Confirmation dialog (open with ImGui::OpenPopup(id)). Returns 1 if confirmed, -1 if
|
// confirmation dialog, open with ImGui::OpenPopup(id), returns 1 confirmed / -1 cancelled / 0 otherwise
|
||||||
// cancelled or dismissed, 0 otherwise. danger styles the confirm button as destructive.
|
// 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);
|
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
|
// shared window shell: top bar, sidebar and dividers, called inside the main window
|
||||||
// in-stream GUI so the two screens stay identical. Call inside the main window.
|
|
||||||
|
|
||||||
// One slot in the top bar's right-aligned cluster. width is the slot's layout width
|
// 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
|
// draw() renders it at the cursor, vertically centred, at the standard control height
|
||||||
// the cursor, vertically centred, at the standard control height.
|
|
||||||
struct top_bar_item
|
struct top_bar_item
|
||||||
{
|
{
|
||||||
float width;
|
float width;
|
||||||
std::function<void()> draw;
|
std::function<void()> draw;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Top bar: WiVRn logo + wordmark on the left, right_items right-aligned. Manages its own
|
// Top bar: WiVRn logo + wordmark on the left, right_items right-aligned, height in pixels
|
||||||
// child window; height is the bar height in pixels.
|
|
||||||
void top_bar(float height, ImTextureID logo, const std::vector<top_bar_item> & right_items);
|
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()
|
// sidebar nav frame: scrolling top section, footer_items rows pinned at the bottom
|
||||||
// between the calls; pair begin_sidebar with end_sidebar.
|
// always pair: begin_sidebar -> sidebar_footer -> end_sidebar
|
||||||
void begin_sidebar(float top_bar_h, float tab_width);
|
void begin_sidebar(float top_bar_h, float tab_width, int footer_items = 0);
|
||||||
|
void sidebar_footer();
|
||||||
void end_sidebar();
|
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);
|
void shell_dividers(float top_bar_h, float tab_width);
|
||||||
|
|
||||||
} // namespace wivrn::ui
|
} // namespace wivrn::ui
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ namespace ui = wivrn::ui;
|
|||||||
|
|
||||||
namespace
|
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)
|
float grid_image_size(uint32_t size)
|
||||||
{
|
{
|
||||||
switch (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 size_w = ui::metrics::app_size_toggle_width;
|
||||||
const float disconnect_w = ui::button_width(cancel);
|
const float disconnect_w = ui::button_width(cancel);
|
||||||
|
|
||||||
// title row stays fixed: view/size toggles then disconnect, right-aligned and
|
// title row stays fixed: view/size toggles then disconnect, right-aligned, disconnect stays enabled while an app starts
|
||||||
// top-aligned with the title. Disconnect stays enabled even while an app starts.
|
|
||||||
const float right = ImGui::GetContentRegionMax().x;
|
const float right = ImGui::GetContentRegionMax().x;
|
||||||
ImGui::SetCursorPos({right - disconnect_w, header_top});
|
ImGui::SetCursorPos({right - disconnect_w, header_top});
|
||||||
if (ui::button(cancel, ui::button_style::danger))
|
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
|
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::PushStyleVar(ImGuiStyleVar_WindowPadding, {0, 0});
|
||||||
ImGui::BeginChild("applist", {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
|
else
|
||||||
{
|
{
|
||||||
// justified grid: as many columns as fit at the chosen icon size, then stretch
|
// justified grid: as many columns as fit, tiles stretched to divide the row exactly so there is no trailing gap
|
||||||
// every tile to divide the row exactly so there is no trailing gap; rows use the
|
|
||||||
// same gap as columns
|
|
||||||
const float tile_margin = ui::metrics::app_tile_margin;
|
const float tile_margin = ui::metrics::app_tile_margin;
|
||||||
const float target = grid_image_size(config.app_icon_size) + tile_margin * 2;
|
const float target = grid_image_size(config.app_icon_size) + tile_margin * 2;
|
||||||
const float avail = ImGui::GetContentRegionAvail().x;
|
const float avail = ImGui::GetContentRegionAvail().x;
|
||||||
|
|||||||
@@ -58,15 +58,14 @@ bool post_processing(
|
|||||||
|
|
||||||
float toggle_width();
|
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
|
struct battery_indicator
|
||||||
{
|
{
|
||||||
std::string label;
|
std::string label;
|
||||||
wivrn::ui::chip_style style;
|
wivrn::ui::chip_style style;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Current headset battery as a top-bar pill, or nullopt when unavailable (always nullopt
|
// headset battery as a top-bar pill, nullopt when unavailable, now drives the charging animation
|
||||||
// off Android). now drives the charging animation. Shared by the lobby and in-stream GUI.
|
|
||||||
std::optional<battery_indicator> battery_status_indicator(XrTime now);
|
std::optional<battery_indicator> battery_status_indicator(XrTime now);
|
||||||
|
|
||||||
} // namespace gui
|
} // namespace gui
|
||||||
|
|||||||
@@ -17,14 +17,9 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* 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`
|
// each page builds a list of `setting` descriptors, render_settings() draws the matching
|
||||||
// descriptors that reference the existing configuration members, and render_settings()
|
// ui:: widget for each, rebuilt every frame so dynamic options/descriptions just work
|
||||||
// renders the matching ui:: widget for each. Gating is done by conditionally adding a
|
// same pages serve the lobby and the in-stream window, gated by ctx.in_game
|
||||||
// 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.
|
|
||||||
|
|
||||||
#include "scenes/gui_common.h"
|
#include "scenes/gui_common.h"
|
||||||
#define IMGUI_DEFINE_MATH_OPERATORS
|
#define IMGUI_DEFINE_MATH_OPERATORS
|
||||||
@@ -76,9 +71,7 @@ enum class ui_kind
|
|||||||
button,
|
button,
|
||||||
};
|
};
|
||||||
|
|
||||||
// One declarative setting. Numeric controls (slider/segmented/combo) use get_int/set_int;
|
// one declarative setting, `enabled` greys the row out without hiding it
|
||||||
// segmented/combo indices map through `options`. Strings are owned so localized text stays
|
|
||||||
// valid. `enabled` greys the row out without hiding it.
|
|
||||||
struct setting
|
struct setting
|
||||||
{
|
{
|
||||||
const char * id; // stable imgui id
|
const char * id; // stable imgui id
|
||||||
@@ -168,8 +161,7 @@ void render_settings(const wivrn::gui::settings_context & ctx, const char * card
|
|||||||
|
|
||||||
ImGui::EndDisabled();
|
ImGui::EndDisabled();
|
||||||
|
|
||||||
// keep the row tall enough for a multi-line description and add breathing room
|
// reserve row height for a multi-line description plus padding, Dummy grows content size
|
||||||
// below. Reserve with Dummy (SetCursorPos would not grow the content size).
|
|
||||||
const float pad = std::max(label_bottom - ImGui::GetCursorPosY(), 0.f) + ui::metrics::label_bottom_pad;
|
const float pad = std::max(label_bottom - ImGui::GetCursorPosY(), 0.f) + ui::metrics::label_bottom_pad;
|
||||||
ImGui::Dummy({0, pad});
|
ImGui::Dummy({0, pad});
|
||||||
|
|
||||||
|
|||||||
+13
-23
@@ -120,7 +120,7 @@ void scenes::lobby::gui_connecting(locked_notifiable<pin_request_data> & pin_req
|
|||||||
if (async_error)
|
if (async_error)
|
||||||
close_button_label = _("Close");
|
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::Dummy({420, 0});
|
||||||
|
|
||||||
ImGui::PushFont(nullptr, style.FontSizeBase * ui::metrics::font_modal_title);
|
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)
|
for (auto && [cookie, data]: config.servers)
|
||||||
sorted_cookies.emplace(data.service.name, cookie);
|
sorted_cookies.emplace(data.service.name, cookie);
|
||||||
|
|
||||||
// deferred: the action menu runs inside the per-row id stack, but the popups are
|
// open below at this scope so OpenPopup and begin_modal hash to the same id
|
||||||
// opened below in this scope so OpenPopup and begin_modal hash to the same id
|
|
||||||
bool open_add_edit = false;
|
bool open_add_edit = false;
|
||||||
bool open_delete = false;
|
bool open_delete = false;
|
||||||
|
|
||||||
@@ -414,19 +413,15 @@ void scenes::lobby::gui_server_list()
|
|||||||
ui::row_separator();
|
ui::row_separator();
|
||||||
first = false;
|
first = false;
|
||||||
|
|
||||||
// Connect button reflects the real reachability state so a momentary
|
// reachable: manual or discovered with matching protocol
|
||||||
// discovery delay doesn't read as a hard failure:
|
// incompatible: discovered but protocol version differs, otherwise still searching
|
||||||
// - 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 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 bool incompatible = data.visible and data.service.txt.contains("protocol") and not data.compatible;
|
||||||
const float gap = ImGui::GetStyle().ItemSpacing.x;
|
const float gap = ImGui::GetStyle().ItemSpacing.x;
|
||||||
const float bh = ImGui::GetFrameHeight() * ui::metrics::control_height;
|
const float bh = ImGui::GetFrameHeight() * ui::metrics::control_height;
|
||||||
const std::string sub = fmt::format("{} : {}", data.service.hostname, data.service.port);
|
const std::string sub = fmt::format("{} : {}", data.service.hostname, data.service.port);
|
||||||
|
|
||||||
// trailing controls: [Auto chip] [Connect] [menu], measured up front so the
|
// trailing controls [Auto chip] [Connect] [menu], measured up front to exclude from the row click area
|
||||||
// row body click area can exclude them
|
|
||||||
const char * c_icon = reachable ? ICON_FA_PLAY : (incompatible ? ICON_FA_TRIANGLE_EXCLAMATION : ICON_FA_MAGNIFYING_GLASS);
|
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_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"));
|
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}))
|
if (ui::button(c_label, reachable ? ui::button_style::primary : ui::button_style::secondary, {cw, 0}))
|
||||||
{
|
{
|
||||||
connect(data);
|
connect(data);
|
||||||
// connecting popup is opened at window scope below (NOT here:
|
// popup opened at window scope below, outside begin_card's PushID so the id matches BeginPopupModal
|
||||||
// inside begin_card PushID the id would not match BeginPopupModal -> orphaned popup)
|
|
||||||
}
|
}
|
||||||
if (not c_tooltip.empty() and ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled))
|
if (not c_tooltip.empty() and ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled))
|
||||||
imgui_ctx->tooltip(c_tooltip);
|
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;
|
style.FontScaleMain = wivrn::ui::current().font_scale * wivrn::ui::metrics::font_base;
|
||||||
|
|
||||||
// rounding follows the theme so every window/popup gets rounded corners
|
// 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.WindowRounding = wivrn::ui::current().card_rounding;
|
||||||
style.ChildRounding = wivrn::ui::current().card_rounding;
|
style.ChildRounding = wivrn::ui::current().card_rounding;
|
||||||
style.PopupRounding = 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.GrabRounding = wivrn::ui::current().rounding;
|
||||||
style.TabRounding = 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_Text] = wivrn::ui::current().text;
|
||||||
style.Colors[ImGuiCol_TextDisabled] = wivrn::ui::current().text_muted;
|
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();
|
auto & config = application::get_config();
|
||||||
const float TopBarH = wivrn::ui::metrics::top_bar_height;
|
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;
|
const float side = ImGui::GetFrameHeight() * wivrn::ui::metrics::control_height;
|
||||||
std::vector<wivrn::ui::top_bar_item> top_items;
|
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) {
|
auto toggle_item = [&](const char * icon, const std::string & label, feature f) {
|
||||||
top_items.push_back({side, [icon, label, f] {
|
top_items.push_back({side, [icon, label, f] {
|
||||||
const float s = ImGui::GetFrameHeight() * wivrn::ui::metrics::control_height;
|
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);
|
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
|
// content area: content_margin from the sidebar, panel runs to the window's right edge so the scrollbar sits at the edge
|
||||||
// to the window's right edge so the scrollbar sits at the edge (no margin beside it).
|
|
||||||
const float content_margin = wivrn::ui::metrics::content_margin;
|
const float content_margin = wivrn::ui::metrics::content_margin;
|
||||||
ImGui::SetCursorPos({TabWidth + content_margin, TopBarH});
|
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::PushStyleVar(ImGuiStyleVar_WindowPadding, {content_margin, 20});
|
||||||
ImGui::BeginChild("Main", ImVec2(ImGui::GetWindowSize().x - ImGui::GetCursorPosX(), 0), 0);
|
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 to keep a gap from the wide scrollbar
|
||||||
// Pull the work area in on the right so the content keeps a clear gap from the scrollbar.
|
|
||||||
{
|
{
|
||||||
ImGuiWindow * main_child = ImGui::GetCurrentWindow();
|
ImGuiWindow * main_child = ImGui::GetCurrentWindow();
|
||||||
main_child->WorkRect.Max.x -= content_margin;
|
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::EndChild();
|
||||||
ImGui::PopStyleVar(2); // ImGuiStyleVar_FrameRounding, ImGuiStyleVar_WindowPadding
|
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))
|
if (wivrn::ui::nav_item(ICON_FA_COMPUTER, _S("Computers"), current_tab == tab::server_list))
|
||||||
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
|
#endif
|
||||||
|
|
||||||
// pinned to the bottom
|
// pinned to the bottom
|
||||||
const float item_h = ImGui::GetFrameHeight() * wivrn::ui::metrics::control_height + ImGui::GetStyle().ItemSpacing.y;
|
wivrn::ui::sidebar_footer();
|
||||||
ImGui::SetCursorPosY(ImGui::GetContentRegionMax().y - 3 * item_h - ImGui::GetStyle().WindowPadding.y);
|
|
||||||
if (wivrn::ui::nav_item(ICON_FA_CIRCLE_INFO, _S("About"), current_tab == tab::about))
|
if (wivrn::ui::nav_item(ICON_FA_CIRCLE_INFO, _S("About"), current_tab == tab::about))
|
||||||
current_tab = tab::about;
|
current_tab = tab::about;
|
||||||
if (wivrn::ui::nav_item(ICON_FA_SCALE_BALANCED, _S("Licenses"), current_tab == tab::licenses))
|
if (wivrn::ui::nav_item(ICON_FA_SCALE_BALANCED, _S("Licenses"), current_tab == tab::licenses))
|
||||||
|
|||||||
@@ -456,7 +456,7 @@ scenes::lobby::environment_item_action scenes::lobby::environment_item(environme
|
|||||||
action = environment_item_action::delete_model;
|
action = environment_item_action::delete_model;
|
||||||
}
|
}
|
||||||
|
|
||||||
// surface download errors the way the original did
|
// surface download errors
|
||||||
if (handle)
|
if (handle)
|
||||||
{
|
{
|
||||||
if (handle->get_state() == libcurl::state::error)
|
if (handle->get_state() == libcurl::state::error)
|
||||||
@@ -674,8 +674,7 @@ void scenes::lobby::gui_customize(XrTime predicted_display_time)
|
|||||||
ui::end_card();
|
ui::end_card();
|
||||||
}
|
}
|
||||||
|
|
||||||
// OpenPopup must run at the same ID-stack level as BeginPopupModal below;
|
// deferred past end_card so OpenPopup hashes at the same id-stack level as BeginPopupModal
|
||||||
// begin_card pushes an ID, so defer the call until after end_card.
|
|
||||||
if (open_download_popup)
|
if (open_download_popup)
|
||||||
ImGui::OpenPopup("download environment model");
|
ImGui::OpenPopup("download environment model");
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ void scenes::lobby::apply_theme_settings()
|
|||||||
{
|
{
|
||||||
auto & config = application::get_config();
|
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())
|
for (const auto & p: ui::presets())
|
||||||
{
|
{
|
||||||
if (p.name == config.theme_preset)
|
if (p.name == config.theme_preset)
|
||||||
@@ -152,8 +152,7 @@ void scenes::lobby::gui_theme()
|
|||||||
|
|
||||||
ui::row_separator();
|
ui::row_separator();
|
||||||
|
|
||||||
// Text size, applied globally via style.FontScaleMain next frame. 100% is the
|
// global font scale, 100% is the design default
|
||||||
// design default; the value is a user multiplier on metrics::font_base.
|
|
||||||
static const int font_scale_default = 100;
|
static const int font_scale_default = 100;
|
||||||
int font_scale = int(theme.font_scale * 100);
|
int font_scale = int(theme.font_scale * 100);
|
||||||
ui::setting_label(_S("Text size"), _S("Global font scale"), control_w);
|
ui::setting_label(_S("Text size"), _S("Global font scale"), control_w);
|
||||||
|
|||||||
@@ -523,9 +523,7 @@ void scenes::stream::on_focused()
|
|||||||
.tooltip_viewport = true,
|
.tooltip_viewport = true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// Pop up window: combos and modals float just in front of the main panel.
|
// popup window for combos and modals, tracks the main panel each frame at the same pixel density
|
||||||
// Position and orientation track the main panel each frame. Same pixel
|
|
||||||
// density as the main panel (1500 px/m) so text matches.
|
|
||||||
.space = xr::spaces::world,
|
.space = xr::spaces::world,
|
||||||
.size = {1.2, 0.6666},
|
.size = {1.2, 0.6666},
|
||||||
.vp_origin = {1800, 0},
|
.vp_origin = {1800, 0},
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ private:
|
|||||||
static bool is_interactable(stream_tab);
|
static bool is_interactable(stream_tab);
|
||||||
bool is_gui_interactable() const;
|
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
|
enum class settings_page
|
||||||
{
|
{
|
||||||
performance,
|
performance,
|
||||||
|
|||||||
@@ -574,7 +574,7 @@ void scenes::stream::gui_applications()
|
|||||||
wivrn::ui::row_separator();
|
wivrn::ui::row_separator();
|
||||||
first = false;
|
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 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 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);
|
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
|
// popup layer floats in front of the main panel so combos and modals pop as their own quad
|
||||||
// out as their own quad, like the lobby (see set_popup_center below).
|
|
||||||
imgui_ctx->place_layer_relative(2, 0, constants::gui::popup_position);
|
imgui_ctx->place_layer_relative(2, 0, constants::gui::popup_position);
|
||||||
|
|
||||||
const float tab_width = wivrn::ui::metrics::sidebar_width;
|
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();
|
ImGuiStyle & style = ImGui::GetStyle();
|
||||||
imgui_ctx->new_frame(predicted_display_time);
|
imgui_ctx->new_frame(predicted_display_time);
|
||||||
|
|
||||||
// theme the shared cards like the lobby
|
// theme the shared cards like the lobby, widget hooks are global so re-point at this scene
|
||||||
// the widget hooks are global, re-point them at this scene's context
|
|
||||||
style.FontScaleMain = wivrn::ui::current().font_scale * wivrn::ui::metrics::font_base;
|
style.FontScaleMain = wivrn::ui::current().font_scale * wivrn::ui::metrics::font_base;
|
||||||
style.WindowRounding = wivrn::ui::current().card_rounding;
|
style.WindowRounding = wivrn::ui::current().card_rounding;
|
||||||
style.ChildRounding = 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)
|
if (display_tabs)
|
||||||
{
|
{
|
||||||
// top bar: logo left; battery, connection status and window controls right
|
// top bar: logo left, battery/connection status/window controls right
|
||||||
// (close/disconnect have no quick-toggles: those only apply on connection)
|
|
||||||
const float side = ImGui::GetFrameHeight() * wivrn::ui::metrics::control_height;
|
const float side = ImGui::GetFrameHeight() * wivrn::ui::metrics::control_height;
|
||||||
std::vector<wivrn::ui::top_bar_item> top_items;
|
std::vector<wivrn::ui::top_bar_item> top_items;
|
||||||
if (auto bat = wivrn::gui::battery_status_indicator(instance.now()))
|
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}))
|
if (wivrn::ui::button(ICON_FA_XMARK, close_label, wivrn::ui::button_style::secondary, {0, side}))
|
||||||
next_gui_status = stream_tab::hidden;
|
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;
|
bool request_disconnect = false;
|
||||||
const std::string disconnect_label = _S("Disconnect");
|
const std::string disconnect_label = _S("Disconnect");
|
||||||
top_items.push_back({wivrn::ui::button_width(ICON_FA_DOOR_OPEN, disconnect_label),
|
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)
|
if (wivrn::ui::confirm_modal("confirm disconnect", _("Disconnect"), _("Disconnect from the server and return to the lobby?"), _("Disconnect"), _("Cancel"), true) == 1)
|
||||||
exit();
|
exit();
|
||||||
|
|
||||||
// navigation sidebar; the settings items swap the page but keep the coarse `settings` tab
|
// navigation sidebar, the settings items swap the page but keep the coarse settings tab
|
||||||
wivrn::ui::begin_sidebar(top_bar_h, tab_width);
|
wivrn::ui::begin_sidebar(top_bar_h, tab_width, 2);
|
||||||
{
|
{
|
||||||
wivrn::ui::nav_section(_S("STREAM"));
|
wivrn::ui::nav_section(_S("STREAM"));
|
||||||
if (wivrn::ui::nav_item(ICON_FA_LIST, _S("Applications"), gui_status == stream_tab::applications))
|
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);
|
settings_item(ICON_FA_GEARS, _S("System"), settings_page::system);
|
||||||
|
|
||||||
// pinned to the bottom
|
// pinned to the bottom
|
||||||
const float item_h = ImGui::GetFrameHeight() * wivrn::ui::metrics::control_height + ImGui::GetStyle().ItemSpacing.y;
|
wivrn::ui::sidebar_footer();
|
||||||
ImGui::SetCursorPosY(ImGui::GetContentRegionMax().y - 2 * item_h - ImGui::GetStyle().WindowPadding.y);
|
|
||||||
|
|
||||||
if (wivrn::ui::nav_item(ICON_FA_CHART_LINE, _S("Statistics overlay"), false))
|
if (wivrn::ui::nav_item(ICON_FA_CHART_LINE, _S("Statistics overlay"), false))
|
||||||
next_gui_status = stream_tab::overlay_only;
|
next_gui_status = stream_tab::overlay_only;
|
||||||
if (wivrn::ui::nav_item(ICON_FA_MINIMIZE, _S("Compact view"), false))
|
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
|
// add the GUI layers, dim the main panel behind a modal popup, popup quad stays bright
|
||||||
// first layer) behind it like the lobby; the popup quad itself stays bright.
|
|
||||||
bool dim_main = imgui_ctx->is_modal_popup_shown() and composition_layer_color_scale_bias_supported;
|
bool dim_main = imgui_ctx->is_modal_popup_shown() and composition_layer_color_scale_bias_supported;
|
||||||
for (auto [_, layer]: layers)
|
for (auto [_, layer]: layers)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user