Ui improvements

This commit is contained in:
ahsanswr
2026-07-26 17:24:36 +02:00
committed by Guillaume Meunier
parent 4226485c57
commit 2e9f2c8646
21 changed files with 1560 additions and 1026 deletions
+5 -5
View File
@@ -1261,20 +1261,20 @@ imgui_context::viewport & imgui_context::layer(ImVec2 position)
return layers_.front();
}
void imgui_context::tooltip(std::string_view text)
void imgui_context::tooltip(std::string_view text, std::optional<ImVec2> anchor)
{
// FIXME: this is incorrect if we use the docking branch of imgui
ImGuiViewport * viewport = ImGui::GetMainViewport();
auto & current_layer = layer(ImGui::GetMousePos());
auto & current_layer = layer(anchor.value_or(ImGui::GetMousePos()));
assert(std::ranges::contains(layers_, true, &viewport::tooltip_viewport));
auto & tooltip_layer = *std::ranges::find(layers_, true, &viewport::tooltip_viewport);
// Get the item position before drawing the tooltip (top center)
ImVec2 item_position{
// Anchor above the given display point, or above the last item's rect (top center)
ImVec2 item_position = anchor.value_or(ImVec2{
(ImGui::GetItemRectMin().x + ImGui::GetItemRectMax().x) / 2,
ImGui::GetItemRectMin().y,
};
});
auto pos_backup = viewport->Pos;
auto size_backup = viewport->Size;
+3 -1
View File
@@ -251,7 +251,9 @@ public:
void vibrate_on_hover();
void set_hovered_item();
void set_controllers_enabled(bool value);
void tooltip(std::string_view text);
// anchor, if set, positions the tooltip above that display point (e.g. the mouse)
// instead of above the last item's rect
void tooltip(std::string_view text, std::optional<ImVec2> anchor = std::nullopt);
std::array<bool, 2> is_aim_interaction() const
{
return {aim_interaction[0] == 1, aim_interaction[1] == 1};
+7 -2
View File
@@ -56,8 +56,7 @@ static theme dark_default()
t.rounding = 8;
t.card_rounding = 14;
t.border_size = 1;
t.font_scale = 1.0; // user multiplier; 100% maps to metrics::font_base
t.background_alpha = 1.0f; // fully opaque panel by default
t.font_scale = 1.0; // user multiplier; 100% maps to metrics::font_base
return t;
}
@@ -176,6 +175,12 @@ void set_theme(const theme & t)
current() = t;
}
float & background_alpha()
{
static float alpha = 0.90f; // translucent panels by default
return alpha;
}
void theme::apply() const
{
ImGuiStyle & style = ImGui::GetStyle();
+21 -2
View File
@@ -60,8 +60,7 @@ struct theme
float card_rounding; // cards
float border_size;
float font_scale; // global text size multiplier
float background_alpha; // opacity of the main panel background, 0..1
float font_scale; // global text size multiplier
// Convert to packed color, applying the current global alpha so widgets drawn
// through the draw list dim with ImGui::BeginDisabled() (and any pushed alpha).
@@ -120,12 +119,32 @@ constexpr float nav_section_gap = 18; // space above a sidebar section header
constexpr ImVec2 card_item_spacing = {12, 10}; // ItemSpacing pushed around a card section
constexpr float setting_control_width = 480; // width of the control in a setting row
// Application shell (top bar + navigation sidebar + content panel), shared by the lobby
// and the in-stream window
constexpr float sidebar_width = 300;
constexpr float top_bar_height = 72;
constexpr float content_margin = 20; // gap around the main content panel
// Application launcher grid
constexpr float app_icon_small = 120;
constexpr float app_icon_medium = 176;
constexpr float app_icon_large = 240;
constexpr float app_tile_margin = 24; // horizontal slack each side of the icon in a tile
constexpr float app_view_toggle_width = 150; // grid/list segmented control
constexpr float app_size_toggle_width = 300; // small/medium/large segmented control
constexpr float app_spinner_radius = 110; // app-starting spinner
constexpr float app_spinner_thickness = 22;
} // namespace metrics
// Theme in effect, call current().apply() after mutating
theme & current();
void set_theme(const theme & t);
// Opacity of the panel and card backgrounds, 0..1. Kept separate from the theme
// presets so switching palette never resets the user's transparency.
float & background_alpha();
std::vector<theme> presets();
struct accent_swatch
+86 -4
View File
@@ -119,7 +119,7 @@ bool begin_card_impl(const char * id, ImVec2 padding)
{
const ImVec2 bb_max = {cf.origin.x + cf.width, cf.origin.y + h};
ImVec4 card = t.card;
card.w *= t.background_alpha; // card fill follows the panel opacity
card.w *= background_alpha(); // card fill follows the panel opacity
window->DrawList->AddRectFilled(cf.origin, bb_max, t.col(card), t.card_rounding);
if (t.border_size > 0)
window->DrawList->AddRect(cf.origin, bb_max, t.col(t.border), t.card_rounding, 0, t.border_size);
@@ -169,7 +169,7 @@ void row_separator()
{
const theme & t = current();
ImVec4 edge = t.border;
edge.w *= t.background_alpha; // match the panel/card opacity
edge.w *= background_alpha(); // match the panel/card opacity
ImGui::PushStyleColor(ImGuiCol_Separator, edge);
ImGui::Separator();
ImGui::PopStyleColor();
@@ -267,6 +267,16 @@ ImVec2 chip_size(const std::string & label)
return {ts.x + metrics::chip_padding.x * 2, ts.y + metrics::chip_padding.y * 2};
}
float chip_width(const std::string & label, bool dot, float height)
{
// mirrors the footprint computed in chip()
const ImVec2 ts = ImGui::CalcTextSize(label.c_str());
const float pad_x = height > 0 ? metrics::chip_pill_padding_x : metrics::chip_padding.x;
const float dot_r = ts.y * 0.26f;
const float dot_gap = dot ? dot_r * 2 + pad_x * 0.55f : 0;
return ts.x + pad_x * 2 + dot_gap;
}
bool button(const std::string & label, button_style s, const ImVec2 & size)
{
const theme & t = current();
@@ -688,7 +698,7 @@ ImVec2 popup_center = {0, 0};
float popup_available_height = 0;
// One selectable option inside the combo modal. A tall, full-width touch target
// with the name (accent when selected) and an optional muted description.
// with the name and an optional muted description.
bool combo_row(const combo_item & item, bool selected)
{
ImGuiWindow * window = ImGui::GetCurrentWindow();
@@ -719,7 +729,7 @@ bool combo_row(const combo_item & item, bool selected)
draw->AddRectFilled(bb.Min, {bb.Min.x + metrics::combo_padding.x * 0.25f, bb.Max.y}, t.col(t.accent), t.rounding, ImDrawFlags_RoundCornersLeft);
const float tx = bb.Min.x + metrics::combo_padding.x;
const ImU32 name_col = t.col(selected ? t.accent : t.text);
const ImU32 name_col = t.col(t.text);
const ImVec2 nts = ImGui::CalcTextSize(item.name);
if (item.description and item.description[0])
@@ -1330,4 +1340,76 @@ int action_menu(const char * id, const char * icon, const std::vector<action_ite
return chosen;
}
void top_bar(float height, ImTextureID logo, const std::vector<top_bar_item> & right_items)
{
const float side = ImGui::GetFrameHeight() * metrics::control_height;
const float gap = 8;
const float margin = 24;
// transparent child bg so the alpha-blended window background shows through
ImGui::SetCursorPos({0, 0});
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4{0, 0, 0, 0});
ImGui::BeginChild("TopBar", {ImGui::GetWindowSize().x, height}, 0, ImGuiWindowFlags_NoScrollbar);
{
// logo: WiVRn mascot followed by the wordmark
const float logo_size = 44;
ImGui::SetCursorPos({margin, (height - logo_size) * 0.5f});
if (logo)
ImGui::Image(logo, {logo_size, logo_size});
ImGui::SameLine(0, 12);
ImGui::PushFont(nullptr, ImGui::GetStyle().FontSizeBase * 1.3f);
ImGui::SetCursorPosY((height - ImGui::GetFontSize()) * 0.5f);
ImGui::TextUnformatted("WiVRn");
ImGui::PopFont();
// right-aligned cluster
float cluster_w = 0;
for (const auto & it: right_items)
cluster_w += it.width;
if (not right_items.empty())
cluster_w += gap * (right_items.size() - 1);
ImGui::SetCursorPos({ImGui::GetWindowSize().x - margin - cluster_w, (height - side) * 0.5f});
for (size_t i = 0; i < right_items.size(); ++i)
{
ImGui::SetCursorPosY((height - side) * 0.5f);
right_items[i].draw();
if (i + 1 < right_items.size())
ImGui::SameLine(0, gap);
}
}
ImGui::EndChild();
ImGui::PopStyleColor();
}
void begin_sidebar(float top_bar_h, float tab_width)
{
// shares the transparent window background; sections separated by shell_dividers
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4{0, 0, 0, 0});
ImGui::SetCursorPos({0, top_bar_h});
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, {16, 16});
ImGui::BeginChild("Tabs", {tab_width, ImGui::GetWindowSize().y - top_bar_h}, ImGuiChildFlags_AlwaysUseWindowPadding);
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, {0, 4});
}
void end_sidebar()
{
ImGui::PopStyleVar(); // ImGuiStyleVar_ItemSpacing
ImGui::EndChild();
ImGui::PopStyleVar(); // ImGuiStyleVar_WindowPadding
ImGui::PopStyleColor(); // ImGuiCol_ChildBg
}
void shell_dividers(float top_bar_h, float tab_width)
{
ImVec4 divider_col = current().border;
divider_col.w *= background_alpha(); // follow the panel opacity
const ImU32 divider = ImGui::GetColorU32(divider_col);
const ImVec2 win_pos = ImGui::GetWindowPos();
const ImVec2 win_size = ImGui::GetWindowSize();
ImDrawList * dl = ImGui::GetWindowDrawList();
dl->AddLine({win_pos.x, win_pos.y + top_bar_h}, {win_pos.x + win_size.x, win_pos.y + top_bar_h}, divider);
dl->AddLine({win_pos.x + tab_width, win_pos.y + top_bar_h}, {win_pos.x + tab_width, win_pos.y + win_size.y}, divider);
}
} // namespace wivrn::ui
+28
View File
@@ -67,6 +67,10 @@ 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);
// Exact layout width of a chip(), accounting for the optional status dot and the roomier
// padding used when height > 0 (the tall pill chips in the top bar).
float chip_width(const std::string & label, bool dot = false, float height = 0);
bool button(const std::string & label, button_style style = button_style::primary, const ImVec2 & size = {0, 0});
// Same, with a larger leading icon glyph drawn before the label
bool button(const char * icon, const std::string & label, button_style style = button_style::primary, const ImVec2 & size = {0, 0});
@@ -179,4 +183,28 @@ void end_list_row();
// cancelled or dismissed, 0 otherwise. danger styles the confirm button as destructive.
int confirm_modal(const char * id, const std::string & title, const std::string & message, const std::string & confirm_label, const std::string & cancel_label, bool danger = false);
// --- Shared window shell: top bar, sidebar and dividers used by the lobby and the
// in-stream GUI so the two screens stay identical. Call inside the main window.
// One slot in the top bar's right-aligned cluster. width is the slot's layout width
// (use chip_width() for chips, the control side for icon buttons); draw() renders it at
// the cursor, vertically centred, at the standard control height.
struct top_bar_item
{
float width;
std::function<void()> draw;
};
// Top bar: WiVRn logo + wordmark on the left, right_items right-aligned. Manages its own
// child window; height is the bar height in pixels.
void top_bar(float height, ImTextureID logo, const std::vector<top_bar_item> & right_items);
// Sidebar nav frame at the standard width/offset. Fill with nav_section()/nav_item()
// between the calls; pair begin_sidebar with end_sidebar.
void begin_sidebar(float top_bar_h, float tab_width);
void end_sidebar();
// Hairline dividers separating the top bar, sidebar and content, dimmed with the panel.
void shell_dividers(float top_bar_h, float tab_width);
} // namespace wivrn::ui