Fixes and improvements
This commit is contained in:
committed by
Guillaume Meunier
parent
12834824ab
commit
e4b4bfa66d
@@ -115,6 +115,9 @@ constexpr float font_modal_title = 1.2; // modal heading, x base font size
|
||||
constexpr float label_line_gap = 5; // title to description
|
||||
constexpr float label_bottom_pad = 6; // breathing room below the description
|
||||
constexpr float nav_section_gap = 18; // space above a sidebar section header
|
||||
|
||||
constexpr ImVec2 card_item_spacing = {12, 10}; // ItemSpacing pushed around a card section
|
||||
constexpr float setting_control_width = 480; // width of the control in a setting row
|
||||
} // namespace metrics
|
||||
|
||||
// Theme in effect, call current().apply() after mutating
|
||||
|
||||
@@ -224,6 +224,31 @@ button_colors colors_for(button_style s, const theme & t)
|
||||
}
|
||||
} // namespace
|
||||
|
||||
std::string icon_label(const char * icon, const std::string & label)
|
||||
{
|
||||
return std::string(icon) + " " + label;
|
||||
}
|
||||
|
||||
float button_width(const std::string & label)
|
||||
{
|
||||
return ImGui::CalcTextSize(label.c_str()).x + metrics::button_padding.x * 2;
|
||||
}
|
||||
|
||||
float button_width(const char * icon, const std::string & label)
|
||||
{
|
||||
ImGui::PushFont(nullptr, ImGui::GetFontSize() * metrics::button_label_glyph);
|
||||
const float icon_w = ImGui::CalcTextSize(icon).x;
|
||||
ImGui::PopFont();
|
||||
const float gap = ImGui::GetFontSize() * 0.4f;
|
||||
return icon_w + gap + ImGui::CalcTextSize(label.c_str()).x + metrics::button_padding.x * 2;
|
||||
}
|
||||
|
||||
ImVec2 chip_size(const std::string & label)
|
||||
{
|
||||
const ImVec2 ts = ImGui::CalcTextSize(label.c_str());
|
||||
return {ts.x + metrics::chip_padding.x * 2, ts.y + metrics::chip_padding.y * 2};
|
||||
}
|
||||
|
||||
bool button(const std::string & label, button_style s, const ImVec2 & size)
|
||||
{
|
||||
const theme & t = current();
|
||||
@@ -866,7 +891,10 @@ bool nav_item(const char * icon, const std::string & label, bool selected)
|
||||
hover_haptic();
|
||||
|
||||
ImDrawList * draw = window->DrawList;
|
||||
const ImVec4 bg = selected ? t.control : (hovered ? t.control_hovered : ImVec4{0, 0, 0, 0});
|
||||
// Subtle accent tint at a fixed alpha so the highlight reads the same in every
|
||||
// theme, instead of the per-theme control surface whose contrast varies.
|
||||
ImVec4 bg = t.accent;
|
||||
bg.w = selected ? 0.16f : (hovered ? 0.08f : 0);
|
||||
if (bg.w > 0)
|
||||
draw->AddRectFilled(bb.Min, bb.Max, t.col(bg), t.rounding);
|
||||
|
||||
|
||||
@@ -52,6 +52,19 @@ void row_separator();
|
||||
// enough for a multi-line label.
|
||||
float setting_label(const std::string & title, const std::string & description, float control_width);
|
||||
|
||||
// "<icon> <label>" with the standard two-space gap, for chips and text buttons that
|
||||
// take a single label string with an embedded glyph.
|
||||
std::string icon_label(const char * icon, const std::string & label);
|
||||
|
||||
// Auto-fit width of a button, matching what button() lays out when size.x is left at 0.
|
||||
// Use to reserve/right-align a button before drawing it. The icon overload accounts for
|
||||
// the leading glyph drawn at metrics::button_label_glyph.
|
||||
float button_width(const std::string & label);
|
||||
float button_width(const char * icon, const std::string & label);
|
||||
|
||||
// Footprint of a chip() with standard padding (no dot, no height override).
|
||||
ImVec2 chip_size(const std::string & label);
|
||||
|
||||
bool button(const std::string & label, button_style style = button_style::primary, const ImVec2 & size = {0, 0});
|
||||
// Same, with a larger leading icon glyph drawn before the label
|
||||
bool button(const char * icon, const std::string & label, button_style style = button_style::primary, const ImVec2 & size = {0, 0});
|
||||
@@ -135,6 +148,13 @@ struct list_row_result
|
||||
{
|
||||
ImVec2 min, max; // row rect (screen) for right-aligning trailing controls
|
||||
bool clicked; // the row body was clicked
|
||||
|
||||
// Screen position for a trailing control of the given size, right-aligned to right_x
|
||||
// and vertically centred in the row. Feed to ImGui::SetCursorScreenPos.
|
||||
ImVec2 trailing(float right_x, const ImVec2 & size) const
|
||||
{
|
||||
return {right_x - size.x, min.y + (max.y - min.y - size.y) * 0.5f};
|
||||
}
|
||||
};
|
||||
|
||||
// List row: leading thumbnail (image, if non-zero) or icon box, title and muted subtitle.
|
||||
|
||||
+18
-28
@@ -319,8 +319,8 @@ void scenes::lobby::gui_new_server()
|
||||
const float gap = ImGui::GetStyle().ItemSpacing.x;
|
||||
const std::string cancel_l = _("Cancel");
|
||||
const std::string save_l = _("Save");
|
||||
const float cancel_w = ImGui::CalcTextSize(cancel_l.c_str()).x + ui::metrics::button_padding.x * 2;
|
||||
const float save_w = ImGui::CalcTextSize(save_l.c_str()).x + ui::metrics::button_padding.x * 2;
|
||||
const float cancel_w = ui::button_width(cancel_l);
|
||||
const float save_w = ui::button_width(save_l);
|
||||
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + ImGui::GetContentRegionAvail().x - cancel_w - save_w - gap);
|
||||
|
||||
if (ui::button(cancel_l, ui::button_style::secondary, {cancel_w, 0}))
|
||||
@@ -367,11 +367,7 @@ void scenes::lobby::gui_server_list()
|
||||
const ImVec2 hend = ImGui::GetCursorPos();
|
||||
|
||||
const std::string add_label = _("Add server");
|
||||
const float font = ImGui::GetFontSize();
|
||||
ImGui::PushFont(nullptr, font * ui::metrics::button_label_glyph);
|
||||
const float glyph_w = ImGui::CalcTextSize(ICON_FA_PLUS).x;
|
||||
ImGui::PopFont();
|
||||
const float add_w = glyph_w + font * 0.4f + ImGui::CalcTextSize(add_label.c_str()).x + ui::metrics::button_padding.x * 2;
|
||||
const float add_w = ui::button_width(ICON_FA_PLUS, add_label);
|
||||
ImGui::SetCursorPos({hstart.x + header_avail - add_w, hstart.y});
|
||||
if (ui::button(ICON_FA_PLUS, add_label, ui::button_style::primary))
|
||||
{
|
||||
@@ -393,7 +389,7 @@ void scenes::lobby::gui_server_list()
|
||||
bool open_add_edit = false;
|
||||
bool open_delete = false;
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, {12, 10});
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ui::metrics::card_item_spacing);
|
||||
ui::begin_card("##servers");
|
||||
{
|
||||
if (sorted_cookies.empty())
|
||||
@@ -426,16 +422,14 @@ void scenes::lobby::gui_server_list()
|
||||
// trailing controls: [Auto chip] [Connect] [menu], measured up front so the
|
||||
// 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 std::string c_label = std::string(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 float cw = ImGui::CalcTextSize(c_label.c_str()).x + ui::metrics::button_padding.x * 2;
|
||||
const std::string chip_label = std::string(ICON_FA_BOLT " ") + _("Auto");
|
||||
const ImVec2 chip_ts = ImGui::CalcTextSize(chip_label.c_str());
|
||||
const float chip_w = chip_ts.x + ui::metrics::chip_padding.x * 2;
|
||||
float trailing = bh + gap + cw + (data.autoconnect ? gap + chip_w : 0) + ui::metrics::list_row_pad;
|
||||
const float cw = ui::button_width(c_label);
|
||||
const std::string chip_label = ui::icon_label(ICON_FA_BOLT, _("Auto"));
|
||||
const ImVec2 chip_sz = ui::chip_size(chip_label);
|
||||
float trailing = bh + gap + cw + (data.autoconnect ? gap + chip_sz.x : 0) + ui::metrics::list_row_pad;
|
||||
|
||||
const auto row = ui::begin_list_row("##row", ICON_FA_SERVER, 0, name, sub, false, trailing);
|
||||
const float row_h = row.max.y - row.min.y;
|
||||
float x = row.max.x;
|
||||
|
||||
// overflow menu
|
||||
@@ -449,7 +443,7 @@ void scenes::lobby::gui_server_list()
|
||||
actions.push_back({ICON_FA_PEN, edit_l.c_str(), false, false});
|
||||
actions.push_back({ICON_FA_TRASH, del_l.c_str(), true, false});
|
||||
}
|
||||
ImGui::SetCursorScreenPos({x - bh, row.min.y + (row_h - bh) * 0.5f});
|
||||
ImGui::SetCursorScreenPos(row.trailing(x, {bh, bh}));
|
||||
switch (ui::action_menu("##menu", ICON_FA_ELLIPSIS_VERTICAL, actions))
|
||||
{
|
||||
case 0:
|
||||
@@ -472,7 +466,7 @@ void scenes::lobby::gui_server_list()
|
||||
x -= bh + gap;
|
||||
|
||||
// connect / searching / incompatible
|
||||
ImGui::SetCursorScreenPos({x - cw, row.min.y + (row_h - bh) * 0.5f});
|
||||
ImGui::SetCursorScreenPos(row.trailing(x, {cw, bh}));
|
||||
ImGui::BeginDisabled(not reachable);
|
||||
if (ui::button(c_label, reachable ? ui::button_style::primary : ui::button_style::secondary, {cw, 0}))
|
||||
{
|
||||
@@ -487,8 +481,7 @@ void scenes::lobby::gui_server_list()
|
||||
// Auto chip
|
||||
if (data.autoconnect)
|
||||
{
|
||||
const float chip_h = chip_ts.y + ui::metrics::chip_padding.y * 2;
|
||||
ImGui::SetCursorScreenPos({x - chip_w, row.min.y + (row_h - chip_h) * 0.5f});
|
||||
ImGui::SetCursorScreenPos(row.trailing(x, chip_sz));
|
||||
ui::chip(chip_label, ui::chip_style::accent);
|
||||
}
|
||||
|
||||
@@ -514,9 +507,8 @@ void scenes::lobby::gui_server_list()
|
||||
if ((async_session.valid() || next_scene) and not ImGui::IsPopupOpen("", ImGuiPopupFlags_AnyPopup))
|
||||
ImGui::OpenPopup("connecting");
|
||||
|
||||
const auto & popup_layer = imgui_ctx->layers()[1];
|
||||
const glm::vec2 popup_layer_center = popup_layer.vp_origin + popup_layer.vp_size / 2;
|
||||
ImGui::SetNextWindowPos({popup_layer_center.x, popup_layer_center.y}, ImGuiCond_Always, ImVec2(0.5f, 0.5f));
|
||||
const ImVec2 popup_center = imgui_ctx->layers()[1].vp_center();
|
||||
ImGui::SetNextWindowPos(popup_center, ImGuiCond_Always, {0.5f, 0.5f});
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, constants::style::window_padding);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, constants::style::window_rounding);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, constants::style::window_border_size);
|
||||
@@ -530,7 +522,7 @@ void scenes::lobby::gui_server_list()
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
|
||||
ImGui::SetNextWindowPos({popup_layer_center.x, popup_layer_center.y}, ImGuiCond_Always, ImVec2(0.5f, 0.5f));
|
||||
ImGui::SetNextWindowPos(popup_center, ImGuiCond_Always, {0.5f, 0.5f});
|
||||
if (ImGui::BeginPopupModal("disconnected", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_AlwaysAutoResize))
|
||||
{
|
||||
gui_disconnected();
|
||||
@@ -935,8 +927,7 @@ void scenes::lobby::gui_licenses()
|
||||
for (const auto & c: components)
|
||||
items.push_back({c.c_str()});
|
||||
|
||||
const float control_w = 480;
|
||||
if (ui::combo("##component", _("Component"), items, &selected, control_w) or not license)
|
||||
if (ui::combo("##component", _("Component"), items, &selected, ui::metrics::setting_control_width) or not license)
|
||||
{
|
||||
selected_item = components[selected];
|
||||
try
|
||||
@@ -952,7 +943,7 @@ void scenes::lobby::gui_licenses()
|
||||
|
||||
if (license)
|
||||
{
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, {12, 10});
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ui::metrics::card_item_spacing);
|
||||
ui::begin_card("##license_text");
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, t.text_muted);
|
||||
ImGui::TextUnformatted((const char *)license->data(), (const char *)license->data() + license->size());
|
||||
@@ -1058,8 +1049,7 @@ std::vector<std::pair<int, XrCompositionLayerQuad>> scenes::lobby::draw_gui(XrTi
|
||||
|
||||
// combo modals open centred on the popup layer
|
||||
const auto & ui_popup_layer = imgui_ctx->layers()[1];
|
||||
const glm::vec2 ui_popup_center = ui_popup_layer.vp_origin + ui_popup_layer.vp_size / 2;
|
||||
wivrn::ui::set_popup_center({ui_popup_center.x, ui_popup_center.y}, float(ui_popup_layer.vp_size.y));
|
||||
wivrn::ui::set_popup_center(ui_popup_layer.vp_center(), float(ui_popup_layer.vp_size.y));
|
||||
|
||||
// let the themed widgets fire the hover haptic and show tooltips
|
||||
wivrn::ui::set_hover_haptic([this] { imgui_ctx->vibrate_on_hover(); });
|
||||
|
||||
@@ -422,17 +422,15 @@ scenes::lobby::environment_item_action scenes::lobby::environment_item(environme
|
||||
const bool transferring = handle and handle->get_state() == libcurl::state::transferring;
|
||||
|
||||
// measure the trailing control so the row body click area can exclude it
|
||||
const std::string active_l = std::string(ICON_FA_CHECK " ") + _("Active");
|
||||
const ImVec2 active_ts = ImGui::CalcTextSize(active_l.c_str());
|
||||
const float active_w = active_ts.x + ui::metrics::chip_padding.x * 2;
|
||||
const std::string active_l = ui::icon_label(ICON_FA_CHECK, _("Active"));
|
||||
const ImVec2 active_sz = ui::chip_size(active_l);
|
||||
float trailing = 0;
|
||||
if (selected)
|
||||
trailing = active_w + ui::metrics::list_row_pad;
|
||||
trailing = active_sz.x + ui::metrics::list_row_pad;
|
||||
else if (transferring or (local and not model.builtin))
|
||||
trailing = bh + ui::metrics::list_row_pad;
|
||||
|
||||
const auto row = ui::begin_list_row("##env", icon, model.screenshot, title, subtitle, selected, trailing);
|
||||
const float row_h = row.max.y - row.min.y;
|
||||
if (row.clicked and not selected)
|
||||
action = local ? environment_item_action::use_model : environment_item_action::download_model;
|
||||
|
||||
@@ -440,19 +438,18 @@ scenes::lobby::environment_item_action scenes::lobby::environment_item(environme
|
||||
|
||||
if (selected)
|
||||
{
|
||||
const float ch = active_ts.y + ui::metrics::chip_padding.y * 2;
|
||||
ImGui::SetCursorScreenPos({x - active_w, row.min.y + (row_h - ch) * 0.5f});
|
||||
ImGui::SetCursorScreenPos(row.trailing(x, active_sz));
|
||||
ui::chip(active_l, ui::chip_style::success);
|
||||
}
|
||||
else if (transferring)
|
||||
{
|
||||
ImGui::SetCursorScreenPos({x - bh, row.min.y + (row_h - bh) * 0.5f});
|
||||
ImGui::SetCursorScreenPos(row.trailing(x, {bh, bh}));
|
||||
if (ui::icon_button(ICON_FA_STOP, {bh, bh}, false, _S("Cancel")))
|
||||
handle->cancel();
|
||||
}
|
||||
else if (local and not model.builtin)
|
||||
{
|
||||
ImGui::SetCursorScreenPos({x - bh, row.min.y + (row_h - bh) * 0.5f});
|
||||
ImGui::SetCursorScreenPos(row.trailing(x, {bh, bh}));
|
||||
if (ui::icon_button(ICON_FA_TRASH, {bh, bh}, false, _S("Delete this model")))
|
||||
action = environment_item_action::delete_model;
|
||||
}
|
||||
@@ -533,9 +530,7 @@ void scenes::lobby::popup_load_environment(XrTime predicted_display_time)
|
||||
ImGui::OpenPopup("loading environment model");
|
||||
}
|
||||
|
||||
const auto & popup_layer = imgui_ctx->layers()[1];
|
||||
const glm::vec2 popup_layer_center = popup_layer.vp_origin + popup_layer.vp_size / 2;
|
||||
ImGui::SetNextWindowPos({popup_layer_center.x, popup_layer_center.y}, ImGuiCond_Always, ImVec2(0.5f, 0.5f));
|
||||
ImGui::SetNextWindowPos(imgui_ctx->layers()[1].vp_center(), ImGuiCond_Always, {0.5f, 0.5f});
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, constants::style::window_padding);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, constants::style::window_rounding);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, constants::style::window_border_size);
|
||||
@@ -653,7 +648,7 @@ void scenes::lobby::gui_customize(XrTime predicted_display_time)
|
||||
|
||||
ui::page_header(_S("Environment"), _S("Choose the environment your panels float in."));
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, {12, 10});
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ui::metrics::card_item_spacing);
|
||||
|
||||
ui::begin_card("##environments");
|
||||
environment_list(local_environments, false);
|
||||
@@ -663,11 +658,10 @@ void scenes::lobby::gui_customize(XrTime predicted_display_time)
|
||||
ui::begin_card("##get_more");
|
||||
{
|
||||
const float bh = ImGui::GetFrameHeight() * ui::metrics::control_height;
|
||||
const std::string browse = std::string(ICON_FA_UP_RIGHT_FROM_SQUARE " ") + _("Browse");
|
||||
const float bw = ImGui::CalcTextSize(browse.c_str()).x + ui::metrics::button_padding.x * 2;
|
||||
const std::string browse = ui::icon_label(ICON_FA_UP_RIGHT_FROM_SQUARE, _("Browse"));
|
||||
const float bw = ui::button_width(browse);
|
||||
const auto row = ui::begin_list_row("##getmore", ICON_FA_IMAGES, 0, _S("Get more environments"), _S("Download community-made spaces from the WiVRn dashboard on your PC."), false, bw + ui::metrics::list_row_pad);
|
||||
const float row_h = row.max.y - row.min.y;
|
||||
ImGui::SetCursorScreenPos({row.max.x - bw, row.min.y + (row_h - bh) * 0.5f});
|
||||
ImGui::SetCursorScreenPos(row.trailing(row.max.x, {bw, bh}));
|
||||
if (ui::button(browse, ui::button_style::secondary, {bw, 0}))
|
||||
{
|
||||
download_environment_list();
|
||||
@@ -680,9 +674,7 @@ void scenes::lobby::gui_customize(XrTime predicted_display_time)
|
||||
if (ui::button(_S("Open local glTF model"), ui::button_style::secondary))
|
||||
lobby_file_picker_future = lobby_file_picker.open();
|
||||
|
||||
const auto & popup_layer = imgui_ctx->layers()[1];
|
||||
const glm::vec2 popup_layer_center = popup_layer.vp_origin + popup_layer.vp_size / 2;
|
||||
ImGui::SetNextWindowPos({popup_layer_center.x, popup_layer_center.y}, ImGuiCond_Always, ImVec2(0.5f, 0.5f));
|
||||
ImGui::SetNextWindowPos(imgui_ctx->layers()[1].vp_center(), ImGuiCond_Always, {0.5f, 0.5f});
|
||||
ImGui::SetNextWindowSize({1200, 900});
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, constants::style::window_rounding);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, constants::style::window_border_size);
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace ui = wivrn::ui;
|
||||
|
||||
namespace
|
||||
{
|
||||
constexpr float control_w = 480;
|
||||
constexpr float control_w = ui::metrics::setting_control_width;
|
||||
|
||||
enum class ui_kind
|
||||
{
|
||||
@@ -95,7 +95,7 @@ struct setting
|
||||
|
||||
void render_settings(const char * card_id, const std::vector<setting> & list)
|
||||
{
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, {12, 10});
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ui::metrics::card_item_spacing);
|
||||
ui::begin_card(card_id);
|
||||
|
||||
for (const auto & s: list)
|
||||
|
||||
@@ -38,8 +38,8 @@ void scenes::lobby::gui_theme()
|
||||
|
||||
ui::page_header(_S("Theme"), _S("Accent color, palette and sizing of the interface."));
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, {12, 10});
|
||||
const float control_w = 480;
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ui::metrics::card_item_spacing);
|
||||
const float control_w = ui::metrics::setting_control_width;
|
||||
|
||||
ui::begin_card("##theme");
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user