Ui improvements
This commit is contained in:
committed by
Guillaume Meunier
parent
4226485c57
commit
2e9f2c8646
@@ -60,6 +60,14 @@ const std::vector<config_field> & scalar_fields()
|
||||
{"resolution_scale", &configuration::resolution_scale},
|
||||
{"bitrate_bps", &configuration::bitrate_bps},
|
||||
{"enable_stream_gui", &configuration::enable_stream_gui},
|
||||
{"app_list_view", &configuration::app_list_view},
|
||||
{"app_icon_size", &configuration::app_icon_size},
|
||||
{"theme_preset", &configuration::theme_preset},
|
||||
{"theme_accent", &configuration::theme_accent},
|
||||
{"theme_rounding", &configuration::theme_rounding},
|
||||
{"theme_card_rounding", &configuration::theme_card_rounding},
|
||||
{"theme_font_scale", &configuration::theme_font_scale},
|
||||
{"theme_background_alpha", &configuration::theme_background_alpha},
|
||||
{"passthrough_enabled", &configuration::passthrough_enabled},
|
||||
{"mic_unprocessed_audio", &configuration::mic_unprocessed_audio},
|
||||
{"forward_keyboard", &configuration::forward_keyboard},
|
||||
|
||||
@@ -78,6 +78,18 @@ public:
|
||||
|
||||
bool enable_stream_gui = true;
|
||||
|
||||
// application launcher: list vs grid, and grid icon size, 0 small 1 medium 2 large
|
||||
bool app_list_view = false;
|
||||
uint32_t app_icon_size = 1;
|
||||
|
||||
// Interface theme; defaults match the built-in "Dark" preset / "Blue" accent
|
||||
std::string theme_preset = "Dark";
|
||||
std::string theme_accent = "Blue";
|
||||
float theme_rounding = 8;
|
||||
float theme_card_rounding = 14;
|
||||
float theme_font_scale = 1.0;
|
||||
float theme_background_alpha = 0.75;
|
||||
|
||||
// XR_FB_composition_layer_settings extension flags
|
||||
struct openxr_post_processing_settings
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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};
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
+165
-142
@@ -20,74 +20,82 @@
|
||||
#define IMGUI_DEFINE_MATH_OPERATORS
|
||||
#include "app_launcher.h"
|
||||
|
||||
#include "constants.h"
|
||||
#include "application.h"
|
||||
#include "configuration.h"
|
||||
#include "imgui.h"
|
||||
#include "imgui_internal.h"
|
||||
#include "render/ui_theme.h"
|
||||
#include "render/ui_widgets.h"
|
||||
#include "scenes/stream.h"
|
||||
#include "utils/i18n.h"
|
||||
#include "utils/ranges.h"
|
||||
|
||||
#include <IconsFontAwesome6.h>
|
||||
#include <algorithm>
|
||||
#include <imspinner.h>
|
||||
#include <spdlog/fmt/fmt.h>
|
||||
#include <uni_algo/case.h>
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
// Display a button with an image and a text centred horizontally
|
||||
static bool icon(
|
||||
const std::string & text,
|
||||
ImTextureRef tex_ref,
|
||||
const ImVec2 & image_size,
|
||||
ImGuiButtonFlags flags = 0,
|
||||
const ImVec2 & size_arg = ImVec2(0, 0),
|
||||
const ImVec2 & uv0 = ImVec2(0, 0),
|
||||
const ImVec2 & uv1 = ImVec2(1, 1),
|
||||
const ImVec4 & tint_col = ImVec4(1, 1, 1, 1))
|
||||
namespace ui = wivrn::ui;
|
||||
|
||||
namespace
|
||||
{
|
||||
// Based on ImGui::ButtonEx and ImGui::ImageButtonEx
|
||||
ImGuiWindow * window = ImGui::GetCurrentWindow();
|
||||
// grid icon image size for the small/medium/large setting
|
||||
float grid_image_size(uint32_t size)
|
||||
{
|
||||
switch (size)
|
||||
{
|
||||
case 0:
|
||||
return ui::metrics::app_icon_small;
|
||||
case 2:
|
||||
return ui::metrics::app_icon_large;
|
||||
default:
|
||||
return ui::metrics::app_icon_medium;
|
||||
}
|
||||
}
|
||||
|
||||
// Themed grid tile: image with a centred label below, control surface, accent on hover
|
||||
bool app_tile(const std::string & id, const std::string & name, ImTextureID texture, float tile_w, float image_size)
|
||||
{
|
||||
const ui::theme & t = ui::current();
|
||||
const ImGuiStyle & style = ImGui::GetStyle();
|
||||
ImGuiWindow * window = ImGui::GetCurrentWindow();
|
||||
|
||||
if (window->SkipItems)
|
||||
return false;
|
||||
|
||||
const ImVec2 label_size = ImGui::CalcTextSize(text.c_str(), nullptr, true);
|
||||
|
||||
ImVec2 size = ImGui::CalcItemSize(
|
||||
size_arg,
|
||||
std::max(image_size.x, label_size.x) + style.FramePadding.x * 2.0f,
|
||||
image_size.y + style.ItemInnerSpacing.y + label_size.y + style.FramePadding.y * 2.0f);
|
||||
|
||||
const float pad = ui::metrics::list_row_pad;
|
||||
const ImVec2 size{tile_w, image_size + pad * 2 + style.ItemInnerSpacing.y + ImGui::GetTextLineHeight()};
|
||||
const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + size);
|
||||
|
||||
ImRect image_pos(
|
||||
{(bb.Min.x + bb.Max.x - image_size.x) / 2, bb.Min.y + style.FramePadding.y},
|
||||
{(bb.Min.x + bb.Max.x + image_size.x) / 2, bb.Min.y + style.FramePadding.y + image_size.y});
|
||||
|
||||
ImRect label_pos(
|
||||
{bb.Min.x + style.FramePadding.x, image_pos.Max.y + style.ItemInnerSpacing.y},
|
||||
{bb.Max.x - style.FramePadding.x, bb.Max.y - style.FramePadding.y});
|
||||
|
||||
ImGui::ItemSize(bb);
|
||||
|
||||
ImGuiID id = window->GetID(text.c_str());
|
||||
if (!ImGui::ItemAdd(bb, id))
|
||||
const ImGuiID iid = window->GetID(id.c_str());
|
||||
if (not ImGui::ItemAdd(bb, iid))
|
||||
return false;
|
||||
|
||||
bool hovered, held;
|
||||
bool pressed = ImGui::ButtonBehavior(bb, id, &hovered, &held, flags);
|
||||
const bool pressed = ImGui::ButtonBehavior(bb, iid, &hovered, &held, ImGuiButtonFlags_PressedOnClickRelease);
|
||||
|
||||
// Render
|
||||
const ImU32 col = ImGui::GetColorU32((held && hovered) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered
|
||||
: ImGuiCol_Button);
|
||||
ImGui::RenderNavCursor(bb, id);
|
||||
ImGui::RenderFrame(bb.Min, bb.Max, col, true, style.FrameRounding);
|
||||
ImDrawList * dl = window->DrawList;
|
||||
dl->AddRectFilled(bb.Min, bb.Max, t.col(held and hovered ? t.control_active : hovered ? t.card_hovered
|
||||
: t.control),
|
||||
t.card_rounding);
|
||||
if (hovered)
|
||||
dl->AddRect(bb.Min, bb.Max, t.col(t.accent), t.card_rounding, 0, t.border_size * 2);
|
||||
|
||||
window->DrawList->AddImage(tex_ref, image_pos.Min, image_pos.Max, uv0, uv1, ImGui::GetColorU32(tint_col));
|
||||
ImGui::RenderTextClipped(label_pos.Min, label_pos.Max, text.c_str(), NULL, &label_size, style.ButtonTextAlign, &bb);
|
||||
const ImVec2 image_min{(bb.Min.x + bb.Max.x - image_size) / 2, bb.Min.y + pad};
|
||||
dl->AddImage(texture, image_min, image_min + ImVec2{image_size, image_size});
|
||||
|
||||
const ImVec2 label_min{bb.Min.x + pad, image_min.y + image_size + style.ItemInnerSpacing.y};
|
||||
const ImVec2 label_max{bb.Max.x - pad, bb.Max.y - pad};
|
||||
const ImVec2 label_size = ImGui::CalcTextSize(name.c_str(), nullptr, true);
|
||||
ImGui::RenderTextClipped(label_min, label_max, name.c_str(), nullptr, &label_size, {0.5f, 0.5f}, &bb);
|
||||
|
||||
return pressed;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
app_launcher::app_launcher(
|
||||
scenes::stream & stream,
|
||||
@@ -105,139 +113,154 @@ app_launcher::app_launcher(
|
||||
|
||||
app_launcher::clicked app_launcher::draw_gui(imgui_context & imgui_ctx, const std::string & cancel)
|
||||
{
|
||||
auto & config = application::get_config();
|
||||
|
||||
auto res = clicked::None;
|
||||
auto t0 = std::chrono::steady_clock::now();
|
||||
bool app_starting = start_time != std::chrono::steady_clock::time_point{} and
|
||||
t0 - start_time < 10s;
|
||||
|
||||
auto cancel_size = ImGui::CalcTextSize(cancel.c_str());
|
||||
|
||||
auto apps = applications.lock();
|
||||
|
||||
ImGui::PushFont(nullptr, constants::gui::font_size_large);
|
||||
if (server_name.empty())
|
||||
CenterTextH(_("Connected to WiVRn server"));
|
||||
else
|
||||
CenterTextH(fmt::format(_F("Connected to {}"), server_name));
|
||||
ImGui::PopFont();
|
||||
// resolve an app's icon, uploading lazily and capped per frame to stay responsive
|
||||
auto texture_for = [&](app & a) -> ImTextureID {
|
||||
if (a.image.empty())
|
||||
return default_icon;
|
||||
auto it = app_icons.find(a.id);
|
||||
if (it == app_icons.end())
|
||||
{
|
||||
if (std::chrono::steady_clock::now() - t0 > 10ms)
|
||||
return default_icon;
|
||||
try
|
||||
{
|
||||
it = app_icons.emplace(a.id, textures.load_texture(a.image)).first;
|
||||
}
|
||||
catch (std::exception & e)
|
||||
{
|
||||
spdlog::warn("Unable to load icon for \"{}\": {}", a.id, e.what());
|
||||
a.image.clear();
|
||||
return default_icon;
|
||||
}
|
||||
}
|
||||
return it->second;
|
||||
};
|
||||
|
||||
auto launch = [&](const std::string & id) {
|
||||
res = clicked::Start;
|
||||
start_time = t0;
|
||||
stream.start_application(id);
|
||||
};
|
||||
|
||||
const float margin = ui::metrics::card_padding.x;
|
||||
const float button_h = ImGui::GetFrameHeight() * ui::metrics::control_height;
|
||||
const float footer_h = button_h + margin * 2;
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ui::metrics::card_padding);
|
||||
ImGui::BeginChild("launcher", {0, ImGui::GetContentRegionAvail().y - footer_h}, ImGuiChildFlags_AlwaysUseWindowPadding);
|
||||
ImGui::BeginDisabled(app_starting);
|
||||
|
||||
const float header_top = ImGui::GetCursorPosY();
|
||||
const std::string subtitle = _S("Pick an application to start streaming, or start one on the PC.");
|
||||
if (server_name.empty())
|
||||
ui::page_header(_S("Connected"), subtitle);
|
||||
else
|
||||
ui::page_header(fmt::format(_F("Connected to {}"), server_name), subtitle);
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, {20, 20});
|
||||
if (apps->empty())
|
||||
{
|
||||
CenterTextHV(_("Start an application on the server to start streaming."));
|
||||
ImGui::Spacing();
|
||||
ImGui::TextUnformatted(_S("Waiting for an application on the server"));
|
||||
}
|
||||
else
|
||||
{
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, {20, 0});
|
||||
ImGui::BeginDisabled(app_starting);
|
||||
ImGui::BeginChild("Main", ImGui::GetWindowSize() - ImGui::GetCursorPos() - ImVec2(0, cancel_size.y + 80), 0, app_starting ? ImGuiWindowFlags_NoScrollWithMouse : 0);
|
||||
const float content_y = ImGui::GetCursorPosY();
|
||||
|
||||
ImGui::Indent(20);
|
||||
if (server_name.empty())
|
||||
ImGui::Text("%s", _S("Start an application on your computer or select one to start streaming."));
|
||||
else
|
||||
ImGui::Text("%s", fmt::format(_F("Start an application on {} or select one to start streaming."), server_name).c_str());
|
||||
ImGui::Unindent();
|
||||
int view = config.app_list_view ? 1 : 0;
|
||||
int size_idx = std::clamp<int>(config.app_icon_size, 0, 2);
|
||||
const std::vector<std::string> size_opts = {_S("Small"), _S("Medium"), _S("Large")};
|
||||
const std::vector<std::string> view_opts = {ICON_FA_TABLE_CELLS_LARGE, ICON_FA_LIST};
|
||||
const float gap = ImGui::GetStyle().ItemSpacing.x;
|
||||
const float view_w = ui::metrics::app_view_toggle_width;
|
||||
const float size_w = ui::metrics::app_size_toggle_width;
|
||||
const float cluster = view_w + (view == 0 ? size_w + gap : 0);
|
||||
|
||||
float icon_width = 400;
|
||||
float icon_spacing = ImGui::GetStyle().ItemSpacing.x;
|
||||
float usable_window_width = ImGui::GetWindowSize().x - ImGui::GetCurrentWindow()->ScrollbarSizes.x;
|
||||
|
||||
int icons_per_line = (usable_window_width + icon_spacing) / (icon_width + icon_spacing);
|
||||
float icon_line_width = icons_per_line * icon_width + (icons_per_line - 1) * icon_spacing;
|
||||
|
||||
ImGui::Indent((usable_window_width - icon_line_width) / 2);
|
||||
|
||||
for (const auto [index, app]: utils::enumerate(*apps))
|
||||
// grid/list and icon size on the title row, right-aligned and centred against the title
|
||||
ImGui::PushFont(nullptr, ImGui::GetStyle().FontSizeBase * ui::metrics::font_title);
|
||||
const float title_h = ImGui::GetFontSize();
|
||||
ImGui::PopFont();
|
||||
const float toggle_h = ImGui::GetFrameHeight() * ui::metrics::control_height;
|
||||
ImGui::SetCursorPos({ImGui::GetContentRegionMax().x - cluster, header_top + (title_h - toggle_h) / 2});
|
||||
if (view == 0)
|
||||
{
|
||||
ImTextureID texture = [&]() -> ImTextureID {
|
||||
if (app.image.empty())
|
||||
return default_icon;
|
||||
else
|
||||
{
|
||||
auto it = app_icons.find(app.id);
|
||||
if (it == app_icons.end())
|
||||
{
|
||||
// Don't load too many textures at the same time to keep the GUI responsive
|
||||
if (std::chrono::steady_clock::now() - t0 > 10ms)
|
||||
return default_icon;
|
||||
|
||||
try
|
||||
{
|
||||
it = app_icons.emplace(app.id, textures.load_texture(app.image)).first;
|
||||
}
|
||||
catch (std::exception & e)
|
||||
{
|
||||
spdlog::warn("Unable to load icon for \"{}\": {}", app.id, e.what());
|
||||
|
||||
app.image.clear();
|
||||
return default_icon;
|
||||
}
|
||||
}
|
||||
return it->second;
|
||||
}
|
||||
}();
|
||||
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, 0);
|
||||
if (icon(app.name + "##" + app.id, texture, {256, 256}, ImGuiButtonFlags_PressedOnClickRelease, {icon_width, 0}))
|
||||
if (ui::segmented("##icon_size", size_opts, &size_idx, {size_w, 0}))
|
||||
{
|
||||
res = clicked::Start;
|
||||
start_time = t0;
|
||||
stream.start_application(app.id);
|
||||
config.app_icon_size = size_idx;
|
||||
config.save();
|
||||
}
|
||||
imgui_ctx.vibrate_on_hover();
|
||||
ImGui::PopStyleColor(); // ImGuiCol_Button
|
||||
|
||||
if ((index + 1) % icons_per_line)
|
||||
ImGui::SameLine();
|
||||
ImGui::SameLine(0, gap);
|
||||
}
|
||||
ImGui::Unindent();
|
||||
if (ui::segmented("##view_mode", view_opts, &view, {view_w, 0}))
|
||||
{
|
||||
config.app_list_view = view == 1;
|
||||
config.save();
|
||||
}
|
||||
ImGui::SetCursorPos({ImGui::GetCursorStartPos().x, content_y});
|
||||
|
||||
std::vector<std::pair<std::string, ImTextureID>> to_be_removed;
|
||||
if (config.app_list_view)
|
||||
{
|
||||
ui::begin_list_card("##apps");
|
||||
for (auto & app: *apps)
|
||||
{
|
||||
if (ui::begin_list_row(app.id.c_str(), nullptr, texture_for(app), app.name, "").clicked)
|
||||
launch(app.id);
|
||||
ui::end_list_row();
|
||||
}
|
||||
ui::end_card();
|
||||
}
|
||||
else
|
||||
{
|
||||
const float image_size = grid_image_size(config.app_icon_size);
|
||||
const float tile_w = image_size + ui::metrics::app_tile_margin * 2;
|
||||
const int per_line = std::max(1, int((ImGui::GetContentRegionAvail().x + gap) / (tile_w + gap)));
|
||||
for (const auto [index, app]: utils::enumerate(*apps))
|
||||
{
|
||||
if (app_tile(app.id, app.name, texture_for(app), tile_w, image_size))
|
||||
launch(app.id);
|
||||
imgui_ctx.vibrate_on_hover();
|
||||
if ((index + 1) % per_line)
|
||||
ImGui::SameLine();
|
||||
}
|
||||
}
|
||||
|
||||
// drop textures for apps no longer listed
|
||||
std::vector<std::string> stale;
|
||||
for (const auto & [app_id, app_icon]: app_icons)
|
||||
{
|
||||
if (not std::ranges::contains(*apps, app_id, &app::id))
|
||||
to_be_removed.emplace_back(app_id, app_icon);
|
||||
}
|
||||
for (const auto & [app_id, app_icon]: to_be_removed)
|
||||
stale.push_back(app_id);
|
||||
for (const auto & app_id: stale)
|
||||
{
|
||||
imgui_ctx.free_texture(app_icon);
|
||||
imgui_ctx.free_texture(app_icons.at(app_id));
|
||||
app_icons.erase(app_id);
|
||||
}
|
||||
|
||||
ScrollWhenDragging();
|
||||
ImGui::EndChild();
|
||||
ImGui::EndDisabled();
|
||||
|
||||
if (app_starting)
|
||||
{
|
||||
ImGui::SetCursorPos(ImGui::GetWindowSize() / 2 - ImVec2{200, 200} - ImGui::GetStyle().FramePadding);
|
||||
ImSpinner::SpinnerAng("App starting spinner",
|
||||
200, // Radius
|
||||
40, // Thickness
|
||||
ImColor{1.f, 1.f, 1.f, 1.f}, // Colour
|
||||
ImColor{1.f, 1.f, 1.f, 0.f}, // Background
|
||||
6, // Velocity
|
||||
0.75f * 2 * M_PI // Angle
|
||||
);
|
||||
}
|
||||
|
||||
ImGui::PopStyleVar(); // ImGuiStyleVar_WindowPadding
|
||||
}
|
||||
|
||||
ScrollWhenDragging();
|
||||
ImGui::EndDisabled();
|
||||
ImGui::EndChild();
|
||||
ImGui::PopStyleVar();
|
||||
|
||||
ImGui::SetCursorPos(ImGui::GetWindowSize() - cancel_size - ImVec2{50, 50});
|
||||
if (app_starting)
|
||||
{
|
||||
const float r = ui::metrics::app_spinner_radius;
|
||||
ImGui::SetCursorPos(ImGui::GetWindowSize() / 2 - ImVec2{r, r});
|
||||
ImSpinner::SpinnerAng("starting", r, ui::metrics::app_spinner_thickness, ImColor{ui::current().accent}, ImColor{ui::current().card}, 6, 0.75f * 2 * M_PI);
|
||||
}
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 10);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, {10, 10});
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.8f, 0.2f, 0.2f, 0.40f));
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.8f, 0.2f, 0.2f, 1.00f));
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(1.0f, 0.1f, 0.1f, 1.00f));
|
||||
if (ImGui::Button(cancel.c_str()))
|
||||
// footer: disconnect / cancel, bottom-right
|
||||
ImGui::SetCursorPos({ImGui::GetWindowSize().x - ui::button_width(cancel) - margin, ImGui::GetWindowSize().y - button_h - margin});
|
||||
if (ui::button(cancel, ui::button_style::danger))
|
||||
res = clicked::Cancel;
|
||||
imgui_ctx.vibrate_on_hover();
|
||||
ImGui::PopStyleColor(3); // ImGuiCol_Button, ImGuiCol_ButtonHovered, ImGuiCol_ButtonActive
|
||||
ImGui::PopStyleVar(2);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
#include "gui_common.h"
|
||||
|
||||
#include "android/battery.h"
|
||||
#include "application.h"
|
||||
#include "configuration.h"
|
||||
#include "constants.h"
|
||||
@@ -34,6 +35,8 @@
|
||||
|
||||
#include "imgui.h"
|
||||
#include "imgui_internal.h"
|
||||
#include <IconsFontAwesome6.h>
|
||||
#include <cmath>
|
||||
|
||||
namespace wivrn::gui
|
||||
{
|
||||
@@ -129,7 +132,8 @@ bool refresh_rate(
|
||||
bool body_tracking_parts(
|
||||
xr::system & system,
|
||||
imgui_context & imgui_ctx,
|
||||
configuration & config)
|
||||
configuration & config,
|
||||
bool in_game)
|
||||
{
|
||||
auto body_tracker = system.body_tracker_supported();
|
||||
if (body_tracker == xr::body_tracker_type::none or body_tracker == xr::body_tracker_type::htc)
|
||||
@@ -151,6 +155,7 @@ bool body_tracking_parts(
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, {12, 10});
|
||||
ui::begin_card("##body_tracking_parts");
|
||||
|
||||
ImGui::BeginDisabled(in_game);
|
||||
for (const auto & [bit, id, name]: body_parts)
|
||||
{
|
||||
if (body_tracker == xr::body_tracker_type::fb and bit > from_headset::body_part_mask::hip)
|
||||
@@ -176,6 +181,7 @@ bool body_tracking_parts(
|
||||
const float pad = std::max(label_bottom - ImGui::GetCursorPosY(), 0.f) + ui::metrics::label_bottom_pad;
|
||||
ImGui::Dummy({0, pad});
|
||||
}
|
||||
ImGui::EndDisabled();
|
||||
|
||||
ui::end_card();
|
||||
ImGui::PopStyleVar();
|
||||
@@ -264,4 +270,57 @@ bool post_processing(
|
||||
ImGui::Unindent();
|
||||
return changed;
|
||||
}
|
||||
|
||||
std::optional<battery_indicator> battery_status_indicator(XrTime now)
|
||||
{
|
||||
#ifdef __ANDROID__
|
||||
const auto battery = get_battery_status();
|
||||
if (not battery.charge)
|
||||
return std::nullopt;
|
||||
|
||||
const char * icon = ICON_FA_BATTERY_FULL;
|
||||
int icon_nr;
|
||||
if (battery.charging)
|
||||
icon_nr = *battery.charge > 0.995 ? 5 : now / 500'000'000 % 5;
|
||||
else
|
||||
icon_nr = std::round((*battery.charge) * 4);
|
||||
switch (icon_nr)
|
||||
{
|
||||
case 0:
|
||||
icon = ICON_FA_BATTERY_EMPTY;
|
||||
break;
|
||||
case 1:
|
||||
icon = ICON_FA_BATTERY_QUARTER;
|
||||
break;
|
||||
case 2:
|
||||
icon = ICON_FA_BATTERY_HALF;
|
||||
break;
|
||||
case 3:
|
||||
icon = ICON_FA_BATTERY_THREE_QUARTERS;
|
||||
break;
|
||||
case 4:
|
||||
icon = ICON_FA_BATTERY_FULL;
|
||||
break;
|
||||
case 5:
|
||||
icon = ICON_FA_PLUG;
|
||||
break;
|
||||
}
|
||||
|
||||
ui::chip_style style;
|
||||
if (*battery.charge < 0.2)
|
||||
style = ui::chip_style::danger;
|
||||
else if (*battery.charge < 0.5)
|
||||
style = ui::chip_style::warning;
|
||||
else
|
||||
style = ui::chip_style::success;
|
||||
|
||||
return battery_indicator{
|
||||
.label = fmt::format("{} {}%", icon, (int)std::round(*battery.charge * 100)),
|
||||
.style = style,
|
||||
};
|
||||
#else
|
||||
(void)now;
|
||||
return std::nullopt;
|
||||
#endif
|
||||
}
|
||||
} // namespace wivrn::gui
|
||||
|
||||
@@ -19,6 +19,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "render/ui_widgets.h"
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <openxr/openxr.h>
|
||||
|
||||
class configuration;
|
||||
class imgui_context;
|
||||
|
||||
@@ -44,7 +49,8 @@ bool refresh_rate(
|
||||
bool body_tracking_parts(
|
||||
xr::system & system,
|
||||
imgui_context & imgui_ctx,
|
||||
configuration & config);
|
||||
configuration & config,
|
||||
bool in_game);
|
||||
|
||||
bool post_processing(
|
||||
imgui_context & imgui_ctx,
|
||||
@@ -52,5 +58,16 @@ bool post_processing(
|
||||
|
||||
float toggle_width();
|
||||
|
||||
// Battery pill shown in the top bar: the icon+percent label and the 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.
|
||||
std::optional<battery_indicator> battery_status_indicator(XrTime now);
|
||||
|
||||
} // namespace gui
|
||||
} // namespace wivrn
|
||||
|
||||
@@ -0,0 +1,688 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2026 Guillaume Meunier <guillaume.meunier@centraliens.net>
|
||||
* Copyright (C) 2026 Patrick Nicolas <patricknicolas@laposte.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* 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.
|
||||
|
||||
#include "scenes/gui_common.h"
|
||||
#define IMGUI_DEFINE_MATH_OPERATORS
|
||||
|
||||
#include "gui_settings.h"
|
||||
|
||||
#include "application.h"
|
||||
#include "configuration.h"
|
||||
#include "decoder/decoder.h"
|
||||
#include "render/imgui_impl.h"
|
||||
#include "render/ui_theme.h"
|
||||
#include "render/ui_widgets.h"
|
||||
#include "utils/i18n.h"
|
||||
#include "xr/instance.h"
|
||||
#include "xr/session.h"
|
||||
#include "xr/system.h"
|
||||
|
||||
#include "imgui.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <boost/locale.hpp>
|
||||
#include <cmath>
|
||||
#include <functional>
|
||||
#include <locale>
|
||||
#include <optional>
|
||||
#include <spdlog/fmt/fmt.h>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
|
||||
namespace ui = wivrn::ui;
|
||||
|
||||
namespace
|
||||
{
|
||||
constexpr float control_w = ui::metrics::setting_control_width;
|
||||
|
||||
float toggle_width()
|
||||
{
|
||||
return ImGui::GetFrameHeight() * ui::metrics::control_height * ui::metrics::toggle_aspect;
|
||||
}
|
||||
|
||||
enum class ui_kind
|
||||
{
|
||||
toggle,
|
||||
slider,
|
||||
segmented,
|
||||
combo,
|
||||
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.
|
||||
struct setting
|
||||
{
|
||||
const char * id; // stable imgui id
|
||||
std::string label;
|
||||
std::string description;
|
||||
ui_kind ui = ui_kind::toggle;
|
||||
|
||||
std::function<bool()> get_bool;
|
||||
std::function<void(bool)> set_bool;
|
||||
|
||||
std::function<int()> get_int;
|
||||
std::function<void(int)> set_int;
|
||||
int v_min = 0;
|
||||
int v_max = 0;
|
||||
std::string fmt;
|
||||
std::function<std::vector<std::string>()> options;
|
||||
std::string title; // combo modal title
|
||||
|
||||
std::string button_label; // ui_kind::button
|
||||
std::function<void()> on_click; // ui_kind::button
|
||||
|
||||
std::optional<bool> default_bool; // reset target for toggles
|
||||
std::optional<int> default_int; // reset target for slider/segmented/combo
|
||||
|
||||
std::function<bool()> enabled;
|
||||
std::string disabled_tooltip; // shown on a disabled row
|
||||
};
|
||||
|
||||
void render_settings(const wivrn::gui::settings_context & ctx, const char * card_id, const std::vector<setting> & list)
|
||||
{
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ui::metrics::card_item_spacing);
|
||||
ui::begin_card(card_id);
|
||||
|
||||
for (const auto & s: list)
|
||||
{
|
||||
const bool enabled = s.enabled ? s.enabled() : true;
|
||||
ImGui::BeginDisabled(not enabled);
|
||||
|
||||
// stable storage for the reset defaults during this call
|
||||
bool def_b = s.default_bool.value_or(false);
|
||||
int def_i = s.default_int.value_or(0);
|
||||
const bool * dpb = s.default_bool ? &def_b : nullptr;
|
||||
const int * dpi = s.default_int ? &def_i : nullptr;
|
||||
|
||||
const ImVec2 row_min = ImGui::GetCursorScreenPos();
|
||||
|
||||
const float w = s.ui == ui_kind::toggle ? toggle_width() + (s.default_bool ? ui::reset_slot_width() : 0) : control_w;
|
||||
const float label_bottom = ui::setting_label(s.label, s.description, w);
|
||||
|
||||
switch (s.ui)
|
||||
{
|
||||
case ui_kind::toggle: {
|
||||
bool v = s.get_bool();
|
||||
if (ui::toggle(s.id, &v, dpb))
|
||||
s.set_bool(v);
|
||||
break;
|
||||
}
|
||||
case ui_kind::slider: {
|
||||
int v = s.get_int();
|
||||
if (ui::slider_int(s.id, &v, s.v_min, s.v_max, s.fmt.c_str(), {control_w, 0}, dpi))
|
||||
s.set_int(v);
|
||||
break;
|
||||
}
|
||||
case ui_kind::segmented: {
|
||||
const auto opts = s.options();
|
||||
int v = s.get_int();
|
||||
if (ui::segmented(s.id, opts, &v, {control_w, 0}, dpi))
|
||||
s.set_int(v);
|
||||
break;
|
||||
}
|
||||
case ui_kind::combo: {
|
||||
const auto opts = s.options();
|
||||
std::vector<ui::combo_item> items;
|
||||
for (const auto & o: opts)
|
||||
items.push_back({o.c_str()});
|
||||
int v = s.get_int();
|
||||
if (ui::combo(s.id, s.title, items, &v, control_w, dpi))
|
||||
s.set_int(v);
|
||||
break;
|
||||
}
|
||||
case ui_kind::button: {
|
||||
if (ui::button(s.button_label, ui::button_style::secondary, {control_w, 0}) and s.on_click)
|
||||
s.on_click();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
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).
|
||||
const float pad = std::max(label_bottom - ImGui::GetCursorPosY(), 0.f) + ui::metrics::label_bottom_pad;
|
||||
ImGui::Dummy({0, pad});
|
||||
|
||||
// disabled rows can't fire the widget tooltip hook, do it on the row
|
||||
if (not enabled and not s.disabled_tooltip.empty())
|
||||
{
|
||||
const ImVec2 row_max{row_min.x + ImGui::GetContentRegionAvail().x, ImGui::GetCursorScreenPos().y};
|
||||
if (ImGui::IsMouseHoveringRect(row_min, row_max))
|
||||
ctx.imgui_ctx.tooltip(s.disabled_tooltip, ImGui::GetMousePos());
|
||||
}
|
||||
}
|
||||
|
||||
ui::end_card();
|
||||
ImGui::PopStyleVar();
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace wivrn::gui
|
||||
{
|
||||
|
||||
void settings_performance(const settings_context & ctx)
|
||||
{
|
||||
auto & config = ctx.config;
|
||||
const std::string disconnect_tip = ctx.in_game ? _("Disconnect to change this setting.") : std::string{};
|
||||
std::vector<setting> list;
|
||||
|
||||
if (ctx.instance.has_extension(XR_FB_DISPLAY_REFRESH_RATE_EXTENSION_NAME) and not ctx.session.get_refresh_rates().empty())
|
||||
{
|
||||
const auto rates = ctx.session.get_refresh_rates();
|
||||
list.push_back({
|
||||
.id = "##refresh",
|
||||
.label = _("Refresh rate"),
|
||||
.description = _("Select refresh rate based on measured application performance.\nMay cause flicker when a change happens."),
|
||||
.ui = ui_kind::segmented,
|
||||
.get_int = [&config, rates] {
|
||||
for (size_t i = 0; i < rates.size(); ++i)
|
||||
if (rates[i] == config.preferred_refresh_rate)
|
||||
return int(i) + 1;
|
||||
return 0; },
|
||||
.set_int = [&ctx, &config, rates](int v) {
|
||||
if (v == 0)
|
||||
{
|
||||
config.preferred_refresh_rate = 0;
|
||||
config.fps_divider = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
ctx.session.set_refresh_rate(rates[v - 1]);
|
||||
config.preferred_refresh_rate = rates[v - 1];
|
||||
}
|
||||
config.save();
|
||||
if (ctx.on_streaming_changed)
|
||||
ctx.on_streaming_changed(); },
|
||||
.options = [rates] {
|
||||
std::vector<std::string> opts;
|
||||
opts.push_back(_C("automatic refresh rate", "Auto"));
|
||||
for (float r: rates)
|
||||
opts.push_back(fmt::format("{}", int(r)));
|
||||
return opts; },
|
||||
.default_int = 0,
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
const auto width = ctx.recommended_width;
|
||||
const auto height = ctx.recommended_height;
|
||||
list.push_back({
|
||||
.id = "##resolution",
|
||||
.label = _("Render resolution"),
|
||||
.description = fmt::format(_cF("render resolution", "Pixels rendered per eye ({}x{}). Lower to gain performance."), int(width * config.resolution_scale), int(height * config.resolution_scale)),
|
||||
.ui = ui_kind::slider,
|
||||
.get_int = [&config] { return int(std::lround(config.resolution_scale * 100)); },
|
||||
.set_int = [&config](int v) { config.resolution_scale = v / 100.0; config.save(); },
|
||||
.v_min = 50,
|
||||
.v_max = config.extended_config ? 350 : 150,
|
||||
.fmt = "%d%%",
|
||||
.default_int = 100,
|
||||
.enabled = [&ctx] { return not ctx.in_game; },
|
||||
.disabled_tooltip = disconnect_tip,
|
||||
});
|
||||
}
|
||||
|
||||
list.push_back({
|
||||
.id = "##foveation",
|
||||
.label = _("Foveated encoding"),
|
||||
.description = config.check_feature(feature::eye_gaze)
|
||||
? _("Higher values focus image quality where you look at, improving latency, power efficiency and quality.")
|
||||
: _("Higher values focus image quality at the center, improving latency, power efficiency and quality."),
|
||||
.ui = ui_kind::slider,
|
||||
.get_int = [&config] { return int(std::lround((1 - config.get_stream_scale()) * 100)); },
|
||||
.set_int = [&config](int v) {
|
||||
if (not config.extended_config)
|
||||
v = std::clamp(v, 30, 80);
|
||||
config.set_stream_scale(1 - v * 0.01);
|
||||
config.save(); },
|
||||
.v_min = 0,
|
||||
.v_max = 80,
|
||||
.fmt = "%d%%",
|
||||
.default_int = int(std::lround((1 - (config.check_feature(feature::eye_gaze) ? 0.3 : 0.5)) * 100)),
|
||||
.enabled = [&ctx] { return not ctx.in_game; },
|
||||
.disabled_tooltip = disconnect_tip,
|
||||
});
|
||||
|
||||
if (ctx.instance.has_extension(XR_FB_DISPLAY_REFRESH_RATE_EXTENSION_NAME))
|
||||
{
|
||||
list.push_back({
|
||||
.id = "##spacewarp",
|
||||
.label = _("Application SpaceWarp"),
|
||||
.description = _("Renders at half the refresh rate and synthesises in-between frames. Managed automatically while the refresh rate is set to Auto."),
|
||||
.ui = ui_kind::toggle,
|
||||
.get_bool = [&config] { return config.fps_divider == 2; },
|
||||
.set_bool = [&ctx, &config](bool v) { config.fps_divider = v ? 2 : 1; config.save(); if (ctx.on_streaming_changed) ctx.on_streaming_changed(); },
|
||||
.default_bool = false,
|
||||
.enabled = [&config] { return config.preferred_refresh_rate != 0; },
|
||||
});
|
||||
}
|
||||
|
||||
if (ctx.instance.has_extension(XR_EXT_PERFORMANCE_SETTINGS_EXTENSION_NAME))
|
||||
{
|
||||
list.push_back({
|
||||
.id = "##high_power",
|
||||
.label = _("High power mode"),
|
||||
.description = _("Increase power usage to allow higher resolution and refresh rate. Drains battery and runs hot."),
|
||||
.ui = ui_kind::toggle,
|
||||
.get_bool = [&config] { return config.high_power_mode; },
|
||||
.set_bool = [&config](bool v) { config.high_power_mode = v; config.save(); },
|
||||
.default_bool = true,
|
||||
});
|
||||
}
|
||||
|
||||
ui::page_header(_S("Performance"), _S("Frame rate, resolution and power draw."));
|
||||
render_settings(ctx, "##performance", list);
|
||||
}
|
||||
|
||||
void settings_streaming(const settings_context & ctx)
|
||||
{
|
||||
auto & config = ctx.config;
|
||||
const std::string disconnect_tip = ctx.in_game ? _("Disconnect to change this setting.") : std::string{};
|
||||
std::vector<setting> list;
|
||||
|
||||
auto codec_name = [](std::optional<wivrn::video_codec> codec) -> std::string {
|
||||
if (not codec)
|
||||
return _C("Codec", "Automatic");
|
||||
switch (*codec)
|
||||
{
|
||||
case wivrn::h264:
|
||||
return _C("Codec", "H.264");
|
||||
case wivrn::h265:
|
||||
return _C("Codec", "HEVC (H.265)");
|
||||
case wivrn::av1:
|
||||
return _C("Codec", "AV1");
|
||||
case wivrn::raw:
|
||||
break;
|
||||
}
|
||||
return _C("Codec", "Automatic");
|
||||
};
|
||||
|
||||
std::vector<wivrn::video_codec> codecs;
|
||||
for (auto c: wivrn::decoder::supported_codecs())
|
||||
if (c != wivrn::raw)
|
||||
codecs.push_back(c);
|
||||
|
||||
list.push_back({
|
||||
.id = "##codec",
|
||||
.label = _("Video codec"),
|
||||
.description = _("How video is compressed before it is sent to the headset."),
|
||||
.ui = ui_kind::combo,
|
||||
.get_int = [&config, codecs] {
|
||||
if (config.codec)
|
||||
for (size_t i = 0; i < codecs.size(); ++i)
|
||||
if (codecs[i] == *config.codec)
|
||||
return int(i) + 1;
|
||||
return 0; },
|
||||
.set_int = [&config, codecs](int v) {
|
||||
config.codec = v == 0 ? std::nullopt : std::optional(codecs[v - 1]);
|
||||
config.save(); },
|
||||
.options = [codecs, codec_name] {
|
||||
std::vector<std::string> opts;
|
||||
opts.push_back(codec_name(std::nullopt));
|
||||
for (auto c: codecs)
|
||||
opts.push_back(codec_name(c));
|
||||
return opts; },
|
||||
.title = _("Video codec"),
|
||||
.default_int = 0,
|
||||
.enabled = [&ctx] { return not ctx.in_game; },
|
||||
.disabled_tooltip = disconnect_tip,
|
||||
});
|
||||
|
||||
if (config.codec == wivrn::h265 or config.codec == wivrn::av1)
|
||||
{
|
||||
list.push_back({
|
||||
.id = "##ten_bit",
|
||||
.label = _("10-bit color"),
|
||||
.description = _("Higher color precision, supported by HEVC and AV1."),
|
||||
.ui = ui_kind::toggle,
|
||||
.get_bool = [&config] { return config.bit_depth == 10; },
|
||||
.set_bool = [&config](bool v) { config.bit_depth = v ? 10 : 8; config.save(); },
|
||||
.default_bool = true,
|
||||
.enabled = [&ctx] { return not ctx.in_game; },
|
||||
.disabled_tooltip = disconnect_tip,
|
||||
});
|
||||
}
|
||||
|
||||
const int mb = 1'000'000;
|
||||
list.push_back({
|
||||
.id = "##bitrate",
|
||||
.label = _("Bitrate"),
|
||||
.description = _("Video data rate sent to the headset."),
|
||||
.ui = ui_kind::slider,
|
||||
.get_int = [&config] { return int(config.bitrate_bps / mb); },
|
||||
.set_int = [&ctx, &config](int v) { config.bitrate_bps = uint32_t(v) * 1'000'000; config.save(); if (ctx.on_streaming_changed) ctx.on_streaming_changed(); },
|
||||
.v_min = 5,
|
||||
.v_max = int(config.max_bitrate() / mb),
|
||||
.fmt = "%d Mbit/s",
|
||||
.default_int = 50,
|
||||
});
|
||||
|
||||
// in-stream: thumbstick bitrate, easier than the slider in VR
|
||||
if (ctx.in_game and ctx.enter_bitrate_adjust)
|
||||
{
|
||||
list.push_back({
|
||||
.id = "##bitrate_adjust",
|
||||
.label = _("Adjust bitrate with thumbstick"),
|
||||
.description = _("Use the right thumbstick to fine-tune the bitrate."),
|
||||
.ui = ui_kind::button,
|
||||
.button_label = _("Adjust"),
|
||||
.on_click = [&ctx] { ctx.enter_bitrate_adjust(); },
|
||||
});
|
||||
}
|
||||
|
||||
// in-stream: steer where foveation focuses quality
|
||||
if (ctx.in_game)
|
||||
{
|
||||
list.push_back({
|
||||
.id = "##fov_override",
|
||||
.label = _("Foveation center override"),
|
||||
.description = _("Manually set where image quality is focused, instead of the center or your gaze."),
|
||||
.ui = ui_kind::toggle,
|
||||
.get_bool = [&config] { return config.override_foveation_enable; },
|
||||
.set_bool = [&ctx, &config](bool v) {
|
||||
config.override_foveation_enable = v;
|
||||
config.save();
|
||||
if (ctx.on_foveation_override_changed)
|
||||
ctx.on_foveation_override_changed(); },
|
||||
.default_bool = false,
|
||||
});
|
||||
list.push_back({
|
||||
.id = "##fov_adjust",
|
||||
.label = _("Foveation center"),
|
||||
.description = fmt::format(_F("Height {:.1f} deg, distance {:.2f} m"), -config.override_foveation_pitch * 180 / M_PI, config.override_foveation_distance),
|
||||
.ui = ui_kind::button,
|
||||
.button_label = _("Change"),
|
||||
.on_click = [&ctx] { if (ctx.enter_foveation_adjust) ctx.enter_foveation_adjust(); },
|
||||
.enabled = [&config] { return config.override_foveation_enable; },
|
||||
});
|
||||
}
|
||||
|
||||
list.push_back({
|
||||
.id = "##stream_gui",
|
||||
.label = _("In-stream window"),
|
||||
.description = _("Enables the configuration window to be shown while the game is streaming.\nIf enabled, the window is activated by pressing both thumbsticks."),
|
||||
.ui = ui_kind::toggle,
|
||||
.get_bool = [&config] { return config.enable_stream_gui; },
|
||||
.set_bool = [&config](bool v) { config.enable_stream_gui = v; config.save(); },
|
||||
.default_bool = true,
|
||||
});
|
||||
|
||||
ui::page_header(_S("Streaming"), _S("How video is encoded and sent to the headset."));
|
||||
render_settings(ctx, "##streaming", list);
|
||||
}
|
||||
|
||||
void settings_post_processing(const settings_context & ctx)
|
||||
{
|
||||
auto & config = ctx.config;
|
||||
std::vector<setting> list;
|
||||
|
||||
if (application::get_openxr_post_processing_supported())
|
||||
{
|
||||
auto flag_name = [](XrCompositionLayerSettingsFlagsFB f) -> std::string {
|
||||
switch (f)
|
||||
{
|
||||
case XR_COMPOSITION_LAYER_SETTINGS_NORMAL_SUPER_SAMPLING_BIT_FB:
|
||||
case XR_COMPOSITION_LAYER_SETTINGS_NORMAL_SHARPENING_BIT_FB:
|
||||
return _C("openxr_post_processing", "Normal");
|
||||
case XR_COMPOSITION_LAYER_SETTINGS_QUALITY_SUPER_SAMPLING_BIT_FB:
|
||||
case XR_COMPOSITION_LAYER_SETTINGS_QUALITY_SHARPENING_BIT_FB:
|
||||
return _C("openxr_post_processing", "Quality");
|
||||
default:
|
||||
return _C("openxr_post_processing", "Disabled");
|
||||
}
|
||||
};
|
||||
|
||||
auto flag_combo = [&](const char * id, std::string label, std::string desc, std::array<XrCompositionLayerSettingsFlagsFB, 3> flags, XrCompositionLayerSettingsFlagsFB configuration::openxr_post_processing_settings::* member) {
|
||||
std::string title = label;
|
||||
list.push_back({
|
||||
.id = id,
|
||||
.label = std::move(label),
|
||||
.description = std::move(desc),
|
||||
.ui = ui_kind::combo,
|
||||
.get_int = [&config, flags, member] {
|
||||
for (size_t i = 0; i < flags.size(); ++i)
|
||||
if (config.openxr_post_processing.*member == flags[i])
|
||||
return int(i);
|
||||
return 0; },
|
||||
.set_int = [&config, flags, member](int v) {
|
||||
config.openxr_post_processing.*member = flags[v];
|
||||
config.save(); },
|
||||
.options = [flags, flag_name] {
|
||||
std::vector<std::string> o;
|
||||
for (auto f: flags)
|
||||
o.push_back(flag_name(f));
|
||||
return o; },
|
||||
.title = std::move(title),
|
||||
.default_int = 0,
|
||||
});
|
||||
};
|
||||
|
||||
flag_combo("##supersampling", _("Supersampling"), _("Reduce flicker for high contrast edges.\nUseful when the input resolution is high compared to the headset display."), {0, XR_COMPOSITION_LAYER_SETTINGS_NORMAL_SUPER_SAMPLING_BIT_FB, XR_COMPOSITION_LAYER_SETTINGS_QUALITY_SUPER_SAMPLING_BIT_FB}, &configuration::openxr_post_processing_settings::super_sampling);
|
||||
flag_combo("##sharpening", _("Sharpening"), _("Improve clarity of high contrast edges and counteract blur.\nUseful when the input resolution is low compared to the headset display."), {0, XR_COMPOSITION_LAYER_SETTINGS_NORMAL_SHARPENING_BIT_FB, XR_COMPOSITION_LAYER_SETTINGS_QUALITY_SHARPENING_BIT_FB}, &configuration::openxr_post_processing_settings::sharpening);
|
||||
}
|
||||
|
||||
ui::page_header(_S("Post-processing"), _S("OpenXR layer supersampling and sharpening."));
|
||||
render_settings(ctx, "##post_processing", list);
|
||||
}
|
||||
|
||||
void settings_audio(const settings_context & ctx)
|
||||
{
|
||||
auto & config = ctx.config;
|
||||
const std::string disconnect_tip = ctx.in_game ? _("Disconnect to change this setting.") : std::string{};
|
||||
std::vector<setting> list;
|
||||
|
||||
list.push_back({
|
||||
.id = "##microphone",
|
||||
.label = _("Microphone"),
|
||||
.description = _("Stream the headset microphone to the PC."),
|
||||
.ui = ui_kind::toggle,
|
||||
.get_bool = [&config] { return config.check_feature(feature::microphone); },
|
||||
.set_bool = [&config](bool v) { config.set_feature(feature::microphone, v); },
|
||||
.default_bool = false,
|
||||
.enabled = [&ctx] { return not ctx.in_game; },
|
||||
.disabled_tooltip = disconnect_tip,
|
||||
});
|
||||
|
||||
list.push_back({
|
||||
.id = "##unprocessed",
|
||||
.label = _("Unprocessed audio"),
|
||||
.description = _("Force disable audio filters, such as noise cancellation."),
|
||||
.ui = ui_kind::toggle,
|
||||
.get_bool = [&config] { return config.mic_unprocessed_audio; },
|
||||
.set_bool = [&config](bool v) { config.mic_unprocessed_audio = v; config.save(); },
|
||||
.default_bool = false,
|
||||
.enabled = [&ctx, &config] { return not ctx.in_game and config.check_feature(feature::microphone); },
|
||||
.disabled_tooltip = disconnect_tip,
|
||||
});
|
||||
|
||||
ui::page_header(_S("Audio"), _S("Microphone streamed to the PC."));
|
||||
render_settings(ctx, "##audio", list);
|
||||
}
|
||||
|
||||
void settings_devices(const settings_context & ctx)
|
||||
{
|
||||
auto & config = application::get_config();
|
||||
std::vector<setting> list;
|
||||
|
||||
list.push_back({
|
||||
.id = "##keyboard",
|
||||
.label = _("Keyboard"),
|
||||
.description = _("Forward the keyboard from the headset to the PC."),
|
||||
.ui = ui_kind::toggle,
|
||||
.get_bool = [&config] { return config.forward_keyboard; },
|
||||
.set_bool = [&config](bool v) { config.forward_keyboard = v; config.save(); },
|
||||
.default_bool = false,
|
||||
});
|
||||
|
||||
list.push_back({
|
||||
.id = "##mouse",
|
||||
.label = _("Mouse"),
|
||||
.description = _("Forward the mouse from the headset to the PC."),
|
||||
.ui = ui_kind::toggle,
|
||||
.get_bool = [&config] { return config.forward_mouse; },
|
||||
.set_bool = [&config](bool v) { config.forward_mouse = v; config.save(); },
|
||||
.default_bool = false,
|
||||
});
|
||||
|
||||
list.push_back({
|
||||
.id = "##gamepad",
|
||||
.label = _("Gamepad"),
|
||||
.description = _("Forward the gamepad from the headset to the PC."),
|
||||
.ui = ui_kind::toggle,
|
||||
.get_bool = [&config] { return config.forward_gamepad; },
|
||||
.set_bool = [&config](bool v) { config.forward_gamepad = v; config.save(); },
|
||||
.default_bool = false,
|
||||
});
|
||||
|
||||
ui::page_header(_S("Devices"), _S("Forward input devices to the PC."));
|
||||
render_settings(ctx, "##devices", list);
|
||||
|
||||
if (ctx.server_hid_forwarding == false and (config.forward_keyboard or config.forward_mouse or config.forward_gamepad))
|
||||
ui::chip(_("The server does not allow forwarded input devices"), ui::chip_style::warning);
|
||||
}
|
||||
|
||||
bool settings_tracking(const settings_context & ctx)
|
||||
{
|
||||
auto & config = ctx.config;
|
||||
const std::string disconnect_tip = ctx.in_game ? _("Disconnect to change this setting.") : std::string{};
|
||||
std::vector<setting> list;
|
||||
|
||||
auto feature_toggle = [&](const char * id, std::string label, std::string desc, feature f, bool def) {
|
||||
list.push_back({
|
||||
.id = id,
|
||||
.label = std::move(label),
|
||||
.description = std::move(desc),
|
||||
.ui = ui_kind::toggle,
|
||||
.get_bool = [&config, f] { return config.check_feature(f); },
|
||||
.set_bool = [&config, f](bool v) { config.set_feature(f, v); },
|
||||
.default_bool = def,
|
||||
.enabled = [&ctx] { return not ctx.in_game; },
|
||||
.disabled_tooltip = disconnect_tip,
|
||||
});
|
||||
};
|
||||
|
||||
if (ctx.system.hand_tracking_supported())
|
||||
feature_toggle("##hand", _("Hand tracking"), _("Track your hands for input when controllers are down."), feature::hand_tracking, true);
|
||||
|
||||
if (application::get_eye_gaze_supported())
|
||||
feature_toggle("##eye", _("Eye tracking"), _("Used by foveated encoding to focus quality where you look."), feature::eye_gaze, false);
|
||||
|
||||
if (ctx.system.face_tracker_supported() != xr::face_tracker_type::none)
|
||||
feature_toggle("##face", _("Face tracking"), _("Stream facial expressions to the PC."), feature::face_tracking, false);
|
||||
|
||||
const auto body_tracker = ctx.system.body_tracker_supported();
|
||||
if (body_tracker != xr::body_tracker_type::none)
|
||||
{
|
||||
list.push_back({
|
||||
.id = "##body",
|
||||
.label = _("Body tracking"),
|
||||
.description = body_tracker == xr::body_tracker_type::fb or body_tracker == xr::body_tracker_type::meta
|
||||
? _("Requires 'Hand and body tracking' to be enabled in the Quest movement tracking settings, otherwise body data will be guessed from controller and headset positions.")
|
||||
: _("Stream body joint positions to the PC."),
|
||||
.ui = ui_kind::toggle,
|
||||
.get_bool = [&config] { return config.check_feature(feature::body_tracking); },
|
||||
.set_bool = [&config](bool v) { config.set_feature(feature::body_tracking, v); },
|
||||
.default_bool = false,
|
||||
.enabled = [&ctx] { return not ctx.in_game; },
|
||||
.disabled_tooltip = disconnect_tip,
|
||||
});
|
||||
}
|
||||
|
||||
ui::page_header(_S("Tracking"), _S("Body and input tracking sent to the PC."));
|
||||
render_settings(ctx, "##tracking", list);
|
||||
|
||||
if (body_tracker != xr::body_tracker_type::none)
|
||||
return wivrn::gui::body_tracking_parts(ctx.system, ctx.imgui_ctx, config, ctx.in_game);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void settings_system(const settings_context & ctx)
|
||||
{
|
||||
auto & config = ctx.config;
|
||||
std::vector<setting> list;
|
||||
|
||||
auto language_name = [](const std::locale & loc = std::locale()) {
|
||||
return boost::locale::pgettext("language selection, replace with the name of the language", "English", loc);
|
||||
};
|
||||
std::vector<std::tuple<std::string, std::locale, std::string>> languages;
|
||||
for (const auto & msg_info: get_locales())
|
||||
{
|
||||
std::string code = msg_info.language;
|
||||
if (not msg_info.country.empty())
|
||||
code += "_" + msg_info.country;
|
||||
std::locale loc(std::locale(), boost::locale::gnu_gettext::create_messages_facet<char>(msg_info));
|
||||
languages.emplace_back(language_name(loc), loc, std::move(code));
|
||||
}
|
||||
std::ranges::sort(languages, [](auto & l, auto & r) { return std::get<0>(l) < std::get<0>(r); });
|
||||
|
||||
list.push_back({
|
||||
.id = "##language",
|
||||
.label = _("Language"),
|
||||
.description = _("Interface language."),
|
||||
.ui = ui_kind::combo,
|
||||
.get_int = [&config, languages] {
|
||||
if (not config.locale.empty())
|
||||
for (size_t i = 0; i < languages.size(); ++i)
|
||||
if (std::get<2>(languages[i]) == config.locale)
|
||||
return int(i) + 1;
|
||||
return 0; },
|
||||
.set_int = [&config, languages](int v) {
|
||||
config.locale = v == 0 ? "" : std::get<2>(languages[v - 1]);
|
||||
config.save();
|
||||
application::instance().load_locale(); },
|
||||
.options = [languages] {
|
||||
std::vector<std::string> opts;
|
||||
opts.push_back(_C("language", "System language"));
|
||||
for (const auto & [lang, loc, code]: languages)
|
||||
opts.push_back(lang);
|
||||
return opts; },
|
||||
.title = _("Language"),
|
||||
.default_int = 0,
|
||||
});
|
||||
|
||||
list.push_back({
|
||||
.id = "##extended",
|
||||
.label = _("Extended configuration"),
|
||||
.description = _("Allows unsafe configuration values, use at your own risk."),
|
||||
.ui = ui_kind::toggle,
|
||||
.get_bool = [&config] { return config.extended_config; },
|
||||
.set_bool = [&config](bool v) { config.extended_config = v; config.save(); },
|
||||
.default_bool = false,
|
||||
});
|
||||
|
||||
ui::page_header(_S("System"), _S("Language and advanced options."));
|
||||
render_settings(ctx, "##system", list);
|
||||
}
|
||||
|
||||
} // namespace wivrn::gui
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2026 Guillaume Meunier <guillaume.meunier@centraliens.net>
|
||||
* Copyright (C) 2026 Patrick Nicolas <patricknicolas@laposte.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
|
||||
class configuration;
|
||||
class imgui_context;
|
||||
|
||||
namespace xr
|
||||
{
|
||||
class instance;
|
||||
class session;
|
||||
class system;
|
||||
} // namespace xr
|
||||
|
||||
namespace wivrn::gui
|
||||
{
|
||||
|
||||
// what the shared settings pages need, in the lobby or the in-stream window
|
||||
struct settings_context
|
||||
{
|
||||
configuration & config;
|
||||
xr::instance & instance;
|
||||
xr::session & session;
|
||||
xr::system & system;
|
||||
imgui_context & imgui_ctx;
|
||||
|
||||
// recommended per-eye render resolution, for the resolution description
|
||||
uint32_t recommended_width = 0;
|
||||
uint32_t recommended_height = 0;
|
||||
|
||||
// streaming: connection-time settings are disabled, in-stream controls appear
|
||||
bool in_game = false;
|
||||
|
||||
std::optional<bool> server_hid_forwarding;
|
||||
|
||||
// in-stream hooks, empty in the lobby
|
||||
std::function<void()> on_streaming_changed; // refresh rate / spacewarp / bitrate
|
||||
std::function<void()> enter_bitrate_adjust; // thumbstick bitrate sub-mode
|
||||
std::function<void()> enter_foveation_adjust; // thumbstick foveation sub-mode
|
||||
std::function<void()> on_foveation_override_changed; // foveation override toggled
|
||||
};
|
||||
|
||||
void settings_performance(const settings_context &);
|
||||
void settings_streaming(const settings_context &);
|
||||
void settings_post_processing(const settings_context &);
|
||||
void settings_audio(const settings_context &);
|
||||
void settings_devices(const settings_context &);
|
||||
bool settings_tracking(const settings_context &);
|
||||
void settings_system(const settings_context &);
|
||||
|
||||
} // namespace wivrn::gui
|
||||
@@ -170,6 +170,8 @@ scenes::lobby::lobby() :
|
||||
|
||||
keyboard.set_layout(config.virtual_keyboard_layout);
|
||||
|
||||
apply_theme_settings();
|
||||
|
||||
if (config.first_run)
|
||||
current_tab = tab::first_run;
|
||||
|
||||
|
||||
@@ -239,6 +239,7 @@ class lobby : public scene_impl<lobby>
|
||||
void gui_post_processing();
|
||||
void gui_customize(XrTime predicted_display_time);
|
||||
void gui_theme();
|
||||
void apply_theme_settings(); // push the saved theme config into the global theme
|
||||
void gui_debug_node_hierarchy(entt::entity root = entt::null);
|
||||
void gui_debug();
|
||||
void gui_about();
|
||||
|
||||
+46
-163
@@ -19,9 +19,6 @@
|
||||
|
||||
#define IMGUI_DEFINE_MATH_OPERATORS
|
||||
|
||||
#ifdef __ANDROID__
|
||||
#include "android/battery.h"
|
||||
#endif
|
||||
#include "application.h"
|
||||
#include "configuration.h"
|
||||
#include "constants.h"
|
||||
@@ -1058,7 +1055,7 @@ std::vector<std::pair<int, XrCompositionLayerQuad>> scenes::lobby::draw_gui(XrTi
|
||||
wivrn::ui::set_hover_haptic([this] { imgui_ctx->vibrate_on_hover(); });
|
||||
wivrn::ui::set_tooltip_hook([this](const char * text) { imgui_ctx->tooltip(text); });
|
||||
|
||||
const float TabWidth = 300;
|
||||
const float TabWidth = wivrn::ui::metrics::sidebar_width;
|
||||
|
||||
if (ImGui::GetIO().WantTextInput)
|
||||
{
|
||||
@@ -1069,7 +1066,7 @@ std::vector<std::pair<int, XrCompositionLayerQuad>> scenes::lobby::draw_gui(XrTi
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ScrollbarSize, 30);
|
||||
// window background follows the theme, with a user-controlled opacity
|
||||
const wivrn::ui::theme & th = wivrn::ui::current();
|
||||
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4{th.background.x, th.background.y, th.background.z, th.background_alpha});
|
||||
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4{th.background.x, th.background.y, th.background.z, wivrn::ui::background_alpha()});
|
||||
|
||||
ImGui::SetNextWindowPos(imgui_ctx->layers()[0].vp_center(), ImGuiCond_Always, {0.5, 0.5});
|
||||
|
||||
@@ -1102,148 +1099,55 @@ std::vector<std::pair<int, XrCompositionLayerQuad>> scenes::lobby::draw_gui(XrTi
|
||||
ImGui::Begin("WiVRn", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove);
|
||||
|
||||
auto & config = application::get_config();
|
||||
const float TopBarH = 72;
|
||||
const float TopBarH = wivrn::ui::metrics::top_bar_height;
|
||||
|
||||
// Top bar: logo on the left, status controls on the right.
|
||||
// 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, TopBarH}, 0, ImGuiWindowFlags_NoScrollbar);
|
||||
{
|
||||
const float side = ImGui::GetFrameHeight() * wivrn::ui::metrics::control_height;
|
||||
const float gap = 8;
|
||||
// Top bar: logo left; feature toggles, battery and connection status right.
|
||||
const float side = ImGui::GetFrameHeight() * wivrn::ui::metrics::control_height;
|
||||
std::vector<wivrn::ui::top_bar_item> top_items;
|
||||
|
||||
// logo: WiVRn mascot followed by the wordmark
|
||||
const float logo_size = 44;
|
||||
ImGui::SetCursorPos({24, (TopBarH - logo_size) * 0.5f});
|
||||
if (about_picture)
|
||||
ImGui::Image(about_picture, {logo_size, logo_size});
|
||||
ImGui::SameLine(0, 12);
|
||||
ImGui::PushFont(nullptr, ImGui::GetStyle().FontSizeBase * 1.3f);
|
||||
ImGui::SetCursorPosY((TopBarH - ImGui::GetFontSize()) * 0.5f);
|
||||
ImGui::TextUnformatted("WiVRn");
|
||||
ImGui::PopFont();
|
||||
// feature toggle slot: reads its state and toggles on click (mic + passthrough always shown)
|
||||
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;
|
||||
auto & config = application::get_config();
|
||||
const bool on = config.check_feature(f);
|
||||
if (wivrn::ui::icon_button(icon, {s, s}, on, label))
|
||||
config.set_feature(f, not on);
|
||||
}});
|
||||
};
|
||||
|
||||
// right cluster: feature toggles + battery + connection status
|
||||
const std::string conn = _("Not connected");
|
||||
const ImVec2 cts = ImGui::CalcTextSize(conn.c_str());
|
||||
const float dot_r = cts.y * 0.26f;
|
||||
// pill: pad_x on each side + dot + 0.55 pad_x gap before the text (see ui::chip)
|
||||
const float chip_w = cts.x + wivrn::ui::metrics::chip_pill_padding_x * 2.55f + dot_r * 2;
|
||||
toggle_item(ICON_FA_MICROPHONE, _S("Microphone"), feature::microphone);
|
||||
top_items.push_back({side, [this] {
|
||||
const float s = ImGui::GetFrameHeight() * wivrn::ui::metrics::control_height;
|
||||
auto & config = application::get_config();
|
||||
if (wivrn::ui::icon_button(ICON_FA_EYE_SLASH, {s, s}, config.passthrough_enabled, _S("Passthrough")))
|
||||
{
|
||||
config.passthrough_enabled = not config.passthrough_enabled;
|
||||
setup_passthrough();
|
||||
config.save();
|
||||
}
|
||||
}});
|
||||
if (system.hand_tracking_supported())
|
||||
toggle_item(ICON_FA_HAND, _S("Hand tracking"), feature::hand_tracking);
|
||||
if (application::get_eye_gaze_supported())
|
||||
toggle_item(ICON_FA_EYE, _S("Eye tracking"), feature::eye_gaze);
|
||||
if (system.face_tracker_supported() != xr::face_tracker_type::none)
|
||||
toggle_item(ICON_FA_FACE_SMILE, _S("Face tracking"), feature::face_tracking);
|
||||
if (system.body_tracker_supported() != xr::body_tracker_type::none)
|
||||
toggle_item(ICON_FA_PERSON, _S("Body tracking"), feature::body_tracking);
|
||||
|
||||
// feature toggles available on this headset (mic + passthrough are always shown)
|
||||
const bool has_hand = system.hand_tracking_supported();
|
||||
const bool has_eye = application::get_eye_gaze_supported();
|
||||
const bool has_face = system.face_tracker_supported() != xr::face_tracker_type::none;
|
||||
const bool has_body = system.body_tracker_supported() != xr::body_tracker_type::none;
|
||||
const int n_toggles = 2 + has_hand + has_eye + has_face + has_body;
|
||||
if (auto bat = wivrn::gui::battery_status_indicator(instance.now()))
|
||||
top_items.push_back({wivrn::ui::chip_width(bat->label, false, side),
|
||||
[bat = *bat, side] { wivrn::ui::chip(bat.label, bat.style, false, side); }});
|
||||
|
||||
#ifdef __ANDROID__
|
||||
const auto battery = get_battery_status();
|
||||
std::string battery_label;
|
||||
wivrn::ui::chip_style battery_style = wivrn::ui::chip_style::neutral;
|
||||
if (battery.charge)
|
||||
{
|
||||
const char * battery_icon = ICON_FA_BATTERY_FULL;
|
||||
int icon_nr;
|
||||
if (battery.charging)
|
||||
icon_nr = *battery.charge > 0.995 ? 5 : instance.now() / 500'000'000 % 5;
|
||||
else
|
||||
icon_nr = std::round((*battery.charge) * 4);
|
||||
switch (icon_nr)
|
||||
{
|
||||
case 0:
|
||||
battery_icon = ICON_FA_BATTERY_EMPTY;
|
||||
break;
|
||||
case 1:
|
||||
battery_icon = ICON_FA_BATTERY_QUARTER;
|
||||
break;
|
||||
case 2:
|
||||
battery_icon = ICON_FA_BATTERY_HALF;
|
||||
break;
|
||||
case 3:
|
||||
battery_icon = ICON_FA_BATTERY_THREE_QUARTERS;
|
||||
break;
|
||||
case 4:
|
||||
battery_icon = ICON_FA_BATTERY_FULL;
|
||||
break;
|
||||
case 5:
|
||||
battery_icon = ICON_FA_PLUG;
|
||||
break;
|
||||
}
|
||||
battery_label = fmt::format("{} {}%", battery_icon, (int)std::round(*battery.charge * 100));
|
||||
if (*battery.charge < 0.2)
|
||||
battery_style = wivrn::ui::chip_style::danger;
|
||||
else if (*battery.charge < 0.5)
|
||||
battery_style = wivrn::ui::chip_style::warning;
|
||||
else
|
||||
battery_style = wivrn::ui::chip_style::success;
|
||||
}
|
||||
const float battery_w = battery_label.empty() ? 0 : gap + ImGui::CalcTextSize(battery_label.c_str()).x + wivrn::ui::metrics::chip_pill_padding_x * 2;
|
||||
#else
|
||||
const float battery_w = 0;
|
||||
#endif
|
||||
const float cluster_w = n_toggles * side + n_toggles * gap + battery_w + chip_w;
|
||||
ImGui::SetCursorPos({ImGui::GetWindowSize().x - 24 - cluster_w, (TopBarH - side) * 0.5f});
|
||||
const std::string conn = _("Not connected");
|
||||
top_items.push_back({wivrn::ui::chip_width(conn, true, side),
|
||||
[conn, side] { wivrn::ui::chip(conn, wivrn::ui::chip_style::muted, true, side); }});
|
||||
|
||||
bool mic = config.check_feature(feature::microphone);
|
||||
if (wivrn::ui::icon_button(ICON_FA_MICROPHONE, {side, side}, mic, _S("Microphone")))
|
||||
config.set_feature(feature::microphone, not mic);
|
||||
ImGui::SameLine(0, gap);
|
||||
if (wivrn::ui::icon_button(ICON_FA_EYE_SLASH, {side, side}, config.passthrough_enabled, _S("Passthrough")))
|
||||
{
|
||||
config.passthrough_enabled = not config.passthrough_enabled;
|
||||
setup_passthrough();
|
||||
config.save();
|
||||
}
|
||||
if (has_hand)
|
||||
{
|
||||
ImGui::SameLine(0, gap);
|
||||
bool hand = config.check_feature(feature::hand_tracking);
|
||||
if (wivrn::ui::icon_button(ICON_FA_HAND, {side, side}, hand, _S("Hand tracking")))
|
||||
config.set_feature(feature::hand_tracking, not hand);
|
||||
}
|
||||
if (has_eye)
|
||||
{
|
||||
ImGui::SameLine(0, gap);
|
||||
bool eye = config.check_feature(feature::eye_gaze);
|
||||
if (wivrn::ui::icon_button(ICON_FA_EYE, {side, side}, eye, _S("Eye tracking")))
|
||||
config.set_feature(feature::eye_gaze, not eye);
|
||||
}
|
||||
if (has_face)
|
||||
{
|
||||
ImGui::SameLine(0, gap);
|
||||
bool face = config.check_feature(feature::face_tracking);
|
||||
if (wivrn::ui::icon_button(ICON_FA_FACE_SMILE, {side, side}, face, _S("Face tracking")))
|
||||
config.set_feature(feature::face_tracking, not face);
|
||||
}
|
||||
if (has_body)
|
||||
{
|
||||
ImGui::SameLine(0, gap);
|
||||
bool body = config.check_feature(feature::body_tracking);
|
||||
if (wivrn::ui::icon_button(ICON_FA_PERSON, {side, side}, body, _S("Body tracking")))
|
||||
config.set_feature(feature::body_tracking, not body);
|
||||
}
|
||||
|
||||
#ifdef __ANDROID__
|
||||
// battery status, as a pill like the connection chip
|
||||
if (not battery_label.empty())
|
||||
{
|
||||
ImGui::SameLine(0, gap);
|
||||
ImGui::SetCursorPosY((TopBarH - side) * 0.5f);
|
||||
wivrn::ui::chip(battery_label, battery_style, false, side);
|
||||
}
|
||||
#endif
|
||||
|
||||
ImGui::SameLine(0, gap);
|
||||
ImGui::SetCursorPosY((TopBarH - side) * 0.5f);
|
||||
wivrn::ui::chip(conn.c_str(), wivrn::ui::chip_style::muted, true, side);
|
||||
}
|
||||
ImGui::EndChild();
|
||||
ImGui::PopStyleColor();
|
||||
wivrn::ui::top_bar(TopBarH, about_picture, top_items);
|
||||
|
||||
// content area, with an equal margin on both sides of the panel
|
||||
const float content_margin = 20;
|
||||
const float content_margin = wivrn::ui::metrics::content_margin;
|
||||
ImGui::SetCursorPos({TabWidth + content_margin, TopBarH});
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 10);
|
||||
@@ -1328,16 +1232,8 @@ std::vector<std::pair<int, XrCompositionLayerQuad>> scenes::lobby::draw_gui(XrTi
|
||||
ImGui::EndChild();
|
||||
ImGui::PopStyleVar(2); // ImGuiStyleVar_FrameRounding, ImGuiStyleVar_WindowPadding
|
||||
|
||||
// Sidebar shares the same transparent background as the rest of the window;
|
||||
// the sections are separated by hairline dividers drawn below.
|
||||
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4{0, 0, 0, 0});
|
||||
ImGui::SetCursorPos({0, TopBarH});
|
||||
wivrn::ui::begin_sidebar(TopBarH, TabWidth);
|
||||
{
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, {16, 16});
|
||||
ImGui::BeginChild("Tabs", {TabWidth, ImGui::GetWindowSize().y - TopBarH}, ImGuiChildFlags_AlwaysUseWindowPadding);
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, {0, 4});
|
||||
|
||||
if (wivrn::ui::nav_item(ICON_FA_COMPUTER, _S("Computers"), current_tab == tab::server_list))
|
||||
current_tab = tab::server_list;
|
||||
|
||||
@@ -1376,23 +1272,10 @@ std::vector<std::pair<int, XrCompositionLayerQuad>> scenes::lobby::draw_gui(XrTi
|
||||
current_tab = tab::licenses;
|
||||
if (wivrn::ui::nav_item(ICON_FA_DOOR_OPEN, _S("Exit"), current_tab == tab::exit))
|
||||
current_tab = tab::exit;
|
||||
|
||||
ImGui::PopStyleVar(); // ImGuiStyleVar_ItemSpacing
|
||||
ImGui::EndChild();
|
||||
ImGui::PopStyleVar(); // ImGuiStyleVar_WindowPadding (Tabs)
|
||||
}
|
||||
ImGui::PopStyleColor(); // ImGuiCol_ChildBg
|
||||
wivrn::ui::end_sidebar();
|
||||
|
||||
// hairline dividers separating the top bar, sidebar and main panel,
|
||||
// following the panel opacity so they dim with the background
|
||||
ImVec4 divider_col = wivrn::ui::current().border;
|
||||
divider_col.w *= wivrn::ui::current().background_alpha;
|
||||
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 + TopBarH}, {win_pos.x + win_size.x, win_pos.y + TopBarH}, divider);
|
||||
dl->AddLine({win_pos.x + TabWidth, win_pos.y + TopBarH}, {win_pos.x + TabWidth, win_pos.y + win_size.y}, divider);
|
||||
wivrn::ui::shell_dividers(TopBarH, TabWidth);
|
||||
|
||||
ImGui::End();
|
||||
ImGui::PopStyleVar(); // ImGuiStyleVar_WindowPadding
|
||||
|
||||
@@ -17,566 +17,62 @@
|
||||
* 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.
|
||||
|
||||
#define IMGUI_DEFINE_MATH_OPERATORS
|
||||
// lobby-side settings pages, shared with the in-stream window (see gui_settings.cpp)
|
||||
|
||||
#include "lobby.h"
|
||||
|
||||
#include "application.h"
|
||||
#include "configuration.h"
|
||||
#include "decoder/decoder.h"
|
||||
#include "render/ui_theme.h"
|
||||
#include "render/ui_widgets.h"
|
||||
#include "scenes/gui_common.h"
|
||||
#include "utils/i18n.h"
|
||||
#include "xr/instance.h"
|
||||
#include "xr/session.h"
|
||||
#include "xr/system.h"
|
||||
|
||||
#include "imgui.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <boost/locale.hpp>
|
||||
#include <cmath>
|
||||
#include <functional>
|
||||
#include <locale>
|
||||
#include <optional>
|
||||
#include <spdlog/fmt/fmt.h>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
|
||||
namespace ui = wivrn::ui;
|
||||
#include "gui_settings.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
constexpr float control_w = ui::metrics::setting_control_width;
|
||||
|
||||
enum class ui_kind
|
||||
wivrn::gui::settings_context lobby_settings_context(xr::instance & instance, xr::session & session, xr::system & system, imgui_context & imgui_ctx, const XrViewConfigurationView & stream_view, std::optional<bool> server_hid_forwarding)
|
||||
{
|
||||
toggle,
|
||||
slider,
|
||||
segmented,
|
||||
combo,
|
||||
};
|
||||
|
||||
// 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.
|
||||
struct setting
|
||||
{
|
||||
const char * id; // stable imgui id
|
||||
std::string label;
|
||||
std::string description;
|
||||
ui_kind ui = ui_kind::toggle;
|
||||
|
||||
std::function<bool()> get_bool;
|
||||
std::function<void(bool)> set_bool;
|
||||
|
||||
std::function<int()> get_int;
|
||||
std::function<void(int)> set_int;
|
||||
int v_min = 0;
|
||||
int v_max = 0;
|
||||
std::string fmt;
|
||||
std::function<std::vector<std::string>()> options;
|
||||
std::string title; // combo modal title
|
||||
|
||||
std::optional<bool> default_bool; // reset target for toggles
|
||||
std::optional<int> default_int; // reset target for slider/segmented/combo
|
||||
|
||||
std::function<bool()> enabled;
|
||||
};
|
||||
|
||||
void render_settings(const char * card_id, const std::vector<setting> & list)
|
||||
{
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ui::metrics::card_item_spacing);
|
||||
ui::begin_card(card_id);
|
||||
|
||||
for (const auto & s: list)
|
||||
{
|
||||
const bool enabled = s.enabled ? s.enabled() : true;
|
||||
ImGui::BeginDisabled(not enabled);
|
||||
|
||||
// stable storage for the reset defaults during this call
|
||||
bool def_b = s.default_bool.value_or(false);
|
||||
int def_i = s.default_int.value_or(0);
|
||||
const bool * dpb = s.default_bool ? &def_b : nullptr;
|
||||
const int * dpi = s.default_int ? &def_i : nullptr;
|
||||
|
||||
const float w = s.ui == ui_kind::toggle ? wivrn::gui::toggle_width() + (s.default_bool ? ui::reset_slot_width() : 0) : control_w;
|
||||
const float label_bottom = ui::setting_label(s.label, s.description, w);
|
||||
|
||||
switch (s.ui)
|
||||
{
|
||||
case ui_kind::toggle: {
|
||||
bool v = s.get_bool();
|
||||
if (ui::toggle(s.id, &v, dpb))
|
||||
s.set_bool(v);
|
||||
break;
|
||||
}
|
||||
case ui_kind::slider: {
|
||||
int v = s.get_int();
|
||||
if (ui::slider_int(s.id, &v, s.v_min, s.v_max, s.fmt.c_str(), {control_w, 0}, dpi))
|
||||
s.set_int(v);
|
||||
break;
|
||||
}
|
||||
case ui_kind::segmented: {
|
||||
const auto opts = s.options();
|
||||
int v = s.get_int();
|
||||
if (ui::segmented(s.id, opts, &v, {control_w, 0}, dpi))
|
||||
s.set_int(v);
|
||||
break;
|
||||
}
|
||||
case ui_kind::combo: {
|
||||
const auto opts = s.options();
|
||||
std::vector<ui::combo_item> items;
|
||||
for (const auto & o: opts)
|
||||
items.push_back({o.c_str()});
|
||||
int v = s.get_int();
|
||||
if (ui::combo(s.id, s.title, items, &v, control_w, dpi))
|
||||
s.set_int(v);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
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).
|
||||
const float pad = std::max(label_bottom - ImGui::GetCursorPosY(), 0.f) + ui::metrics::label_bottom_pad;
|
||||
ImGui::Dummy({0, pad});
|
||||
}
|
||||
|
||||
ui::end_card();
|
||||
ImGui::PopStyleVar();
|
||||
return {
|
||||
.config = application::get_config(),
|
||||
.instance = instance,
|
||||
.session = session,
|
||||
.system = system,
|
||||
.imgui_ctx = imgui_ctx,
|
||||
.recommended_width = stream_view.recommendedImageRectWidth,
|
||||
.recommended_height = stream_view.recommendedImageRectHeight,
|
||||
.in_game = false,
|
||||
.server_hid_forwarding = server_hid_forwarding,
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void scenes::lobby::gui_performance()
|
||||
{
|
||||
auto & config = application::get_config();
|
||||
std::vector<setting> list;
|
||||
|
||||
if (instance.has_extension(XR_FB_DISPLAY_REFRESH_RATE_EXTENSION_NAME) and not session.get_refresh_rates().empty())
|
||||
{
|
||||
const auto rates = session.get_refresh_rates();
|
||||
list.push_back({
|
||||
.id = "##refresh",
|
||||
.label = _("Refresh rate"),
|
||||
.description = _("Select refresh rate based on measured application performance.\nMay cause flicker when a change happens."),
|
||||
.ui = ui_kind::segmented,
|
||||
.get_int = [&config, rates] {
|
||||
for (size_t i = 0; i < rates.size(); ++i)
|
||||
if (rates[i] == config.preferred_refresh_rate)
|
||||
return int(i) + 1;
|
||||
return 0; },
|
||||
.set_int = [this, &config, rates](int v) {
|
||||
if (v == 0)
|
||||
{
|
||||
config.preferred_refresh_rate = 0;
|
||||
config.fps_divider = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
session.set_refresh_rate(rates[v - 1]);
|
||||
config.preferred_refresh_rate = rates[v - 1];
|
||||
}
|
||||
config.save(); },
|
||||
.options = [rates] {
|
||||
std::vector<std::string> opts;
|
||||
opts.push_back(_C("automatic refresh rate", "Auto"));
|
||||
for (float r: rates)
|
||||
opts.push_back(fmt::format("{}", int(r)));
|
||||
return opts; },
|
||||
.default_int = 0,
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
const auto width = stream_view.recommendedImageRectWidth;
|
||||
const auto height = stream_view.recommendedImageRectHeight;
|
||||
list.push_back({
|
||||
.id = "##resolution",
|
||||
.label = _("Render resolution"),
|
||||
.description = fmt::format(_cF("render resolution", "Pixels rendered per eye ({}x{}). Lower to gain performance."), int(width * config.resolution_scale), int(height * config.resolution_scale)),
|
||||
.ui = ui_kind::slider,
|
||||
.get_int = [&config] { return int(std::lround(config.resolution_scale * 100)); },
|
||||
.set_int = [&config](int v) { config.resolution_scale = v / 100.0; config.save(); },
|
||||
.v_min = 50,
|
||||
.v_max = config.extended_config ? 350 : 150,
|
||||
.fmt = "%d%%",
|
||||
.default_int = 100,
|
||||
});
|
||||
}
|
||||
|
||||
list.push_back({
|
||||
.id = "##foveation",
|
||||
.label = _("Foveated encoding"),
|
||||
.description = config.check_feature(feature::eye_gaze)
|
||||
? _("Higher values focus image quality where you look at, improving latency, power efficiency and quality.")
|
||||
: _("Higher values focus image quality at the center, improving latency, power efficiency and quality."),
|
||||
.ui = ui_kind::slider,
|
||||
.get_int = [&config] { return int(std::lround((1 - config.get_stream_scale()) * 100)); },
|
||||
.set_int = [&config](int v) {
|
||||
if (not config.extended_config)
|
||||
v = std::clamp(v, 30, 80);
|
||||
config.set_stream_scale(1 - v * 0.01);
|
||||
config.save(); },
|
||||
.v_min = 0,
|
||||
.v_max = 80,
|
||||
.fmt = "%d%%",
|
||||
.default_int = int(std::lround((1 - (config.check_feature(feature::eye_gaze) ? 0.3 : 0.5)) * 100)),
|
||||
});
|
||||
|
||||
if (instance.has_extension(XR_FB_DISPLAY_REFRESH_RATE_EXTENSION_NAME))
|
||||
{
|
||||
list.push_back({
|
||||
.id = "##spacewarp",
|
||||
.label = _("Application SpaceWarp"),
|
||||
.description = _("Renders at half the refresh rate and synthesises in-between frames. Managed automatically while the refresh rate is set to Auto."),
|
||||
.ui = ui_kind::toggle,
|
||||
.get_bool = [&config] { return config.fps_divider == 2; },
|
||||
.set_bool = [&config](bool v) { config.fps_divider = v ? 2 : 1; config.save(); },
|
||||
.default_bool = false,
|
||||
.enabled = [&config] { return config.preferred_refresh_rate != 0; },
|
||||
});
|
||||
}
|
||||
|
||||
if (instance.has_extension(XR_EXT_PERFORMANCE_SETTINGS_EXTENSION_NAME))
|
||||
{
|
||||
list.push_back({
|
||||
.id = "##high_power",
|
||||
.label = _("High power mode"),
|
||||
.description = _("Increase power usage to allow higher resolution and refresh rate. Drains battery and runs hot."),
|
||||
.ui = ui_kind::toggle,
|
||||
.get_bool = [&config] { return config.high_power_mode; },
|
||||
.set_bool = [&config](bool v) { config.high_power_mode = v; config.save(); },
|
||||
.default_bool = true,
|
||||
});
|
||||
}
|
||||
|
||||
ui::page_header(_S("Performance"), _S("Frame rate, resolution and power draw."));
|
||||
render_settings("##performance", list);
|
||||
wivrn::gui::settings_performance(lobby_settings_context(instance, session, system, *imgui_ctx, stream_view, server_hid_forwarding));
|
||||
}
|
||||
|
||||
void scenes::lobby::gui_streaming()
|
||||
{
|
||||
auto & config = application::get_config();
|
||||
std::vector<setting> list;
|
||||
|
||||
auto codec_name = [](std::optional<wivrn::video_codec> codec) -> std::string {
|
||||
if (not codec)
|
||||
return _C("Codec", "Automatic");
|
||||
switch (*codec)
|
||||
{
|
||||
case wivrn::h264:
|
||||
return _C("Codec", "H.264");
|
||||
case wivrn::h265:
|
||||
return _C("Codec", "HEVC (H.265)");
|
||||
case wivrn::av1:
|
||||
return _C("Codec", "AV1");
|
||||
case wivrn::raw:
|
||||
break;
|
||||
}
|
||||
return _C("Codec", "Automatic");
|
||||
};
|
||||
|
||||
std::vector<wivrn::video_codec> codecs;
|
||||
for (auto c: wivrn::decoder::supported_codecs())
|
||||
if (c != wivrn::raw)
|
||||
codecs.push_back(c);
|
||||
|
||||
list.push_back({
|
||||
.id = "##codec",
|
||||
.label = _("Video codec"),
|
||||
.description = _("How video is compressed before it is sent to the headset."),
|
||||
.ui = ui_kind::combo,
|
||||
.get_int = [&config, codecs] {
|
||||
if (config.codec)
|
||||
for (size_t i = 0; i < codecs.size(); ++i)
|
||||
if (codecs[i] == *config.codec)
|
||||
return int(i) + 1;
|
||||
return 0; },
|
||||
.set_int = [&config, codecs](int v) {
|
||||
config.codec = v == 0 ? std::nullopt : std::optional(codecs[v - 1]);
|
||||
config.save(); },
|
||||
.options = [codecs, codec_name] {
|
||||
std::vector<std::string> opts;
|
||||
opts.push_back(codec_name(std::nullopt));
|
||||
for (auto c: codecs)
|
||||
opts.push_back(codec_name(c));
|
||||
return opts; },
|
||||
.title = _("Video codec"),
|
||||
.default_int = 0,
|
||||
});
|
||||
|
||||
if (config.codec == wivrn::h265 or config.codec == wivrn::av1)
|
||||
{
|
||||
list.push_back({
|
||||
.id = "##ten_bit",
|
||||
.label = _("10-bit color"),
|
||||
.description = _("Higher color precision, supported by HEVC and AV1."),
|
||||
.ui = ui_kind::toggle,
|
||||
.get_bool = [&config] { return config.bit_depth == 10; },
|
||||
.set_bool = [&config](bool v) { config.bit_depth = v ? 10 : 8; config.save(); },
|
||||
.default_bool = true,
|
||||
});
|
||||
}
|
||||
|
||||
const int mb = 1'000'000;
|
||||
list.push_back({
|
||||
.id = "##bitrate",
|
||||
.label = _("Bitrate"),
|
||||
.description = _("Video data rate sent to the headset."),
|
||||
.ui = ui_kind::slider,
|
||||
.get_int = [&config] { return int(config.bitrate_bps / mb); },
|
||||
.set_int = [&config](int v) { config.bitrate_bps = uint32_t(v) * mb; config.save(); },
|
||||
.v_min = 5,
|
||||
.v_max = int(config.max_bitrate() / mb),
|
||||
.fmt = "%d Mbit/s",
|
||||
.default_int = 50,
|
||||
});
|
||||
|
||||
list.push_back({
|
||||
.id = "##stream_gui",
|
||||
.label = _("In-stream window"),
|
||||
.description = _("Enables the configuration window to be shown while the game is streaming.\nIf enabled, the window is activated by pressing both thumbsticks."),
|
||||
.ui = ui_kind::toggle,
|
||||
.get_bool = [&config] { return config.enable_stream_gui; },
|
||||
.set_bool = [&config](bool v) { config.enable_stream_gui = v; config.save(); },
|
||||
.default_bool = true,
|
||||
});
|
||||
|
||||
ui::page_header(_S("Streaming"), _S("How video is encoded and sent to the headset."));
|
||||
render_settings("##streaming", list);
|
||||
wivrn::gui::settings_streaming(lobby_settings_context(instance, session, system, *imgui_ctx, stream_view, server_hid_forwarding));
|
||||
}
|
||||
|
||||
void scenes::lobby::gui_post_processing()
|
||||
{
|
||||
auto & config = application::get_config();
|
||||
std::vector<setting> list;
|
||||
|
||||
if (application::get_openxr_post_processing_supported())
|
||||
{
|
||||
auto flag_name = [](XrCompositionLayerSettingsFlagsFB f) -> std::string {
|
||||
switch (f)
|
||||
{
|
||||
case XR_COMPOSITION_LAYER_SETTINGS_NORMAL_SUPER_SAMPLING_BIT_FB:
|
||||
case XR_COMPOSITION_LAYER_SETTINGS_NORMAL_SHARPENING_BIT_FB:
|
||||
return _C("openxr_post_processing", "Normal");
|
||||
case XR_COMPOSITION_LAYER_SETTINGS_QUALITY_SUPER_SAMPLING_BIT_FB:
|
||||
case XR_COMPOSITION_LAYER_SETTINGS_QUALITY_SHARPENING_BIT_FB:
|
||||
return _C("openxr_post_processing", "Quality");
|
||||
default:
|
||||
return _C("openxr_post_processing", "Disabled");
|
||||
}
|
||||
};
|
||||
|
||||
auto flag_combo = [&](const char * id, std::string label, std::string desc, std::array<XrCompositionLayerSettingsFlagsFB, 3> flags, XrCompositionLayerSettingsFlagsFB configuration::openxr_post_processing_settings::* member) {
|
||||
std::string title = label;
|
||||
list.push_back({
|
||||
.id = id,
|
||||
.label = std::move(label),
|
||||
.description = std::move(desc),
|
||||
.ui = ui_kind::combo,
|
||||
.get_int = [&config, flags, member] {
|
||||
for (size_t i = 0; i < flags.size(); ++i)
|
||||
if (config.openxr_post_processing.*member == flags[i])
|
||||
return int(i);
|
||||
return 0; },
|
||||
.set_int = [&config, flags, member](int v) {
|
||||
config.openxr_post_processing.*member = flags[v];
|
||||
config.save(); },
|
||||
.options = [flags, flag_name] {
|
||||
std::vector<std::string> o;
|
||||
for (auto f: flags)
|
||||
o.push_back(flag_name(f));
|
||||
return o; },
|
||||
.title = std::move(title),
|
||||
.default_int = 0,
|
||||
});
|
||||
};
|
||||
|
||||
flag_combo("##supersampling", _("Supersampling"), _("Reduce flicker for high contrast edges.\nUseful when the input resolution is high compared to the headset display."), {0, XR_COMPOSITION_LAYER_SETTINGS_NORMAL_SUPER_SAMPLING_BIT_FB, XR_COMPOSITION_LAYER_SETTINGS_QUALITY_SUPER_SAMPLING_BIT_FB}, &configuration::openxr_post_processing_settings::super_sampling);
|
||||
flag_combo("##sharpening", _("Sharpening"), _("Improve clarity of high contrast edges and counteract blur.\nUseful when the input resolution is low compared to the headset display."), {0, XR_COMPOSITION_LAYER_SETTINGS_NORMAL_SHARPENING_BIT_FB, XR_COMPOSITION_LAYER_SETTINGS_QUALITY_SHARPENING_BIT_FB}, &configuration::openxr_post_processing_settings::sharpening);
|
||||
}
|
||||
|
||||
ui::page_header(_S("Post-processing"), _S("OpenXR layer supersampling and sharpening."));
|
||||
render_settings("##post_processing", list);
|
||||
wivrn::gui::settings_post_processing(lobby_settings_context(instance, session, system, *imgui_ctx, stream_view, server_hid_forwarding));
|
||||
}
|
||||
|
||||
void scenes::lobby::gui_audio()
|
||||
{
|
||||
auto & config = application::get_config();
|
||||
std::vector<setting> list;
|
||||
|
||||
list.push_back({
|
||||
.id = "##microphone",
|
||||
.label = _("Microphone"),
|
||||
.description = _("Stream the headset microphone to the PC."),
|
||||
.ui = ui_kind::toggle,
|
||||
.get_bool = [&config] { return config.check_feature(feature::microphone); },
|
||||
.set_bool = [&config](bool v) { config.set_feature(feature::microphone, v); },
|
||||
.default_bool = false,
|
||||
});
|
||||
|
||||
list.push_back({
|
||||
.id = "##unprocessed",
|
||||
.label = _("Unprocessed audio"),
|
||||
.description = _("Force disable audio filters, such as noise cancellation."),
|
||||
.ui = ui_kind::toggle,
|
||||
.get_bool = [&config] { return config.mic_unprocessed_audio; },
|
||||
.set_bool = [&config](bool v) { config.mic_unprocessed_audio = v; config.save(); },
|
||||
.default_bool = false,
|
||||
.enabled = [&config] { return config.check_feature(feature::microphone); },
|
||||
});
|
||||
|
||||
ui::page_header(_S("Audio"), _S("Microphone streamed to the PC."));
|
||||
render_settings("##audio", list);
|
||||
wivrn::gui::settings_audio(lobby_settings_context(instance, session, system, *imgui_ctx, stream_view, server_hid_forwarding));
|
||||
}
|
||||
|
||||
void scenes::lobby::gui_devices()
|
||||
{
|
||||
auto & config = application::get_config();
|
||||
std::vector<setting> list;
|
||||
|
||||
list.push_back({
|
||||
.id = "##keyboard",
|
||||
.label = _("Keyboard"),
|
||||
.ui = ui_kind::toggle,
|
||||
.get_bool = [&config] { return config.forward_keyboard; },
|
||||
.set_bool = [&config](bool v) { config.forward_keyboard = v; config.save(); },
|
||||
.default_bool = false,
|
||||
});
|
||||
|
||||
list.push_back({
|
||||
.id = "##mouse",
|
||||
.label = _("Mouse"),
|
||||
.ui = ui_kind::toggle,
|
||||
.get_bool = [&config] { return config.forward_mouse; },
|
||||
.set_bool = [&config](bool v) { config.forward_mouse = v; config.save(); },
|
||||
.default_bool = false,
|
||||
});
|
||||
|
||||
list.push_back({
|
||||
.id = "##gamepad",
|
||||
.label = _("Gamepad"),
|
||||
.ui = ui_kind::toggle,
|
||||
.get_bool = [&config] { return config.forward_gamepad; },
|
||||
.set_bool = [&config](bool v) { config.forward_gamepad = v; config.save(); },
|
||||
.default_bool = false,
|
||||
});
|
||||
|
||||
ui::page_header(_S("Devices"), _S("Forward input devices to the PC."));
|
||||
render_settings("##devices", list);
|
||||
|
||||
if (server_hid_forwarding == false and (config.forward_keyboard or config.forward_mouse or config.forward_gamepad))
|
||||
ui::chip(_("The server does not allow forwarded input devices"), ui::chip_style::warning);
|
||||
wivrn::gui::settings_devices(lobby_settings_context(instance, session, system, *imgui_ctx, stream_view, server_hid_forwarding));
|
||||
}
|
||||
|
||||
void scenes::lobby::gui_tracking()
|
||||
{
|
||||
auto & config = application::get_config();
|
||||
std::vector<setting> list;
|
||||
|
||||
auto feature_toggle = [&](const char * id, std::string label, std::string desc, feature f, bool def) {
|
||||
list.push_back({
|
||||
.id = id,
|
||||
.label = std::move(label),
|
||||
.description = std::move(desc),
|
||||
.ui = ui_kind::toggle,
|
||||
.get_bool = [&config, f] { return config.check_feature(f); },
|
||||
.set_bool = [&config, f](bool v) { config.set_feature(f, v); },
|
||||
.default_bool = def,
|
||||
});
|
||||
};
|
||||
|
||||
if (system.hand_tracking_supported())
|
||||
feature_toggle("##hand", _("Hand tracking"), _("Track your hands for input when controllers are down."), feature::hand_tracking, true);
|
||||
|
||||
if (application::get_eye_gaze_supported())
|
||||
feature_toggle("##eye", _("Eye tracking"), _("Used by foveated encoding to focus quality where you look."), feature::eye_gaze, false);
|
||||
|
||||
if (system.face_tracker_supported() != xr::face_tracker_type::none)
|
||||
feature_toggle("##face", _("Face tracking"), _("Stream facial expressions to the PC."), feature::face_tracking, false);
|
||||
|
||||
const auto body_tracker = system.body_tracker_supported();
|
||||
if (body_tracker != xr::body_tracker_type::none)
|
||||
feature_toggle("##body",
|
||||
_("Body tracking"),
|
||||
body_tracker == xr::body_tracker_type::fb or body_tracker == xr::body_tracker_type::meta
|
||||
? _("Requires 'Hand and body tracking' to be enabled in the Quest movement tracking settings, otherwise body data will be guessed from controller and headset positions.")
|
||||
: _("Stream body joint positions to the PC."),
|
||||
feature::body_tracking,
|
||||
false);
|
||||
|
||||
ui::page_header(_S("Tracking"), _S("Body and input tracking sent to the PC."));
|
||||
render_settings("##tracking", list);
|
||||
|
||||
if (body_tracker != xr::body_tracker_type::none)
|
||||
wivrn::gui::body_tracking_parts(system, *imgui_ctx, config);
|
||||
wivrn::gui::settings_tracking(lobby_settings_context(instance, session, system, *imgui_ctx, stream_view, server_hid_forwarding));
|
||||
}
|
||||
|
||||
void scenes::lobby::gui_system()
|
||||
{
|
||||
auto & config = application::get_config();
|
||||
std::vector<setting> list;
|
||||
|
||||
auto language_name = [](const std::locale & loc = std::locale()) {
|
||||
return boost::locale::pgettext("language selection, replace with the name of the language", "English", loc);
|
||||
};
|
||||
std::vector<std::tuple<std::string, std::locale, std::string>> languages;
|
||||
for (const auto & msg_info: get_locales())
|
||||
{
|
||||
std::string code = msg_info.language;
|
||||
if (not msg_info.country.empty())
|
||||
code += "_" + msg_info.country;
|
||||
std::locale loc(std::locale(), boost::locale::gnu_gettext::create_messages_facet<char>(msg_info));
|
||||
languages.emplace_back(language_name(loc), loc, std::move(code));
|
||||
}
|
||||
std::ranges::sort(languages, [](auto & l, auto & r) { return std::get<0>(l) < std::get<0>(r); });
|
||||
|
||||
list.push_back({
|
||||
.id = "##language",
|
||||
.label = _("Language"),
|
||||
.description = _("Interface language."),
|
||||
.ui = ui_kind::combo,
|
||||
.get_int = [&config, languages] {
|
||||
if (not config.locale.empty())
|
||||
for (size_t i = 0; i < languages.size(); ++i)
|
||||
if (std::get<2>(languages[i]) == config.locale)
|
||||
return int(i) + 1;
|
||||
return 0; },
|
||||
.set_int = [&config, languages](int v) {
|
||||
config.locale = v == 0 ? "" : std::get<2>(languages[v - 1]);
|
||||
config.save();
|
||||
application::instance().load_locale(); },
|
||||
.options = [languages] {
|
||||
std::vector<std::string> opts;
|
||||
opts.push_back(_C("language", "System language"));
|
||||
for (const auto & [lang, loc, code]: languages)
|
||||
opts.push_back(lang);
|
||||
return opts; },
|
||||
.title = _("Language"),
|
||||
.default_int = 0,
|
||||
});
|
||||
|
||||
list.push_back({
|
||||
.id = "##extended",
|
||||
.label = _("Extended configuration"),
|
||||
.description = _("Allows unsafe configuration values, use at your own risk."),
|
||||
.ui = ui_kind::toggle,
|
||||
.get_bool = [&config] { return config.extended_config; },
|
||||
.set_bool = [&config](bool v) { config.extended_config = v; config.save(); },
|
||||
.default_bool = false,
|
||||
});
|
||||
|
||||
ui::page_header(_S("System"), _S("Language and advanced options."));
|
||||
render_settings("##system", list);
|
||||
wivrn::gui::settings_system(lobby_settings_context(instance, session, system, *imgui_ctx, stream_view, server_hid_forwarding));
|
||||
}
|
||||
|
||||
@@ -21,6 +21,8 @@
|
||||
|
||||
#include "lobby.h"
|
||||
|
||||
#include "application.h"
|
||||
#include "configuration.h"
|
||||
#include "render/ui_theme.h"
|
||||
#include "render/ui_widgets.h"
|
||||
#include "utils/i18n.h"
|
||||
@@ -32,9 +34,40 @@
|
||||
|
||||
namespace ui = wivrn::ui;
|
||||
|
||||
void scenes::lobby::apply_theme_settings()
|
||||
{
|
||||
auto & config = application::get_config();
|
||||
|
||||
// preset by name; surfaces only, the accent is applied separately below
|
||||
for (const auto & p: ui::presets())
|
||||
{
|
||||
if (p.name == config.theme_preset)
|
||||
{
|
||||
ui::set_theme(p);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto & swatch: ui::accent_swatches())
|
||||
{
|
||||
if (swatch.name == config.theme_accent)
|
||||
{
|
||||
ui::set_accent(swatch);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ui::theme & theme = ui::current();
|
||||
theme.rounding = config.theme_rounding;
|
||||
theme.card_rounding = config.theme_card_rounding;
|
||||
theme.font_scale = config.theme_font_scale;
|
||||
ui::background_alpha() = config.theme_background_alpha;
|
||||
}
|
||||
|
||||
void scenes::lobby::gui_theme()
|
||||
{
|
||||
ui::theme & theme = ui::current();
|
||||
auto & config = application::get_config();
|
||||
|
||||
ui::page_header(_S("Theme"), _S("Accent color, palette and sizing of the interface."));
|
||||
|
||||
@@ -51,7 +84,11 @@ void scenes::lobby::gui_theme()
|
||||
const bool selected = theme.accent.x == swatch.base.x and theme.accent.y == swatch.base.y and theme.accent.z == swatch.base.z;
|
||||
const auto flags = ImGuiColorEditFlags_NoTooltip | ImGuiColorEditFlags_NoBorder | (selected ? 0 : ImGuiColorEditFlags_NoDragDrop);
|
||||
if (ImGui::ColorButton(swatch.name, swatch.base, flags, {ImGui::GetFrameHeight() * 1.4f, ImGui::GetFrameHeight() * 1.4f}))
|
||||
{
|
||||
ui::set_accent(swatch);
|
||||
config.theme_accent = swatch.name;
|
||||
config.save();
|
||||
}
|
||||
ImGui::SameLine();
|
||||
}
|
||||
ImGui::NewLine();
|
||||
@@ -59,12 +96,19 @@ void scenes::lobby::gui_theme()
|
||||
ui::row_separator();
|
||||
|
||||
// Preset
|
||||
static int preset = 1; // dark_default
|
||||
const auto preset_list = ui::presets();
|
||||
std::vector<ui::combo_item> preset_items;
|
||||
for (const auto & p: preset_list)
|
||||
preset_items.push_back({p.name.c_str()});
|
||||
|
||||
// seed the selection from the saved preset so the box matches what is applied
|
||||
static int preset = [&] {
|
||||
for (int i = 0; i < int(preset_list.size()); ++i)
|
||||
if (preset_list[i].name == config.theme_preset)
|
||||
return i;
|
||||
return 1; // dark_default
|
||||
}();
|
||||
|
||||
static const int preset_default = 1;
|
||||
ui::setting_label(_S("Preset"), _S("Surface and background palette"), control_w);
|
||||
if (ui::combo("##preset", _("Theme preset"), preset_items, &preset, control_w, &preset_default))
|
||||
@@ -77,6 +121,8 @@ void scenes::lobby::gui_theme()
|
||||
theme.accent = keep_accent;
|
||||
theme.accent_hovered = keep_hover;
|
||||
theme.accent_active = keep_active;
|
||||
config.theme_preset = preset_list[preset].name;
|
||||
config.save();
|
||||
}
|
||||
|
||||
ui::row_separator();
|
||||
@@ -86,7 +132,11 @@ void scenes::lobby::gui_theme()
|
||||
int rounding = int(theme.rounding);
|
||||
ui::setting_label(_S("Rounding"), _S("Corner radius of controls"), control_w);
|
||||
if (ui::slider_int("##rounding", &rounding, 0, 20, "%d px", {control_w, 0}, &rounding_default))
|
||||
{
|
||||
theme.rounding = float(rounding);
|
||||
config.theme_rounding = theme.rounding;
|
||||
config.save();
|
||||
}
|
||||
|
||||
ui::row_separator();
|
||||
|
||||
@@ -94,7 +144,11 @@ void scenes::lobby::gui_theme()
|
||||
int card_rounding = int(theme.card_rounding);
|
||||
ui::setting_label(_S("Card rounding"), _S("Corner radius of panels"), control_w);
|
||||
if (ui::slider_int("##card_rounding", &card_rounding, 0, 28, "%d px", {control_w, 0}, &card_rounding_default))
|
||||
{
|
||||
theme.card_rounding = float(card_rounding);
|
||||
config.theme_card_rounding = theme.card_rounding;
|
||||
config.save();
|
||||
}
|
||||
|
||||
ui::row_separator();
|
||||
|
||||
@@ -104,16 +158,24 @@ void scenes::lobby::gui_theme()
|
||||
int font_scale = int(theme.font_scale * 100);
|
||||
ui::setting_label(_S("Text size"), _S("Global font scale"), control_w);
|
||||
if (ui::slider_int("##font_scale", &font_scale, 60, 140, "%d%%", {control_w, 0}, &font_scale_default))
|
||||
{
|
||||
theme.font_scale = float(font_scale) / 100.f;
|
||||
config.theme_font_scale = theme.font_scale;
|
||||
config.save();
|
||||
}
|
||||
|
||||
ui::row_separator();
|
||||
|
||||
// Panel transparency
|
||||
static const int opacity_default = 100;
|
||||
int opacity = int(theme.background_alpha * 100);
|
||||
// Panel transparency, independent of the selected preset
|
||||
static const int opacity_default = 90;
|
||||
int opacity = int(ui::background_alpha() * 100);
|
||||
ui::setting_label(_S("Panel opacity"), _S("Opacity of the panel and card backgrounds"), control_w);
|
||||
if (ui::slider_int("##opacity", &opacity, 20, 100, "%d%%", {control_w, 0}, &opacity_default))
|
||||
theme.background_alpha = float(opacity) / 100.f;
|
||||
{
|
||||
ui::background_alpha() = float(opacity) / 100.f;
|
||||
config.theme_background_alpha = ui::background_alpha();
|
||||
config.save();
|
||||
}
|
||||
|
||||
ui::end_card();
|
||||
}
|
||||
|
||||
@@ -540,6 +540,24 @@ void scenes::stream::on_focused()
|
||||
std::move(vps),
|
||||
image_cache);
|
||||
|
||||
// match the lobby's seasonal wordmark logo
|
||||
{
|
||||
auto t = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
|
||||
auto tm = std::localtime(&t);
|
||||
switch (tm->tm_mon)
|
||||
{
|
||||
case 5:
|
||||
wivrn_logo = imgui_ctx->load_texture("assets://wivrn-pride.ktx2");
|
||||
break;
|
||||
case 11:
|
||||
wivrn_logo = imgui_ctx->load_texture("assets://wivrn-christmas.ktx2");
|
||||
break;
|
||||
default:
|
||||
wivrn_logo = imgui_ctx->load_texture("assets://wivrn.ktx2");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (application::get_config().enable_stream_gui)
|
||||
{
|
||||
plots_toggle_1 = get_action("plots_toggle_1").first;
|
||||
|
||||
@@ -132,6 +132,7 @@ private:
|
||||
uint32_t height;
|
||||
|
||||
std::optional<imgui_context> imgui_ctx;
|
||||
ImTextureID wivrn_logo = 0; // wordmark logo shown in the top bar, like the lobby
|
||||
struct gui_toast
|
||||
{
|
||||
std::string content;
|
||||
@@ -141,6 +142,18 @@ private:
|
||||
static bool is_interactable(stream_tab);
|
||||
bool is_gui_interactable() const;
|
||||
|
||||
// settings sub-page, client-only: the wire stream_tab stays `settings`
|
||||
enum class settings_page
|
||||
{
|
||||
performance,
|
||||
streaming,
|
||||
post_processing,
|
||||
audio,
|
||||
tracking,
|
||||
system,
|
||||
};
|
||||
settings_page current_settings_page = settings_page::performance;
|
||||
|
||||
// Tab currently being displayed
|
||||
stream_tab gui_status = stream_tab::hidden;
|
||||
// Tab that we will switch to if button is pressed
|
||||
|
||||
+220
-175
@@ -23,11 +23,15 @@
|
||||
#include "stream.h"
|
||||
|
||||
#include "application.h"
|
||||
#include "configuration.h"
|
||||
#include "constants.h"
|
||||
#include "gui_common.h"
|
||||
#include "gui_settings.h"
|
||||
#include "imgui.h"
|
||||
#include "imgui_internal.h"
|
||||
#include "implot.h"
|
||||
#include "render/ui_theme.h"
|
||||
#include "render/ui_widgets.h"
|
||||
#include "utils/i18n.h"
|
||||
#include "utils/ranges.h"
|
||||
#include <IconsFontAwesome6.h>
|
||||
@@ -392,90 +396,55 @@ static void send_settings_changed_packet(xr::session & session, wivrn_session *
|
||||
});
|
||||
}
|
||||
|
||||
void scenes::stream::gui_settings(float predicted_display_period)
|
||||
void scenes::stream::gui_settings(float)
|
||||
{
|
||||
const ImGuiStyle & style = ImGui::GetStyle();
|
||||
auto & config = application::get_config();
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(20, 20));
|
||||
|
||||
if (gui::refresh_rate(instance, session, *imgui_ctx, config))
|
||||
send_settings_changed_packet(session, network_session.get(), config);
|
||||
// same pages as the lobby, with in_game enabling the in-stream controls
|
||||
wivrn::gui::settings_context ctx{
|
||||
.config = application::get_config(),
|
||||
.instance = instance,
|
||||
.session = session,
|
||||
.system = system,
|
||||
.imgui_ctx = *imgui_ctx,
|
||||
.recommended_width = width,
|
||||
.recommended_height = height,
|
||||
.in_game = true,
|
||||
.on_streaming_changed = [this] { send_settings_changed_packet(session, network_session.get(), application::get_config()); },
|
||||
.enter_bitrate_adjust = [this] { next_gui_status = stream_tab::bitrate_settings; },
|
||||
.enter_foveation_adjust = [this] { next_gui_status = stream_tab::foveation_settings; },
|
||||
.on_foveation_override_changed = [this] {
|
||||
const auto & config = application::get_config();
|
||||
override_foveation_enable = config.override_foveation_enable;
|
||||
override_foveation_pitch = config.override_foveation_pitch;
|
||||
override_foveation_distance = config.override_foveation_distance;
|
||||
network_session->send_control(from_headset::override_foveation_center{
|
||||
.enabled = override_foveation_enable,
|
||||
.pitch = override_foveation_pitch,
|
||||
.distance = override_foveation_distance,
|
||||
}); },
|
||||
};
|
||||
|
||||
switch (current_settings_page)
|
||||
{
|
||||
const auto text = _("Bitrate:");
|
||||
const auto size = ImGui::CalcTextSize(text.c_str());
|
||||
ImGui::Text("%s", text.c_str());
|
||||
|
||||
ImGui::SameLine(0.f, 10.f);
|
||||
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + (size.y / 4.f) - style.FramePadding.y * 3.f);
|
||||
if (ImGui::Button(fmt::format("{}Mbit/s", config.bitrate_bps / 1'000'000).c_str()))
|
||||
next_gui_status = stream_tab::bitrate_settings;
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
if (ImGui::IsItemHovered())
|
||||
imgui_ctx->tooltip(_("Click to adjust bitrate"));
|
||||
case settings_page::performance:
|
||||
wivrn::gui::settings_performance(ctx);
|
||||
break;
|
||||
case settings_page::streaming:
|
||||
wivrn::gui::settings_streaming(ctx);
|
||||
break;
|
||||
case settings_page::post_processing:
|
||||
wivrn::gui::settings_post_processing(ctx);
|
||||
break;
|
||||
case settings_page::audio:
|
||||
wivrn::gui::settings_audio(ctx);
|
||||
break;
|
||||
case settings_page::tracking:
|
||||
if (wivrn::gui::settings_tracking(ctx))
|
||||
send_settings_changed_packet(session, network_session.get(), ctx.config);
|
||||
break;
|
||||
case settings_page::system:
|
||||
wivrn::gui::settings_system(ctx);
|
||||
break;
|
||||
}
|
||||
|
||||
if (config.check_feature(feature::body_tracking))
|
||||
{
|
||||
if (gui::body_tracking_parts(system, *imgui_ctx, config))
|
||||
send_settings_changed_packet(session, network_session.get(), config);
|
||||
}
|
||||
|
||||
gui::post_processing(*imgui_ctx, config);
|
||||
|
||||
bool send_packet = false;
|
||||
bool save_config = false;
|
||||
ImGui::Text("%s", _S("Foveation center override"));
|
||||
ImGui::Indent();
|
||||
{
|
||||
if (ImGui::Checkbox(_S("Enable"), &override_foveation_enable))
|
||||
{
|
||||
send_packet = true;
|
||||
save_config = true;
|
||||
}
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
ImGui::BeginDisabled(!override_foveation_enable);
|
||||
ImGui::Text("%s", fmt::format(_F("Height {:.1f} deg"), -override_foveation_pitch * 180 / M_PI).c_str());
|
||||
ImGui::Text("%s", fmt::format(_F("Distance {:.2f} m"), override_foveation_distance).c_str());
|
||||
if (ImGui::Button(_S("Default")))
|
||||
{
|
||||
override_foveation_distance = configuration{}.override_foveation_distance;
|
||||
override_foveation_pitch = configuration{}.override_foveation_pitch;
|
||||
send_packet = true;
|
||||
save_config = true;
|
||||
}
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
ImGui::SameLine();
|
||||
|
||||
if (ImGui::Button(_S("Change")))
|
||||
next_gui_status = stream_tab::foveation_settings;
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
ImGui::EndDisabled();
|
||||
}
|
||||
ImGui::Unindent();
|
||||
|
||||
if (send_packet)
|
||||
{
|
||||
network_session->send_control(from_headset::override_foveation_center{
|
||||
.enabled = override_foveation_enable,
|
||||
.pitch = override_foveation_pitch,
|
||||
.distance = override_foveation_distance,
|
||||
});
|
||||
}
|
||||
|
||||
if (save_config)
|
||||
{
|
||||
auto & config = application::get_config();
|
||||
config.override_foveation_enable = override_foveation_enable;
|
||||
config.override_foveation_pitch = override_foveation_pitch;
|
||||
config.override_foveation_distance = override_foveation_distance;
|
||||
config.save();
|
||||
}
|
||||
ImGui::PopStyleVar();
|
||||
}
|
||||
|
||||
void scenes::stream::gui_bitrate_settings(float predicted_display_period)
|
||||
@@ -562,68 +531,77 @@ void scenes::stream::gui_applications()
|
||||
network_session->send_control(from_headset::get_running_applications{});
|
||||
}
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 10);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, {10, 10});
|
||||
ImGui::PushFont(nullptr, constants::gui::font_size_large);
|
||||
CenterTextH(_("Running XR applications:"));
|
||||
ImGui::PopFont();
|
||||
wivrn::ui::page_header(_S("Applications"), _S("Running XR applications on the server."));
|
||||
|
||||
auto apps = running_applications.lock();
|
||||
ImVec2 button_size(ImGui::GetWindowSize().x - ImGui::GetCursorPosX() - 20, 0);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(ImGui::GetStyle().ItemSpacing.x, 20));
|
||||
ImGui::Spacing();
|
||||
std::ranges::sort(apps->applications, [](auto & l, auto & r) {
|
||||
if (l.overlay == r.overlay)
|
||||
return false;
|
||||
return r.overlay;
|
||||
});
|
||||
bool overlay = false;
|
||||
for (const auto & app: apps->applications)
|
||||
|
||||
const float gap = ImGui::GetStyle().ItemSpacing.x;
|
||||
const float ctrl_h = ImGui::GetFrameHeight() * wivrn::ui::metrics::control_height;
|
||||
const std::string stop_label = wivrn::ui::icon_label(ICON_FA_XMARK, _("Stop"));
|
||||
const float stop_w = wivrn::ui::button_width(stop_label);
|
||||
const std::string active_label = wivrn::ui::icon_label(ICON_FA_CIRCLE_CHECK, _("Active"));
|
||||
const ImVec2 active_sz = wivrn::ui::chip_size(active_label);
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, wivrn::ui::metrics::card_item_spacing);
|
||||
wivrn::ui::begin_list_card("##running");
|
||||
{
|
||||
if (app.overlay and not overlay)
|
||||
if (apps->applications.empty())
|
||||
{
|
||||
ImGui::Separator();
|
||||
CenterTextH(_S("Overlays"));
|
||||
overlay = true;
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, wivrn::ui::current().text_muted);
|
||||
ImGui::TextUnformatted(_S("No XR application is currently running."));
|
||||
ImGui::PopStyleColor();
|
||||
}
|
||||
int colors = 1;
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, IM_COL32_BLACK_TRANS);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 0);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(10, 20));
|
||||
if (app.active or app.overlay)
|
||||
{
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, IM_COL32_BLACK_TRANS);
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, IM_COL32_BLACK_TRANS);
|
||||
colors += 2;
|
||||
}
|
||||
ImGui::SetNextItemAllowOverlap();
|
||||
const bool clicked = RadioButtonWithoutCheckBox(
|
||||
std::format("{}{}##{}", app.active ? ICON_FA_CHEVRON_RIGHT " " : " ", app.name, app.id).c_str(),
|
||||
app.active,
|
||||
button_size);
|
||||
if (clicked and not(app.active or app.overlay))
|
||||
{
|
||||
network_session->send_control(from_headset::set_active_application{.id = app.id});
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
}
|
||||
ImGui::PopStyleColor(colors);
|
||||
ImGui::PopStyleVar(2);
|
||||
|
||||
ImGui::SameLine();
|
||||
auto right = ImGui::GetWindowSize().x;
|
||||
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 10);
|
||||
ImGui::SetCursorPosX(right - ImGui::CalcTextSize(ICON_FA_XMARK).x - ImGui::GetStyle().FramePadding.x - 40);
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.8f, 0.2f, 0.2f, 0.40f));
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.8f, 0.2f, 0.2f, 1.00f));
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(1.0f, 0.1f, 0.1f, 1.00f));
|
||||
if (ImGui::Button(std::format(ICON_FA_XMARK "##{}", app.id).c_str()))
|
||||
network_session->send_control(from_headset::stop_application{.id = app.id});
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
ImGui::PopStyleColor(3);
|
||||
bool overlay = false;
|
||||
bool first = true;
|
||||
for (const auto & app: apps->applications)
|
||||
{
|
||||
if (app.overlay and not overlay)
|
||||
{
|
||||
overlay = true;
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, wivrn::ui::current().text_muted);
|
||||
ImGui::TextUnformatted(_S("Overlays"));
|
||||
ImGui::PopStyleColor();
|
||||
first = true;
|
||||
}
|
||||
ImGui::PushID(static_cast<int>(app.id));
|
||||
if (not first)
|
||||
wivrn::ui::row_separator();
|
||||
first = false;
|
||||
|
||||
if (ImGui::IsItemHovered())
|
||||
imgui_ctx->tooltip(_S("Request to quit, may be ignored by the application"));
|
||||
// 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);
|
||||
float x = row.max.x;
|
||||
|
||||
ImGui::SetCursorScreenPos(row.trailing(x, {stop_w, ctrl_h}));
|
||||
if (wivrn::ui::button(stop_label, wivrn::ui::button_style::danger, {stop_w, 0}))
|
||||
network_session->send_control(from_headset::stop_application{.id = app.id});
|
||||
if (ImGui::IsItemHovered())
|
||||
imgui_ctx->tooltip(_S("Request to quit, may be ignored by the application"));
|
||||
x -= stop_w + gap;
|
||||
|
||||
if (app.active)
|
||||
{
|
||||
ImGui::SetCursorScreenPos(row.trailing(x, active_sz));
|
||||
wivrn::ui::chip(active_label, wivrn::ui::chip_style::success);
|
||||
}
|
||||
|
||||
if (row.clicked and interactive)
|
||||
network_session->send_control(from_headset::set_active_application{.id = app.id});
|
||||
|
||||
wivrn::ui::end_list_row();
|
||||
ImGui::PopID();
|
||||
}
|
||||
}
|
||||
ImGui::PopStyleVar(3);
|
||||
wivrn::ui::end_card();
|
||||
ImGui::PopStyleVar();
|
||||
}
|
||||
|
||||
void scenes::stream::gui_toasts()
|
||||
@@ -774,12 +752,29 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte
|
||||
imgui_ctx->layers()[1].position = imgui_ctx->layers()[0].position + imgui_ctx->layers()[0].orientation * constants::lobby::popup_position;
|
||||
}
|
||||
|
||||
const float tab_width = 300;
|
||||
const float tab_width = wivrn::ui::metrics::sidebar_width;
|
||||
const float top_bar_h = wivrn::ui::metrics::top_bar_height;
|
||||
const float content_margin = wivrn::ui::metrics::content_margin;
|
||||
const ImVec2 margin_around_window{50, 50};
|
||||
|
||||
const ImGuiStyle & style = ImGui::GetStyle();
|
||||
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
|
||||
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;
|
||||
style.PopupRounding = wivrn::ui::current().card_rounding;
|
||||
style.FrameRounding = wivrn::ui::current().rounding;
|
||||
style.GrabRounding = wivrn::ui::current().rounding;
|
||||
style.TabRounding = wivrn::ui::current().rounding;
|
||||
style.Colors[ImGuiCol_Text] = wivrn::ui::current().text;
|
||||
style.Colors[ImGuiCol_TextDisabled] = wivrn::ui::current().text_muted;
|
||||
wivrn::ui::set_popup_center(imgui_ctx->layers()[0].vp_center(), float(imgui_ctx->layers()[0].vp_size.y));
|
||||
wivrn::ui::set_hover_haptic([this] { imgui_ctx->vibrate_on_hover(); });
|
||||
wivrn::ui::set_tooltip_hook([this](const char * text) { imgui_ctx->tooltip(text); });
|
||||
|
||||
ImVec2 viewport_size(imgui_ctx->layers()[0].vp_size.x, imgui_ctx->layers()[0].vp_size.y);
|
||||
ImVec2 content_size{viewport_size - ImVec2{tab_width, 0} - margin_around_window * 2};
|
||||
ImVec2 content_center = margin_around_window + content_size / 2 + ImVec2{tab_width, 0};
|
||||
@@ -824,6 +819,13 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 4);
|
||||
}
|
||||
|
||||
// themed translucent background, matching the lobby
|
||||
if (display_tabs)
|
||||
{
|
||||
const wivrn::ui::theme & th = wivrn::ui::current();
|
||||
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4{th.background.x, th.background.y, th.background.z, wivrn::ui::background_alpha()});
|
||||
}
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ChildBorderSize, 0);
|
||||
if (always_auto_resize)
|
||||
{
|
||||
@@ -863,17 +865,28 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte
|
||||
break;
|
||||
|
||||
case stream_tab::stats:
|
||||
ImGui::SetCursorPos({tab_width + 20, 20});
|
||||
ImGui::BeginChild("Main", ImVec2(ImGui::GetWindowSize().x - ImGui::GetCursorPosX(), 0));
|
||||
ImGui::SetCursorPos({tab_width + content_margin, top_bar_h});
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, {20, 20});
|
||||
ImGui::BeginChild("Main", ImVec2(ImGui::GetWindowSize().x - ImGui::GetCursorPosX() - content_margin, 0));
|
||||
ImGui::SetCursorPosY(20);
|
||||
wivrn::ui::page_header(_S("Statistics"), _S("Live streaming performance."));
|
||||
ImGui::BeginChild("plots", {0, 0});
|
||||
gui_performance_metrics();
|
||||
ImGui::EndChild();
|
||||
ImGui::EndChild();
|
||||
ImGui::PopStyleVar();
|
||||
break;
|
||||
|
||||
case stream_tab::settings:
|
||||
ImGui::SetCursorPos({tab_width + 20, 20});
|
||||
ImGui::BeginChild("Main", ImVec2(ImGui::GetWindowSize().x - ImGui::GetCursorPosX(), 0));
|
||||
ImGui::SetCursorPos({tab_width + content_margin, top_bar_h});
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, {20, 20});
|
||||
ImGui::BeginChild("Main", ImVec2(ImGui::GetWindowSize().x - ImGui::GetCursorPosX() - content_margin, 0));
|
||||
ImGui::SetCursorPosY(20);
|
||||
gui_settings(predicted_display_period * 1.e-9f);
|
||||
ImGui::Dummy(ImVec2(0, 20));
|
||||
ScrollWhenDragging();
|
||||
ImGui::EndChild();
|
||||
ImGui::PopStyleVar();
|
||||
break;
|
||||
|
||||
case stream_tab::bitrate_settings:
|
||||
@@ -885,10 +898,15 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte
|
||||
break;
|
||||
|
||||
case stream_tab::applications:
|
||||
ImGui::SetCursorPos({tab_width + 20, 20});
|
||||
ImGui::BeginChild("Main", ImVec2(ImGui::GetWindowSize().x - ImGui::GetCursorPosX(), 0));
|
||||
ImGui::SetCursorPos({tab_width + content_margin, top_bar_h});
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, {20, 20});
|
||||
ImGui::BeginChild("Main", ImVec2(ImGui::GetWindowSize().x - ImGui::GetCursorPosX() - content_margin, 0));
|
||||
ImGui::SetCursorPosY(20);
|
||||
gui_applications();
|
||||
ImGui::Dummy(ImVec2(0, 20));
|
||||
ScrollWhenDragging();
|
||||
ImGui::EndChild();
|
||||
ImGui::PopStyleVar();
|
||||
break;
|
||||
|
||||
case stream_tab::application_launcher:
|
||||
@@ -900,18 +918,42 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte
|
||||
|
||||
if (display_tabs)
|
||||
{
|
||||
ImGui::PushStyleColor(ImGuiCol_ChildBg, IM_COL32(0, 0, 0, 255));
|
||||
ImGui::SetCursorPos(style.WindowPadding);
|
||||
// top bar: logo left; battery, connection status and window controls right
|
||||
// (close/disconnect have no quick-toggles: those only apply on connection)
|
||||
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()))
|
||||
top_items.push_back({wivrn::ui::chip_width(bat->label, false, side),
|
||||
[bat = *bat, side] { wivrn::ui::chip(bat.label, bat.style, false, side); }});
|
||||
const std::string conn = _("Connected");
|
||||
top_items.push_back({wivrn::ui::chip_width(conn, true, side),
|
||||
[conn, side] { wivrn::ui::chip(conn, wivrn::ui::chip_style::success, true, side); }});
|
||||
top_items.push_back({side, [this] {
|
||||
const float s = ImGui::GetFrameHeight() * wivrn::ui::metrics::control_height;
|
||||
if (wivrn::ui::icon_button(ICON_FA_XMARK, {s, s}, false, _S("Close")))
|
||||
next_gui_status = stream_tab::hidden;
|
||||
}});
|
||||
// disconnect asks for confirmation; OpenPopup/confirm_modal share the window id stack
|
||||
bool request_disconnect = false;
|
||||
top_items.push_back({side, [&request_disconnect] {
|
||||
const float s = ImGui::GetFrameHeight() * wivrn::ui::metrics::control_height;
|
||||
if (wivrn::ui::icon_button(ICON_FA_DOOR_OPEN, {s, s}, false, _S("Disconnect")))
|
||||
request_disconnect = true;
|
||||
}});
|
||||
wivrn::ui::top_bar(top_bar_h, wivrn_logo, top_items);
|
||||
|
||||
if (request_disconnect)
|
||||
ImGui::OpenPopup("confirm disconnect");
|
||||
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);
|
||||
{
|
||||
ImGui::BeginChild("Tabs", {tab_width, ImGui::GetContentRegionMax().y - ImGui::GetWindowContentRegionMin().y});
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(10, 10));
|
||||
|
||||
auto target = next_gui_status.load();
|
||||
RadioButtonWithoutCheckBox(ICON_FA_LIST " " + _("Applications"), target, stream_tab::applications, {tab_width, 0});
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
if (RadioButtonWithoutCheckBox(ICON_FA_ROCKET " " + _("Start"), target, stream_tab::application_launcher, {tab_width, 0}))
|
||||
wivrn::ui::nav_section(_S("STREAM"));
|
||||
if (wivrn::ui::nav_item(ICON_FA_LIST, _S("Applications"), gui_status == stream_tab::applications))
|
||||
next_gui_status = stream_tab::applications;
|
||||
if (wivrn::ui::nav_item(ICON_FA_ROCKET, _S("Start"), false))
|
||||
{
|
||||
apps.reset();
|
||||
network_session->send_control(from_headset::get_application_list{
|
||||
@@ -919,40 +961,43 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte
|
||||
.country = application::get_messages_info().country,
|
||||
.variant = application::get_messages_info().variant,
|
||||
});
|
||||
next_gui_status = stream_tab::application_launcher;
|
||||
}
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
if (wivrn::ui::nav_item(ICON_FA_COMPUTER, _S("Statistics"), gui_status == stream_tab::stats))
|
||||
next_gui_status = stream_tab::stats;
|
||||
|
||||
RadioButtonWithoutCheckBox(ICON_FA_GEARS " " + _("Settings"), target, stream_tab::settings, {tab_width, 0});
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
wivrn::ui::nav_section(_S("SETTINGS"));
|
||||
auto settings_item = [&](const char * icon, const std::string & label, settings_page page) {
|
||||
if (wivrn::ui::nav_item(icon, label, gui_status == stream_tab::settings and current_settings_page == page))
|
||||
{
|
||||
current_settings_page = page;
|
||||
next_gui_status = stream_tab::settings;
|
||||
}
|
||||
};
|
||||
settings_item(ICON_FA_GAUGE_HIGH, _S("Performance"), settings_page::performance);
|
||||
settings_item(ICON_FA_TOWER_BROADCAST, _S("Streaming"), settings_page::streaming);
|
||||
settings_item(ICON_FA_WAND_MAGIC_SPARKLES, _S("Post-processing"), settings_page::post_processing);
|
||||
settings_item(ICON_FA_VOLUME_HIGH, _S("Audio"), settings_page::audio);
|
||||
settings_item(ICON_FA_LOCATION_CROSSHAIRS, _S("Tracking"), settings_page::tracking);
|
||||
settings_item(ICON_FA_GEARS, _S("System"), settings_page::system);
|
||||
|
||||
RadioButtonWithoutCheckBox(ICON_FA_COMPUTER " " + _("Stats"), target, stream_tab::stats, {tab_width, 0});
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
// 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);
|
||||
|
||||
int n_items_at_end = 4;
|
||||
ImGui::SetCursorPosY(ImGui::GetContentRegionMax().y - n_items_at_end * ImGui::GetCurrentContext()->FontSize - (n_items_at_end * 2) * style.FramePadding.y - (n_items_at_end - 1) * style.ItemSpacing.y - style.WindowPadding.y);
|
||||
|
||||
RadioButtonWithoutCheckBox(ICON_FA_CHART_LINE " " + _("Statistics overlay"), target, stream_tab::overlay_only, {tab_width, 0});
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
RadioButtonWithoutCheckBox(ICON_FA_MINIMIZE " " + _("Compact view"), target, stream_tab::compact, {tab_width, 0});
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
RadioButtonWithoutCheckBox(ICON_FA_XMARK " " + _("Close"), target, stream_tab::hidden, {tab_width, 0});
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
bool dummy = false;
|
||||
if (RadioButtonWithoutCheckBox(ICON_FA_DOOR_OPEN " " + _("Disconnect"), dummy, true, {tab_width, 0}))
|
||||
exit();
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
ImGui::PopStyleVar(); // ImGuiStyleVar_FramePadding
|
||||
ImGui::EndChild();
|
||||
next_gui_status = target;
|
||||
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))
|
||||
next_gui_status = stream_tab::compact;
|
||||
}
|
||||
ImGui::PopStyleColor(); // ImGuiCol_ChildBg
|
||||
wivrn::ui::end_sidebar();
|
||||
|
||||
wivrn::ui::shell_dividers(top_bar_h, tab_width);
|
||||
}
|
||||
ImGui::End();
|
||||
ImGui::PopStyleVar(2); // ImGuiStyleVar_ChildBorderSize, ImGuiStyleVar_WindowPadding
|
||||
if (display_tabs)
|
||||
ImGui::PopStyleColor(); // ImGuiCol_WindowBg
|
||||
|
||||
auto layers = imgui_ctx->end_frame();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user