Code cleanup
This commit is contained in:
committed by
Guillaume Meunier
parent
5e359fe983
commit
80ee73128d
@@ -42,7 +42,7 @@ namespace ui = wivrn::ui;
|
||||
|
||||
namespace
|
||||
{
|
||||
// target grid icon size for the small/medium/large setting; tiles stretch from this to fill the row
|
||||
// target grid icon size per small/medium/large setting, tiles stretch from this to fill the row
|
||||
float grid_image_size(uint32_t size)
|
||||
{
|
||||
switch (size)
|
||||
@@ -174,8 +174,7 @@ app_launcher::clicked app_launcher::draw_gui(imgui_context & imgui_ctx, const st
|
||||
const float size_w = ui::metrics::app_size_toggle_width;
|
||||
const float disconnect_w = ui::button_width(cancel);
|
||||
|
||||
// title row stays fixed: view/size toggles then disconnect, right-aligned and
|
||||
// top-aligned with the title. Disconnect stays enabled even while an app starts.
|
||||
// title row stays fixed: view/size toggles then disconnect, right-aligned, disconnect stays enabled while an app starts
|
||||
const float right = ImGui::GetContentRegionMax().x;
|
||||
ImGui::SetCursorPos({right - disconnect_w, header_top});
|
||||
if (ui::button(cancel, ui::button_style::danger))
|
||||
@@ -214,7 +213,7 @@ app_launcher::clicked app_launcher::draw_gui(imgui_context & imgui_ctx, const st
|
||||
}
|
||||
else
|
||||
{
|
||||
// only the grid/list scrolls; flush to the header edge with no extra inset
|
||||
// only the grid/list scrolls, flush to the header edge with no extra inset
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, {0, 0});
|
||||
ImGui::BeginChild("applist", {0, 0});
|
||||
|
||||
@@ -231,9 +230,7 @@ app_launcher::clicked app_launcher::draw_gui(imgui_context & imgui_ctx, const st
|
||||
}
|
||||
else
|
||||
{
|
||||
// justified grid: as many columns as fit at the chosen icon size, then stretch
|
||||
// every tile to divide the row exactly so there is no trailing gap; rows use the
|
||||
// same gap as columns
|
||||
// justified grid: as many columns as fit, tiles stretched to divide the row exactly so there is no trailing gap
|
||||
const float tile_margin = ui::metrics::app_tile_margin;
|
||||
const float target = grid_image_size(config.app_icon_size) + tile_margin * 2;
|
||||
const float avail = ImGui::GetContentRegionAvail().x;
|
||||
|
||||
@@ -58,15 +58,14 @@ bool post_processing(
|
||||
|
||||
float toggle_width();
|
||||
|
||||
// Battery pill shown in the top bar: the icon+percent label and the threshold colour.
|
||||
// top-bar battery pill: icon+percent label and threshold colour
|
||||
struct battery_indicator
|
||||
{
|
||||
std::string label;
|
||||
wivrn::ui::chip_style style;
|
||||
};
|
||||
|
||||
// Current headset battery as a top-bar pill, or nullopt when unavailable (always nullopt
|
||||
// off Android). now drives the charging animation. Shared by the lobby and in-stream GUI.
|
||||
// headset battery as a top-bar pill, nullopt when unavailable, now drives the charging animation
|
||||
std::optional<battery_indicator> battery_status_indicator(XrTime now);
|
||||
|
||||
} // namespace gui
|
||||
|
||||
@@ -17,14 +17,9 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// The settings screens are drawn procedurally: each page builds a list of `setting`
|
||||
// descriptors that reference the existing configuration members, and render_settings()
|
||||
// renders the matching ui:: widget for each. Gating is done by conditionally adding a
|
||||
// descriptor; the disabled-but-shown case uses the `enabled` predicate. Descriptors are
|
||||
// rebuilt every frame, so dynamic options and descriptions just work.
|
||||
//
|
||||
// The same pages serve the lobby and the in-stream window, where in_game disables the
|
||||
// connection-time settings and shows the in-stream controls.
|
||||
// each page builds a list of `setting` descriptors, render_settings() draws the matching
|
||||
// ui:: widget for each, rebuilt every frame so dynamic options/descriptions just work
|
||||
// same pages serve the lobby and the in-stream window, gated by ctx.in_game
|
||||
|
||||
#include "scenes/gui_common.h"
|
||||
#define IMGUI_DEFINE_MATH_OPERATORS
|
||||
@@ -76,9 +71,7 @@ enum class ui_kind
|
||||
button,
|
||||
};
|
||||
|
||||
// One declarative setting. Numeric controls (slider/segmented/combo) use get_int/set_int;
|
||||
// segmented/combo indices map through `options`. Strings are owned so localized text stays
|
||||
// valid. `enabled` greys the row out without hiding it.
|
||||
// one declarative setting, `enabled` greys the row out without hiding it
|
||||
struct setting
|
||||
{
|
||||
const char * id; // stable imgui id
|
||||
@@ -168,8 +161,7 @@ void render_settings(const wivrn::gui::settings_context & ctx, const char * card
|
||||
|
||||
ImGui::EndDisabled();
|
||||
|
||||
// keep the row tall enough for a multi-line description and add breathing room
|
||||
// below. Reserve with Dummy (SetCursorPos would not grow the content size).
|
||||
// reserve row height for a multi-line description plus padding, Dummy grows content size
|
||||
const float pad = std::max(label_bottom - ImGui::GetCursorPosY(), 0.f) + ui::metrics::label_bottom_pad;
|
||||
ImGui::Dummy({0, pad});
|
||||
|
||||
|
||||
+13
-23
@@ -120,7 +120,7 @@ void scenes::lobby::gui_connecting(locked_notifiable<pin_request_data> & pin_req
|
||||
if (async_error)
|
||||
close_button_label = _("Close");
|
||||
|
||||
// keep a sensible minimum width as the status text changes between stages
|
||||
// minimum width as the status text changes between stages
|
||||
ImGui::Dummy({420, 0});
|
||||
|
||||
ImGui::PushFont(nullptr, style.FontSizeBase * ui::metrics::font_modal_title);
|
||||
@@ -390,8 +390,7 @@ void scenes::lobby::gui_server_list()
|
||||
for (auto && [cookie, data]: config.servers)
|
||||
sorted_cookies.emplace(data.service.name, cookie);
|
||||
|
||||
// deferred: the action menu runs inside the per-row id stack, but the popups are
|
||||
// opened below in this scope so OpenPopup and begin_modal hash to the same id
|
||||
// open below at this scope so OpenPopup and begin_modal hash to the same id
|
||||
bool open_add_edit = false;
|
||||
bool open_delete = false;
|
||||
|
||||
@@ -414,19 +413,15 @@ void scenes::lobby::gui_server_list()
|
||||
ui::row_separator();
|
||||
first = false;
|
||||
|
||||
// Connect button reflects the real reachability state so a momentary
|
||||
// discovery delay doesn't read as a hard failure:
|
||||
// - reachable: manual server, or one discovered with a matching protocol
|
||||
// - incompatible: discovered and resolved, but the protocol version differs
|
||||
// - searching: not seen on the network yet (or still resolving its records)
|
||||
// reachable: manual or discovered with matching protocol
|
||||
// incompatible: discovered but protocol version differs, otherwise still searching
|
||||
const bool reachable = (data.visible and data.compatible) or data.manual;
|
||||
const bool incompatible = data.visible and data.service.txt.contains("protocol") and not data.compatible;
|
||||
const float gap = ImGui::GetStyle().ItemSpacing.x;
|
||||
const float bh = ImGui::GetFrameHeight() * ui::metrics::control_height;
|
||||
const std::string sub = fmt::format("{} : {}", data.service.hostname, data.service.port);
|
||||
|
||||
// trailing controls: [Auto chip] [Connect] [menu], measured up front so the
|
||||
// row body click area can exclude them
|
||||
// trailing controls [Auto chip] [Connect] [menu], measured up front to exclude from the row click area
|
||||
const char * c_icon = reachable ? ICON_FA_PLAY : (incompatible ? ICON_FA_TRIANGLE_EXCLAMATION : ICON_FA_MAGNIFYING_GLASS);
|
||||
const std::string c_label = ui::icon_label(c_icon, reachable ? _("Connect") : (incompatible ? _("Incompatible") : _("Searching…")));
|
||||
const std::string c_tooltip = reachable ? std::string{} : (incompatible ? _("Incompatible server version") : _("Looking for this server on your network"));
|
||||
@@ -477,8 +472,7 @@ void scenes::lobby::gui_server_list()
|
||||
if (ui::button(c_label, reachable ? ui::button_style::primary : ui::button_style::secondary, {cw, 0}))
|
||||
{
|
||||
connect(data);
|
||||
// connecting popup is opened at window scope below (NOT here:
|
||||
// inside begin_card PushID the id would not match BeginPopupModal -> orphaned popup)
|
||||
// popup opened at window scope below, outside begin_card's PushID so the id matches BeginPopupModal
|
||||
}
|
||||
if (not c_tooltip.empty() and ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled))
|
||||
imgui_ctx->tooltip(c_tooltip);
|
||||
@@ -1035,7 +1029,6 @@ std::vector<std::pair<int, XrCompositionLayerQuad>> scenes::lobby::draw_gui(XrTi
|
||||
style.FontScaleMain = wivrn::ui::current().font_scale * wivrn::ui::metrics::font_base;
|
||||
|
||||
// rounding follows the theme so every window/popup gets rounded corners
|
||||
// (theme::apply() is never called; the widgets theme colours themselves but nothing sets rounding)
|
||||
style.WindowRounding = wivrn::ui::current().card_rounding;
|
||||
style.ChildRounding = wivrn::ui::current().card_rounding;
|
||||
style.PopupRounding = wivrn::ui::current().card_rounding;
|
||||
@@ -1043,7 +1036,7 @@ std::vector<std::pair<int, XrCompositionLayerQuad>> scenes::lobby::draw_gui(XrTi
|
||||
style.GrabRounding = wivrn::ui::current().rounding;
|
||||
style.TabRounding = wivrn::ui::current().rounding;
|
||||
|
||||
// base text colour follows the theme so plain ImGui text is legible on light themes
|
||||
// base text colour follows the theme so plain ImGui text stays legible
|
||||
style.Colors[ImGuiCol_Text] = wivrn::ui::current().text;
|
||||
style.Colors[ImGuiCol_TextDisabled] = wivrn::ui::current().text_muted;
|
||||
|
||||
@@ -1101,11 +1094,11 @@ std::vector<std::pair<int, XrCompositionLayerQuad>> scenes::lobby::draw_gui(XrTi
|
||||
auto & config = application::get_config();
|
||||
const float TopBarH = wivrn::ui::metrics::top_bar_height;
|
||||
|
||||
// Top bar: logo left; feature toggles, battery and connection status right.
|
||||
// Top bar: logo left, feature toggles / battery / connection status right
|
||||
const float side = ImGui::GetFrameHeight() * wivrn::ui::metrics::control_height;
|
||||
std::vector<wivrn::ui::top_bar_item> top_items;
|
||||
|
||||
// feature toggle slot: reads its state and toggles on click (mic + passthrough always shown)
|
||||
// feature toggle slot: reads its state, toggles on click
|
||||
auto toggle_item = [&](const char * icon, const std::string & label, feature f) {
|
||||
top_items.push_back({side, [icon, label, f] {
|
||||
const float s = ImGui::GetFrameHeight() * wivrn::ui::metrics::control_height;
|
||||
@@ -1146,8 +1139,7 @@ std::vector<std::pair<int, XrCompositionLayerQuad>> scenes::lobby::draw_gui(XrTi
|
||||
|
||||
wivrn::ui::top_bar(TopBarH, about_picture, top_items);
|
||||
|
||||
// content area: content_margin from the sidebar on the left; the panel runs all the way
|
||||
// to the window's right edge so the scrollbar sits at the edge (no margin beside it).
|
||||
// content area: content_margin from the sidebar, panel runs to the window's right edge so the scrollbar sits at the edge
|
||||
const float content_margin = wivrn::ui::metrics::content_margin;
|
||||
ImGui::SetCursorPos({TabWidth + content_margin, TopBarH});
|
||||
|
||||
@@ -1155,8 +1147,7 @@ std::vector<std::pair<int, XrCompositionLayerQuad>> scenes::lobby::draw_gui(XrTi
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, {content_margin, 20});
|
||||
ImGui::BeginChild("Main", ImVec2(ImGui::GetWindowSize().x - ImGui::GetCursorPosX(), 0), 0);
|
||||
|
||||
// The scrollbar is wide (30px); WindowPadding alone leaves the content cramped against it.
|
||||
// Pull the work area in on the right so the content keeps a clear gap from the scrollbar.
|
||||
// pull the work area in on the right to keep a gap from the wide scrollbar
|
||||
{
|
||||
ImGuiWindow * main_child = ImGui::GetCurrentWindow();
|
||||
main_child->WorkRect.Max.x -= content_margin;
|
||||
@@ -1241,7 +1232,7 @@ std::vector<std::pair<int, XrCompositionLayerQuad>> scenes::lobby::draw_gui(XrTi
|
||||
ImGui::EndChild();
|
||||
ImGui::PopStyleVar(2); // ImGuiStyleVar_FrameRounding, ImGuiStyleVar_WindowPadding
|
||||
|
||||
wivrn::ui::begin_sidebar(TopBarH, TabWidth);
|
||||
wivrn::ui::begin_sidebar(TopBarH, TabWidth, 3);
|
||||
{
|
||||
if (wivrn::ui::nav_item(ICON_FA_COMPUTER, _S("Computers"), current_tab == tab::server_list))
|
||||
current_tab = tab::server_list;
|
||||
@@ -1273,8 +1264,7 @@ std::vector<std::pair<int, XrCompositionLayerQuad>> scenes::lobby::draw_gui(XrTi
|
||||
#endif
|
||||
|
||||
// pinned to the bottom
|
||||
const float item_h = ImGui::GetFrameHeight() * wivrn::ui::metrics::control_height + ImGui::GetStyle().ItemSpacing.y;
|
||||
ImGui::SetCursorPosY(ImGui::GetContentRegionMax().y - 3 * item_h - ImGui::GetStyle().WindowPadding.y);
|
||||
wivrn::ui::sidebar_footer();
|
||||
if (wivrn::ui::nav_item(ICON_FA_CIRCLE_INFO, _S("About"), current_tab == tab::about))
|
||||
current_tab = tab::about;
|
||||
if (wivrn::ui::nav_item(ICON_FA_SCALE_BALANCED, _S("Licenses"), current_tab == tab::licenses))
|
||||
|
||||
@@ -456,7 +456,7 @@ scenes::lobby::environment_item_action scenes::lobby::environment_item(environme
|
||||
action = environment_item_action::delete_model;
|
||||
}
|
||||
|
||||
// surface download errors the way the original did
|
||||
// surface download errors
|
||||
if (handle)
|
||||
{
|
||||
if (handle->get_state() == libcurl::state::error)
|
||||
@@ -674,8 +674,7 @@ void scenes::lobby::gui_customize(XrTime predicted_display_time)
|
||||
ui::end_card();
|
||||
}
|
||||
|
||||
// OpenPopup must run at the same ID-stack level as BeginPopupModal below;
|
||||
// begin_card pushes an ID, so defer the call until after end_card.
|
||||
// deferred past end_card so OpenPopup hashes at the same id-stack level as BeginPopupModal
|
||||
if (open_download_popup)
|
||||
ImGui::OpenPopup("download environment model");
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ void scenes::lobby::apply_theme_settings()
|
||||
{
|
||||
auto & config = application::get_config();
|
||||
|
||||
// preset by name; surfaces only, the accent is applied separately below
|
||||
// preset by name, surfaces only, accent applied separately below
|
||||
for (const auto & p: ui::presets())
|
||||
{
|
||||
if (p.name == config.theme_preset)
|
||||
@@ -152,8 +152,7 @@ void scenes::lobby::gui_theme()
|
||||
|
||||
ui::row_separator();
|
||||
|
||||
// Text size, applied globally via style.FontScaleMain next frame. 100% is the
|
||||
// design default; the value is a user multiplier on metrics::font_base.
|
||||
// global font scale, 100% is the design default
|
||||
static const int font_scale_default = 100;
|
||||
int font_scale = int(theme.font_scale * 100);
|
||||
ui::setting_label(_S("Text size"), _S("Global font scale"), control_w);
|
||||
|
||||
@@ -523,9 +523,7 @@ void scenes::stream::on_focused()
|
||||
.tooltip_viewport = true,
|
||||
},
|
||||
{
|
||||
// Pop up window: combos and modals float just in front of the main panel.
|
||||
// Position and orientation track the main panel each frame. Same pixel
|
||||
// density as the main panel (1500 px/m) so text matches.
|
||||
// popup window for combos and modals, tracks the main panel each frame at the same pixel density
|
||||
.space = xr::spaces::world,
|
||||
.size = {1.2, 0.6666},
|
||||
.vp_origin = {1800, 0},
|
||||
|
||||
@@ -142,7 +142,7 @@ private:
|
||||
static bool is_interactable(stream_tab);
|
||||
bool is_gui_interactable() const;
|
||||
|
||||
// settings sub-page, client-only: the wire stream_tab stays `settings`
|
||||
// settings sub-page, client-only: the wire stream_tab stays settings
|
||||
enum class settings_page
|
||||
{
|
||||
performance,
|
||||
|
||||
@@ -574,7 +574,7 @@ void scenes::stream::gui_applications()
|
||||
wivrn::ui::row_separator();
|
||||
first = false;
|
||||
|
||||
// overlays and the active app aren't selectable; only their stop button acts
|
||||
// overlays and the active app aren't selectable, only their stop button acts
|
||||
const bool interactive = not(app.active or app.overlay);
|
||||
const float trailing = stop_w + (app.active ? gap + active_sz.x : 0) + wivrn::ui::metrics::list_row_pad;
|
||||
const auto row = wivrn::ui::begin_list_row("##row", ICON_FA_CUBE, 0, app.name, {}, app.active, trailing, 0, false, interactive);
|
||||
@@ -748,8 +748,7 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte
|
||||
}
|
||||
}
|
||||
|
||||
// The popup layer floats just in front of the main panel so combos and modals pop
|
||||
// out as their own quad, like the lobby (see set_popup_center below).
|
||||
// popup layer floats in front of the main panel so combos and modals pop as their own quad
|
||||
imgui_ctx->place_layer_relative(2, 0, constants::gui::popup_position);
|
||||
|
||||
const float tab_width = wivrn::ui::metrics::sidebar_width;
|
||||
@@ -760,8 +759,7 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte
|
||||
ImGuiStyle & style = ImGui::GetStyle();
|
||||
imgui_ctx->new_frame(predicted_display_time);
|
||||
|
||||
// theme the shared cards like the lobby
|
||||
// the widget hooks are global, re-point them at this scene's context
|
||||
// theme the shared cards like the lobby, widget hooks are global so re-point at this scene
|
||||
style.FontScaleMain = wivrn::ui::current().font_scale * wivrn::ui::metrics::font_base;
|
||||
style.WindowRounding = wivrn::ui::current().card_rounding;
|
||||
style.ChildRounding = wivrn::ui::current().card_rounding;
|
||||
@@ -918,8 +916,7 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte
|
||||
|
||||
if (display_tabs)
|
||||
{
|
||||
// top bar: logo left; battery, connection status and window controls right
|
||||
// (close/disconnect have no quick-toggles: those only apply on connection)
|
||||
// top bar: logo left, battery/connection status/window controls right
|
||||
const float side = ImGui::GetFrameHeight() * wivrn::ui::metrics::control_height;
|
||||
std::vector<wivrn::ui::top_bar_item> top_items;
|
||||
if (auto bat = wivrn::gui::battery_status_indicator(instance.now()))
|
||||
@@ -934,7 +931,7 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte
|
||||
if (wivrn::ui::button(ICON_FA_XMARK, close_label, wivrn::ui::button_style::secondary, {0, side}))
|
||||
next_gui_status = stream_tab::hidden;
|
||||
}});
|
||||
// disconnect asks for confirmation; OpenPopup/confirm_modal share the window id stack
|
||||
// disconnect asks for confirmation, OpenPopup/confirm_modal share the window id stack
|
||||
bool request_disconnect = false;
|
||||
const std::string disconnect_label = _S("Disconnect");
|
||||
top_items.push_back({wivrn::ui::button_width(ICON_FA_DOOR_OPEN, disconnect_label),
|
||||
@@ -949,8 +946,8 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte
|
||||
if (wivrn::ui::confirm_modal("confirm disconnect", _("Disconnect"), _("Disconnect from the server and return to the lobby?"), _("Disconnect"), _("Cancel"), true) == 1)
|
||||
exit();
|
||||
|
||||
// navigation sidebar; the settings items swap the page but keep the coarse `settings` tab
|
||||
wivrn::ui::begin_sidebar(top_bar_h, tab_width);
|
||||
// navigation sidebar, the settings items swap the page but keep the coarse settings tab
|
||||
wivrn::ui::begin_sidebar(top_bar_h, tab_width, 2);
|
||||
{
|
||||
wivrn::ui::nav_section(_S("STREAM"));
|
||||
if (wivrn::ui::nav_item(ICON_FA_LIST, _S("Applications"), gui_status == stream_tab::applications))
|
||||
@@ -984,9 +981,7 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte
|
||||
settings_item(ICON_FA_GEARS, _S("System"), settings_page::system);
|
||||
|
||||
// pinned to the bottom
|
||||
const float item_h = ImGui::GetFrameHeight() * wivrn::ui::metrics::control_height + ImGui::GetStyle().ItemSpacing.y;
|
||||
ImGui::SetCursorPosY(ImGui::GetContentRegionMax().y - 2 * item_h - ImGui::GetStyle().WindowPadding.y);
|
||||
|
||||
wivrn::ui::sidebar_footer();
|
||||
if (wivrn::ui::nav_item(ICON_FA_CHART_LINE, _S("Statistics overlay"), false))
|
||||
next_gui_status = stream_tab::overlay_only;
|
||||
if (wivrn::ui::nav_item(ICON_FA_MINIMIZE, _S("Compact view"), false))
|
||||
@@ -1081,8 +1076,7 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte
|
||||
}
|
||||
}
|
||||
|
||||
// Add the layer with the GUI. While a modal popup is shown, dim the main panel (the
|
||||
// first layer) behind it like the lobby; the popup quad itself stays bright.
|
||||
// add the GUI layers, dim the main panel behind a modal popup, popup quad stays bright
|
||||
bool dim_main = imgui_ctx->is_modal_popup_shown() and composition_layer_color_scale_bias_supported;
|
||||
for (auto [_, layer]: layers)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user