Use combo box with multiple selection for virtual body trackers
This commit is contained in:
@@ -20,22 +20,13 @@
|
||||
#include "gui_common.h"
|
||||
|
||||
#include "android/battery.h"
|
||||
#include "application.h"
|
||||
#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"
|
||||
#include "xr/instance.h"
|
||||
#include "xr/session.h"
|
||||
#include "xr/system.h"
|
||||
|
||||
#include "imgui.h"
|
||||
#include <IconsFontAwesome6.h>
|
||||
#include <cmath>
|
||||
#include <spdlog/fmt/fmt.h>
|
||||
|
||||
namespace wivrn::gui
|
||||
{
|
||||
@@ -44,66 +35,6 @@ float toggle_width()
|
||||
return ImGui::GetFrameHeight() * ui::metrics::control_height * ui::metrics::toggle_aspect;
|
||||
}
|
||||
|
||||
bool body_tracking_parts(
|
||||
xr::system & system,
|
||||
imgui_context & imgui_ctx,
|
||||
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)
|
||||
return false;
|
||||
|
||||
const std::array body_parts{
|
||||
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;
|
||||
|
||||
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)
|
||||
continue;
|
||||
|
||||
const auto underlying = std::to_underlying(bit);
|
||||
bool enabled = config.body_part_mask & underlying;
|
||||
|
||||
const float label_bottom = ui::setting_label(name, "", toggle_width());
|
||||
if (ui::toggle(id, &enabled))
|
||||
{
|
||||
if (enabled)
|
||||
config.body_part_mask |= underlying;
|
||||
else
|
||||
config.body_part_mask &= ~underlying;
|
||||
|
||||
config.save();
|
||||
changed = true;
|
||||
}
|
||||
|
||||
// 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::EndDisabled();
|
||||
|
||||
ui::end_card();
|
||||
ImGui::PopStyleVar();
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
std::optional<battery_indicator> battery_status_indicator(XrTime now)
|
||||
{
|
||||
#ifdef __ANDROID__
|
||||
|
||||
@@ -46,12 +46,6 @@ bool refresh_rate(
|
||||
imgui_context & imgui_ctx,
|
||||
configuration & config);
|
||||
|
||||
bool body_tracking_parts(
|
||||
xr::system & system,
|
||||
imgui_context & imgui_ctx,
|
||||
configuration & config,
|
||||
bool in_game);
|
||||
|
||||
bool post_processing(
|
||||
imgui_context & imgui_ctx,
|
||||
configuration & config);
|
||||
|
||||
@@ -68,6 +68,7 @@ enum class ui_kind
|
||||
slider,
|
||||
segmented,
|
||||
combo,
|
||||
combo_multi,
|
||||
button,
|
||||
};
|
||||
|
||||
@@ -86,6 +87,10 @@ struct setting
|
||||
std::function<void(int)> set_int;
|
||||
int v_min = 0;
|
||||
int v_max = 0;
|
||||
|
||||
std::function<bool(int)> get_multi;
|
||||
std::function<void(int, bool)> set_multi;
|
||||
|
||||
std::string fmt;
|
||||
std::function<std::vector<std::string>()> options;
|
||||
std::string title; // combo modal title
|
||||
@@ -93,8 +98,9 @@ struct setting
|
||||
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::optional<bool> default_bool; // reset target for toggles
|
||||
std::optional<int> default_int; // reset target for slider/segmented/combo
|
||||
std::optional<std::vector<char>> default_multi; // reset target for multicombo
|
||||
|
||||
std::function<bool()> enabled;
|
||||
std::string disabled_tooltip; // shown on a disabled row
|
||||
@@ -115,6 +121,7 @@ void render_settings(const wivrn::gui::settings_context & ctx, const char * card
|
||||
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 std::vector<char> * dpm = s.default_multi ? &s.default_multi.value() : nullptr;
|
||||
|
||||
const ImVec2 row_min = ImGui::GetCursorScreenPos();
|
||||
|
||||
@@ -152,6 +159,23 @@ void render_settings(const wivrn::gui::settings_context & ctx, const char * card
|
||||
s.set_int(v);
|
||||
break;
|
||||
}
|
||||
case ui_kind::combo_multi: {
|
||||
const auto opts = s.options();
|
||||
std::vector<ui::combo_item> items;
|
||||
std::vector<char> selected;
|
||||
for (const auto & o: opts)
|
||||
items.push_back({o.c_str()});
|
||||
for (size_t i = 0; i < items.size(); ++i)
|
||||
selected.push_back(s.get_multi(i));
|
||||
|
||||
if (ui::combo_multi(s.id, s.title, s.title, items, &selected, control_w, dpm))
|
||||
{
|
||||
// TODO only set the changed value
|
||||
for (size_t i = 0; i < items.size(); ++i)
|
||||
s.set_multi(i, selected[i]);
|
||||
}
|
||||
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();
|
||||
@@ -594,6 +618,29 @@ bool settings_tracking(const settings_context & ctx)
|
||||
feature_toggle("##face", _("Face tracking"), _("Stream facial expressions to the PC."), feature::face_tracking, false);
|
||||
|
||||
const auto body_tracker = ctx.system.body_tracker_supported();
|
||||
|
||||
std::vector<char> body_parts_default;
|
||||
std::vector<std::string> body_parts_names;
|
||||
std::vector<from_headset::body_part_mask> body_parts_bit;
|
||||
for (const auto & [bit, name]: {
|
||||
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")),
|
||||
})
|
||||
{
|
||||
if (body_tracker == xr::body_tracker_type::fb and bit > from_headset::body_part_mask::hip)
|
||||
break;
|
||||
body_parts_default.push_back(1);
|
||||
body_parts_names.push_back(name);
|
||||
body_parts_bit.push_back(bit);
|
||||
}
|
||||
|
||||
bool changed = false;
|
||||
if (body_tracker != xr::body_tracker_type::none)
|
||||
{
|
||||
list.push_back({
|
||||
@@ -609,15 +656,34 @@ bool settings_tracking(const settings_context & ctx)
|
||||
.enabled = [&ctx] { return not ctx.in_game; },
|
||||
.disabled_tooltip = disconnect_tip,
|
||||
});
|
||||
|
||||
list.push_back({
|
||||
.id = "##body_tracking_parts",
|
||||
.label = _("Virtual body trackers"),
|
||||
.description = _("Create virtual tracker devices."),
|
||||
.ui = ui_kind::combo_multi,
|
||||
.get_multi = [&config, &body_parts_bit](int index) {
|
||||
const auto underlying = std::to_underlying(body_parts_bit[index]);
|
||||
return config.body_part_mask & underlying; },
|
||||
.set_multi = [&config, &body_parts_bit, &changed](int index, bool value) {
|
||||
const auto underlying = std::to_underlying(body_parts_bit[index]);
|
||||
if (value)
|
||||
config.body_part_mask |= underlying;
|
||||
else
|
||||
config.body_part_mask &= ~underlying;
|
||||
changed = true; },
|
||||
.options = [&body_parts_names]() { return body_parts_names; },
|
||||
.title = _("Virtual body trackers"),
|
||||
.default_multi = body_parts_default,
|
||||
.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;
|
||||
return changed;
|
||||
}
|
||||
|
||||
void settings_system(const settings_context & ctx)
|
||||
|
||||
Reference in New Issue
Block a user