Overhaul settings UI

This commit is contained in:
ahsanswr
2026-07-26 17:24:36 +02:00
committed by Guillaume Meunier
parent 45710151aa
commit a5b1b6dbeb
12 changed files with 1548 additions and 1480 deletions
+36 -52
View File
@@ -23,6 +23,8 @@
#include "configuration.h"
#include "constants.h"
#include "render/imgui_impl.h"
#include "render/ui_theme.h"
#include "render/ui_widgets.h"
#include "utils/i18n.h"
#include "wivrn_packets.h"
@@ -35,6 +37,10 @@
namespace wivrn::gui
{
float toggle_width()
{
return ImGui::GetFrameHeight() * ui::metrics::control_height * ui::metrics::toggle_aspect;
}
std::string rate_label(float rate, uint32_t divider)
{
@@ -130,71 +136,49 @@ bool body_tracking_parts(
return false;
const std::array body_parts{
std::make_pair(from_headset::body_part_mask::chest, _C("virtual body tracker selection", "Chest")),
std::make_pair(from_headset::body_part_mask::left_elbow, _C("virtual body tracker selection", "Left elbow")),
std::make_pair(from_headset::body_part_mask::right_elbow, _C("virtual body tracker selection", "Right elbow")),
std::make_pair(from_headset::body_part_mask::hip, _C("virtual body tracker selection", "Hip")),
std::make_pair(from_headset::body_part_mask::left_knee, _C("virtual body tracker selection", "Left knee")),
std::make_pair(from_headset::body_part_mask::right_knee, _C("virtual body tracker selection", "Right knee")),
std::make_pair(from_headset::body_part_mask::left_foot, _C("virtual body tracker selection", "Left foot")),
std::make_pair(from_headset::body_part_mask::right_foot, _C("virtual body tracker selection", "Right foot")),
std::make_tuple(from_headset::body_part_mask::chest, "##chest", _C("virtual body tracker selection", "Chest")),
std::make_tuple(from_headset::body_part_mask::left_elbow, "##left_elbow", _C("virtual body tracker selection", "Left elbow")),
std::make_tuple(from_headset::body_part_mask::right_elbow, "##right_elbow", _C("virtual body tracker selection", "Right elbow")),
std::make_tuple(from_headset::body_part_mask::hip, "##hip", _C("virtual body tracker selection", "Hip")),
std::make_tuple(from_headset::body_part_mask::left_knee, "##left_knee", _C("virtual body tracker selection", "Left knee")),
std::make_tuple(from_headset::body_part_mask::right_knee, "##right_knee", _C("virtual body tracker selection", "Right knee")),
std::make_tuple(from_headset::body_part_mask::left_foot, "##left_foot", _C("virtual body tracker selection", "Left foot")),
std::make_tuple(from_headset::body_part_mask::right_foot, "##right_foot", _C("virtual body tracker selection", "Right foot")),
};
bool changed = false;
bool button_pressed = ImGui::ArrowButton("##OpenBodyPartMenu", ImGuiDir_Down);
ImGui::SameLine(0.f, ImGui::GetStyle().ItemInnerSpacing.x);
ImGui::Text("%s", _S("Virtual body trackers"));
if (button_pressed)
ImGui::OpenPopup("body part menu");
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, {12, 10});
ui::begin_card("##body_tracking_parts");
const auto & popup_layer = imgui_ctx.layers()[1];
const glm::vec2 popup_layer_center = popup_layer.vp_origin + popup_layer.vp_size / 2;
ImGui::SetNextWindowPos({popup_layer_center.x, popup_layer_center.y}, ImGuiCond_Always, ImVec2(0.5f, 0.5f));
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, constants::style::window_padding);
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, constants::style::window_rounding);
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, constants::style::window_border_size);
if (ImGui::BeginPopupModal("body part menu", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_AlwaysAutoResize))
for (const auto & [bit, id, name]: body_parts)
{
const float height = ImGui::GetFrameHeight();
const ImVec2 size(height, height);
if (body_tracker == xr::body_tracker_type::fb and bit > from_headset::body_part_mask::hip)
continue;
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));
ImGui::SetCursorPosX(ImGui::GetWindowContentRegionMax().x - size.x);
if (ImGui::Button("X", size))
ImGui::CloseCurrentPopup();
imgui_ctx.vibrate_on_hover();
ImGui::PopStyleColor(3); // ImGuiCol_Button, ImGuiCol_ButtonHovered, ImGuiCol_ButtonActive
const auto underlying = std::to_underlying(bit);
bool enabled = config.body_part_mask & underlying;
for (const auto & [bit, name]: body_parts)
const float label_bottom = ui::setting_label(name, "", toggle_width());
if (ui::toggle(id, &enabled))
{
if (body_tracker == xr::body_tracker_type::fb and bit > from_headset::body_part_mask::hip)
continue;
if (enabled)
config.body_part_mask |= underlying;
else
config.body_part_mask &= ~underlying;
const auto underlying = std::to_underlying(bit);
bool enabled = config.body_part_mask & underlying;
if (ImGui::Checkbox(name.c_str(), &enabled))
{
if (enabled)
{
config.body_part_mask |= underlying;
}
else
{
config.body_part_mask &= ~underlying;
}
config.save();
changed = true;
imgui_ctx.vibrate_on_hover();
}
config.save();
changed = true;
}
ImGui::EndPopup();
// 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});
}
ImGui::PopStyleVar(3); // ImGuiStyleVar_WindowPadding, ImGuiStyleVar_WindowRounding, ImGuiStyleVar_WindowBorderSize
ui::end_card();
ImGui::PopStyleVar();
return changed;
}
+2
View File
@@ -50,5 +50,7 @@ bool post_processing(
imgui_context & imgui_ctx,
configuration & config);
float toggle_width();
} // namespace gui
} // namespace wivrn
+13 -4
View File
@@ -118,11 +118,16 @@ class lobby : public scene_impl<lobby>
{
first_run,
server_list,
settings,
performance,
streaming,
post_processing,
audio,
devices,
tracking,
system,
customize,
components,
#if WIVRN_CLIENT_DEBUG_MENU
components,
debug,
#endif
about,
@@ -218,14 +223,18 @@ class lobby : public scene_impl<lobby>
std::pair<entt::entity, int> debug_primitive_to_highlight = {entt::null, 0};
#endif
void draw_features_status(XrTime predicted_display_time);
void gui_connecting(locked_notifiable<pin_request_data> & request);
void gui_enter_pin(locked_notifiable<pin_request_data> & request);
void gui_connected(XrTime predicted_display_time);
void gui_disconnected();
void gui_server_list();
void gui_new_server();
void gui_settings();
void gui_performance();
void gui_streaming();
void gui_audio();
void gui_devices();
void gui_tracking();
void gui_system();
void gui_post_processing();
void gui_customize(XrTime predicted_display_time);
void gui_components();
File diff suppressed because it is too large Load Diff
+4
View File
@@ -21,6 +21,8 @@
#include "lobby.h"
#if WIVRN_CLIENT_DEBUG_MENU
#include "render/ui_theme.h"
#include "render/ui_widgets.h"
@@ -357,3 +359,5 @@ void scenes::lobby::gui_components()
ImGui::PopStyleVar(); // ImGuiStyleVar_ItemSpacing
}
#endif // WIVRN_CLIENT_DEBUG_MENU
+137 -289
View File
@@ -28,6 +28,8 @@
#include "imspinner.h"
#include "render/image_writer.h"
#include "render/scene_renderer.h"
#include "render/ui_theme.h"
#include "render/ui_widgets.h"
#include "utils/files.h"
#include "utils/i18n.h"
#include "utils/json_string.h"
@@ -337,278 +339,141 @@ void scenes::lobby::download_environment_list()
scenes::lobby::environment_item_action scenes::lobby::environment_item(environment_model & model, bool download_screenshot)
{
namespace ui = wivrn::ui;
environment_item_action action = environment_item_action::none;
ImGuiWindow * window = ImGui::GetCurrentWindow();
const ImGuiStyle & style = ImGui::GetStyle();
bool local = std::ranges::contains(local_environments, model.name, &environment_model::name);
const bool local = std::ranges::contains(local_environments, model.name, &environment_model::name);
static std::unordered_map<std::string, float> expanded_height;
float width = ImGui::GetWindowSize().x - ImGui::GetCurrentWindow()->ScrollbarSizes.x - 2 * ImGui::GetCurrentWindow()->WindowPadding.x;
ImVec2 screenshot_size{256, 256};
ImVec2 default_selectable_size{
width,
screenshot_size.y + 2 * style.FramePadding.y // Screenshot size including padding
// + style.ItemSpacing.y // Spacing
// + ImGui::GetFontSize() + 2 * style.FramePadding.y // Progress bar height
};
ImVec2 selectable_size = default_selectable_size;
bool expanded = false;
if (auto iter = expanded_height.find(model.gltf_url); iter != expanded_height.end())
// lazily load the screenshot texture
if (model.screenshot == 0)
{
selectable_size.y = std::max(selectable_size.y, iter->second);
expanded = true;
}
ImTextureID screenshot = model.screenshot;
if (ImRect{window->DC.CursorPos, window->DC.CursorPos + selectable_size}.Overlaps(window->ClipRect))
{
if (screenshot == 0)
if (download_screenshot)
{
if (download_screenshot)
if (model.screenshot_url != "" and not try_get_download_handle(model.screenshot_url))
{
if (model.screenshot_url != "" and not try_get_download_handle(model.screenshot_url))
{
spdlog::info("Downloading {}", model.screenshot_url);
download(model.screenshot_url,
[this, url = model.screenshot_url](libcurl::curl_handle & handle) {
try
{
auto png = handle.get_response_bytes();
auto screenshot = imgui_ctx->load_texture(png);
for (auto & model: downloadable_environments)
{
if (model.screenshot_url == url)
{
model.screenshot = screenshot;
model.screenshot_png = std::vector<std::byte>{png.begin(), png.end()};
}
}
}
catch (std::exception & e)
{
spdlog::warn("Cannot load image from {}: {}", handle.get_url(), e.what());
for (auto & model: downloadable_environments)
{
if (model.screenshot_url == url)
{
model.screenshot_url = "";
model.screenshot = default_environment_screenshot;
}
}
}
});
}
spdlog::info("Downloading {}", model.screenshot_url);
download(model.screenshot_url, [this, url = model.screenshot_url](libcurl::curl_handle & handle) {
try
{
auto png = handle.get_response_bytes();
auto tex = imgui_ctx->load_texture(png);
for (auto & m: downloadable_environments)
if (m.screenshot_url == url)
{
m.screenshot = tex;
m.screenshot_png = std::vector<std::byte>{png.begin(), png.end()};
}
}
catch (std::exception & e)
{
spdlog::warn("Cannot load image from {}: {}", handle.get_url(), e.what());
for (auto & m: downloadable_environments)
if (m.screenshot_url == url)
{
m.screenshot_url = "";
m.screenshot = default_environment_screenshot;
}
}
});
}
else if (model.local_screenshot_path != "" and std::filesystem::exists(model.local_screenshot_path))
}
else if (model.local_screenshot_path != "" and std::filesystem::exists(model.local_screenshot_path))
{
try
{
try
{
spdlog::info("Loading {}", model.local_screenshot_path.native());
screenshot = model.screenshot = imgui_ctx->load_texture(utils::mapped_file{model.local_screenshot_path});
}
catch (std::exception & e)
{
spdlog::warn("Cannot load screenshot {}: {}", model.local_screenshot_path.native(), e.what());
std::error_code ec;
std::filesystem::remove(model.local_screenshot_path, ec); // Ignore errors
model.local_screenshot_path = ""; // Avoid subsequent loading errors
model.screenshot = default_environment_screenshot;
}
model.screenshot = imgui_ctx->load_texture(utils::mapped_file{model.local_screenshot_path});
}
catch (std::exception & e)
{
spdlog::warn("Cannot load screenshot {}: {}", model.local_screenshot_path.native(), e.what());
std::error_code ec;
std::filesystem::remove(model.local_screenshot_path, ec);
model.local_screenshot_path = "";
model.screenshot = default_environment_screenshot;
}
}
}
auto backup_cursor = ImGui::GetCursorScreenPos();
const auto & config = application::get_config();
bool selected = (config.passthrough_enabled and model.local_gltf_path == "") or
(not config.passthrough_enabled and config.environment_model == model.local_gltf_path);
const bool selected = (config.passthrough_enabled and model.local_gltf_path == "") or
(not config.passthrough_enabled and config.environment_model == model.local_gltf_path);
ImGui::SetNextItemAllowOverlap();
// Use ImGuiSelectableFlags_AllowDoubleClick to have ImGuiButtonFlags_PressedOnClickRelease in ImGui::Selectable
if (ImGui::Selectable(("##" + model.gltf_url).c_str(), &selected, ImGuiSelectableFlags_AllowDoubleClick, selectable_size))
{
if (local)
action = environment_item_action::use_model;
else
action = environment_item_action::download_model;
}
imgui_ctx->vibrate_on_hover();
auto end_cursor = ImGui::GetCursorScreenPos();
// Remove the height of the progress bar if a transfer is in progress
float text_clip_height = selectable_size.y + style.FramePadding.y;
if (auto handle = try_get_download_handle(model.gltf_url); handle and handle->get_state() == libcurl::state::transferring)
text_clip_height -= ImGui::GetFontSize() + 2 * style.FramePadding.y + style.ItemSpacing.y;
// Display the screenshot
ImGui::SetCursorScreenPos(backup_cursor + ImVec2(style.FramePadding.x, 0));
ImGui::Image(screenshot ? screenshot : default_environment_screenshot, screenshot_size);
ImGui::PushClipRect(backup_cursor, backup_cursor + ImVec2(selectable_size.x, text_clip_height), true);
float indent = screenshot_size.x + style.FramePadding.x + 2 * style.ImageBorderSize + style.ItemSpacing.x;
// Display the text
std::pair<std::string, ImVec2> text_name;
std::pair<std::string, ImVec2> text_author;
std::pair<std::string, ImVec2> text_description;
std::pair<std::string, ImVec2> text_filesize;
text_name.first = model.builtin ? _(model.name.c_str()) : model.name;
// subtitle: author / description / size, one per line
std::string subtitle;
auto add_line = [&](const std::string & s) {
if (s.empty())
return;
if (not subtitle.empty())
subtitle += "\n";
subtitle += s;
};
if (model.author != "")
text_author.first = fmt::format(_F("Author: {}"), model.author);
add_line(fmt::format(_F("Author: {}"), model.author));
if (model.description != "")
text_description.first = model.description;
add_line(model.builtin ? std::string(_(model.description.c_str())) : model.description);
if (not model.builtin)
text_filesize.first = fmt::format(_F("Size: {:.1f} MB"), model.size * 1.0e-6);
add_line(fmt::format(_F("Size: {:.1f} MB"), model.size * 1.0e-6));
const float wrap_width = selectable_size.x - indent - style.FramePadding.x;
const char * icon = model.local_gltf_path == "" ? ICON_FA_VIDEO : (model.builtin ? ICON_FA_TABLE_CELLS : ICON_FA_IMAGE);
const std::string title = model.builtin ? std::string(_(model.name.c_str())) : model.name;
// clang-format off
text_name.second = ImGui::CalcTextSize(text_name.first.data(), text_name.first.data() + text_name.first.size(), false, wrap_width);
text_author.second = ImGui::CalcTextSize(text_author.first.data(), text_author.first.data() + text_author.first.size(), false, wrap_width);
text_description.second = ImGui::CalcTextSize(text_description.first.data(), text_description.first.data() + text_description.first.size(), false, wrap_width);
text_filesize.second = ImGui::CalcTextSize(text_filesize.first.data(), text_filesize.first.data() + text_filesize.first.size(), false, wrap_width);
// clang-format on
ImGui::PushID(model.gltf_url.c_str());
const float bh = ImGui::GetFrameHeight() * ui::metrics::control_height;
auto handle = try_get_download_handle(model.gltf_url);
const bool transferring = handle and handle->get_state() == libcurl::state::transferring;
ImGui::SetCursorScreenPos(backup_cursor);
// measure the trailing control so the row body click area can exclude it
const std::string active_l = std::string(ICON_FA_CHECK " ") + _("Active");
const ImVec2 active_ts = ImGui::CalcTextSize(active_l.c_str());
const float active_w = active_ts.x + ui::metrics::chip_padding.x * 2;
float trailing = 0;
if (selected)
trailing = active_w + ui::metrics::list_row_pad;
else if (transferring or (local and not model.builtin))
trailing = bh + ui::metrics::list_row_pad;
ImVec2 text_pos = backup_cursor + ImVec2(indent, 0);
float text_height = 0;
const auto row = ui::begin_list_row("##env", icon, model.screenshot, title, subtitle, selected, trailing);
const float row_h = row.max.y - row.min.y;
if (row.clicked and not selected)
action = local ? environment_item_action::use_model : environment_item_action::download_model;
ImGui::RenderTextWrapped(text_pos, text_name.first.data(), text_name.first.data() + text_name.first.size(), wrap_width);
text_height += text_name.second.y + style.ItemSpacing.y;
const float x = row.max.x;
if (text_author.first != "")
if (selected)
{
ImGui::RenderTextWrapped(text_pos + ImVec2(0, text_height), text_author.first.data(), text_author.first.data() + text_author.first.size(), wrap_width);
text_height += text_author.second.y + style.ItemSpacing.y;
const float ch = active_ts.y + ui::metrics::chip_padding.y * 2;
ImGui::SetCursorScreenPos({x - active_w, row.min.y + (row_h - ch) * 0.5f});
ui::chip(active_l, ui::chip_style::success);
}
if (text_description.first != "")
else if (transferring)
{
ImGui::RenderTextWrapped(text_pos + ImVec2(0, text_height), text_description.first.data(), text_description.first.data() + text_description.first.size(), wrap_width);
text_height += text_description.second.y + style.ItemSpacing.y;
ImGui::SetCursorScreenPos({x - bh, row.min.y + (row_h - bh) * 0.5f});
if (ui::icon_button(ICON_FA_STOP, {bh, bh}, false, _S("Cancel")))
handle->cancel();
}
if (text_filesize.first != "")
else if (local and not model.builtin)
{
ImGui::RenderTextWrapped(text_pos + ImVec2(0, text_height), text_filesize.first.data(), text_filesize.first.data() + text_filesize.first.size(), wrap_width);
text_height += text_filesize.second.y + style.ItemSpacing.y;
}
ImGui::PopClipRect();
// Display the expand/collapse button
if (text_height > default_selectable_size.y - 2 * style.FramePadding.y)
{
const char * button_text = expanded ? ICON_FA_CHEVRON_UP : ICON_FA_CHEVRON_DOWN;
auto expand_size = ImGui::CalcTextSize(button_text) + style.FramePadding * 2.0f;
float radius = std::max(expand_size.x, expand_size.y) / 2;
ImGui::SetCursorScreenPos(ImVec2(
backup_cursor.x + selectable_size.x / 2 - radius,
backup_cursor.y + selectable_size.y + style.FramePadding.y - radius));
// Triple hash so that the button text is not used to compute the button ID and
// avoid vibrating the controller when the text changes
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, radius);
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0, 0, 0, 0));
if (ImGui::Button((button_text + ("###expand-" + model.gltf_url)).c_str(), ImVec2(radius * 2, radius * 2)))
{
if (expanded)
expanded_height.erase(model.gltf_url);
else
expanded_height[model.gltf_url] = text_height + 2 * style.FramePadding.y;
}
imgui_ctx->vibrate_on_hover();
ImGui::PopStyleColor();
ImGui::PopStyleVar(); // ImGuiStyleVar_FrameRounding
}
// Display the delete button
if (local and not model.builtin)
{
auto delete_size = ImGui::CalcTextSize(ICON_FA_TRASH) + style.FramePadding * 2;
ImGui::SetCursorScreenPos(ImVec2(
backup_cursor.x + width - style.FramePadding.x - delete_size.x,
backup_cursor.y));
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((ICON_FA_TRASH "##delete-" + model.name).c_str()))
ImGui::SetCursorScreenPos({x - bh, row.min.y + (row_h - bh) * 0.5f});
if (ui::icon_button(ICON_FA_TRASH, {bh, bh}, false, _S("Delete this model")))
action = environment_item_action::delete_model;
if (ImGui::IsItemHovered())
imgui_ctx->tooltip(_("Delete this model"));
imgui_ctx->vibrate_on_hover();
ImGui::PopStyleColor(3);
}
// Display the download progress
else if (auto handle = try_get_download_handle(model.gltf_url))
// surface download errors the way the original did
if (handle)
{
switch (handle->get_state())
if (handle->get_state() == libcurl::state::error)
{
case libcurl::state::transferring: {
ImVec2 cancel_size = ImGui::CalcTextSize(ICON_FA_STOP) + style.FramePadding * 2;
ImGui::SetCursorScreenPos(ImVec2(
backup_cursor.x + screenshot_size.x + style.FramePadding.x + style.ItemSpacing.x,
backup_cursor.y + selectable_size.y - (ImGui::GetFontSize() + 2 * style.FramePadding.y)));
float progress_width = width - cancel_size.x - screenshot_size.x - 2 * style.FramePadding.x - 2 * style.ItemSpacing.x;
if (handle->get_content_length() > 0)
ImGui::ProgressBar(handle->get_progress() / (float)handle->get_content_length(), {progress_width, 0});
else
ImGui::ProgressBar(-ImGui::GetTime(), {progress_width, 0}); // Indeterminate progress bar
ImGui::SameLine();
if (ImGui::Button((ICON_FA_STOP "##" + model.name).c_str()))
handle->cancel();
imgui_ctx->vibrate_on_hover();
break;
}
case libcurl::state::error:
if (handle->get_curl_code() == CURLE_HTTP_RETURNED_ERROR)
{
spdlog::error("HTTP error {} when downloading {}", handle->get_response_code(), handle->get_url());
load_environment_status = fmt::format(
_F("HTTP error {} when downloading {}"),
handle->get_response_code(),
handle->get_url());
}
else
{
spdlog::error("Curl error when downloading {}: {}", handle->get_url(), curl_easy_strerror(handle->get_curl_code()));
load_environment_status = fmt::format(
_F("Curl error when downloading {}\n{}: {}"),
handle->get_url(),
magic_enum::enum_name(handle->get_curl_code()),
curl_easy_strerror(handle->get_curl_code()));
}
handle->reset();
break;
case libcurl::state::cancelled:
handle->reset();
break;
case libcurl::state::cancelling:
case libcurl::state::reset:
case libcurl::state::done:
break;
if (handle->get_curl_code() == CURLE_HTTP_RETURNED_ERROR)
load_environment_status = fmt::format(_F("HTTP error {} when downloading {}"), handle->get_response_code(), handle->get_url());
else
load_environment_status = fmt::format(_F("Curl error when downloading {}\n{}: {}"), handle->get_url(), magic_enum::enum_name(handle->get_curl_code()), curl_easy_strerror(handle->get_curl_code()));
handle->reset();
}
else if (handle->get_state() == libcurl::state::cancelled)
handle->reset();
}
ImGui::SetCursorScreenPos(end_cursor);
ImGui::Dummy({});
ui::end_list_row();
ImGui::PopID();
return action;
}
@@ -640,46 +505,20 @@ void scenes::lobby::environment_list(std::vector<environment_model> & models, bo
ImGui::EndDisabled();
}
const auto & popup_layer = imgui_ctx->layers()[1];
const glm::vec2 popup_layer_center = popup_layer.vp_origin + popup_layer.vp_size / 2;
ImGui::SetNextWindowPos({popup_layer_center.x, popup_layer_center.y}, ImGuiCond_Always, ImVec2(0.5f, 0.5f));
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, constants::style::window_padding);
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, constants::style::window_rounding);
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, constants::style::window_border_size);
if (ImGui::BeginPopupModal("confirm delete model", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_AlwaysAutoResize))
if (environment_to_be_deleted)
{
ImGui::Text("%s", fmt::format(_F("Really delete {}?"), environment_to_be_deleted->name).c_str());
const auto & style = ImGui::GetStyle();
auto cancel_text = _("Cancel");
auto delete_text = _("Delete");
auto cancel_size = ImGui::CalcTextSize(cancel_text.c_str()) + style.FramePadding * 2.0f;
auto delete_size = ImGui::CalcTextSize(delete_text.c_str()) + style.FramePadding * 2.0f;
ImGui::SetCursorPosX(ImGui::GetWindowContentRegionMax().x - cancel_size.x - style.ItemSpacing.x - delete_size.x);
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(delete_text.c_str()))
const std::string msg = fmt::format(_F("Permanently delete {}?"), environment_to_be_deleted->name);
switch (wivrn::ui::confirm_modal("confirm delete model", _("Delete environment"), msg, _("Delete"), _("Cancel"), true))
{
delete_environment(*environment_to_be_deleted);
environment_to_be_deleted = nullptr;
ImGui::CloseCurrentPopup();
case 1:
delete_environment(*environment_to_be_deleted);
environment_to_be_deleted = nullptr;
break;
case -1:
environment_to_be_deleted = nullptr;
break;
}
imgui_ctx->vibrate_on_hover();
ImGui::PopStyleColor(3);
ImGui::SameLine();
if (ImGui::Button(cancel_text.c_str()))
{
environment_to_be_deleted = nullptr;
ImGui::CloseCurrentPopup();
}
imgui_ctx->vibrate_on_hover();
ImGui::EndPopup();
}
ImGui::PopStyleVar(3); // ImGuiStyleVar_WindowPadding, ImGuiStyleVar_WindowRounding, ImGuiStyleVar_WindowBorderSize
}
void scenes::lobby::popup_load_environment(XrTime predicted_display_time)
@@ -810,27 +649,36 @@ void scenes::lobby::gui_customize(XrTime predicted_display_time)
{
auto & config = application::get_config();
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, {20, 20});
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, {10, 10});
namespace ui = wivrn::ui;
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, {0, 0});
ImGui::BeginChild("environment list", ImGui::GetWindowSize() - ImGui::GetCursorPos() - ImVec2(0, ImGui::GetFontSize() + 80));
ui::page_header(_S("Customize"), _S("Choose the environment your panels float in."));
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, {12, 10});
ui::begin_card("##environments");
environment_list(local_environments, false);
ScrollWhenDragging();
ImGui::EndChild();
ImGui::PopStyleVar();
ui::end_card();
if (ImGui::Button(_S("Download more environments")))
// Get more environments
ui::begin_card("##get_more");
{
download_environment_list();
ImGui::OpenPopup("download environment model");
const float bh = ImGui::GetFrameHeight() * ui::metrics::control_height;
const std::string browse = std::string(ICON_FA_UP_RIGHT_FROM_SQUARE " ") + _("Browse");
const float bw = ImGui::CalcTextSize(browse.c_str()).x + ui::metrics::button_padding.x * 2;
const auto row = ui::begin_list_row("##getmore", ICON_FA_IMAGES, 0, _S("Get more environments"), _S("Download community-made spaces from the WiVRn dashboard on your PC."), false, bw + ui::metrics::list_row_pad);
const float row_h = row.max.y - row.min.y;
ImGui::SetCursorScreenPos({row.max.x - bw, row.min.y + (row_h - bh) * 0.5f});
if (ui::button(browse, ui::button_style::secondary, {bw, 0}))
{
download_environment_list();
ImGui::OpenPopup("download environment model");
}
ui::end_list_row();
ui::end_card();
}
imgui_ctx->vibrate_on_hover();
ImGui::SameLine();
if (ImGui::Button(_S("Open local glTF model")))
if (ui::button(_S("Open local glTF model"), ui::button_style::secondary))
lobby_file_picker_future = lobby_file_picker.open();
imgui_ctx->vibrate_on_hover();
const auto & popup_layer = imgui_ctx->layers()[1];
const glm::vec2 popup_layer_center = popup_layer.vp_origin + popup_layer.vp_size / 2;
@@ -952,5 +800,5 @@ void scenes::lobby::gui_customize(XrTime predicted_display_time)
// ImGui::SliderFloat("Environment elevation", &lobby_node.position.y, -3, 3, "%.3f");
// imgui_ctx->vibrate_on_hover();
ImGui::PopStyleVar(2); // ImGuiStyleVar_ItemSpacing, ImGuiStyleVar_FramePadding
ImGui::PopStyleVar(); // ImGuiStyleVar_ItemSpacing
}
+582
View File
@@ -0,0 +1,582 @@
/*
* 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.
#define IMGUI_DEFINE_MATH_OPERATORS
#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;
namespace
{
constexpr float control_w = 480;
enum class ui_kind
{
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, {12, 10});
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();
}
} // 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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}