mirror of https://github.com/wayvr-org/wayvr.git
fix weird range slider behavior
This commit is contained in:
parent
a3b1fdcd0d
commit
3f858e5e2f
|
|
@ -20,7 +20,9 @@ use wgui::{
|
||||||
use wlx_common::{
|
use wlx_common::{
|
||||||
config_io,
|
config_io,
|
||||||
openxr_actions::{OneOrMany, OpenXrInputAction, OpenXrInputProfile, load_xr_input_profiles},
|
openxr_actions::{OneOrMany, OpenXrInputAction, OpenXrInputProfile, load_xr_input_profiles},
|
||||||
openxr_bindings_schema::{XrControllerProfile, XrInputComponent, XrInputSide, XrInputSubpathKind},
|
openxr_bindings_schema::{
|
||||||
|
DEFAULT_BUTTON_THRESHOLDS, XrControllerProfile, XrInputComponent, XrInputSide, XrInputSubpathKind,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
|
@ -39,7 +41,7 @@ enum Task {
|
||||||
Save,
|
Save,
|
||||||
Cancel,
|
Cancel,
|
||||||
OpenContextMenu(glam::Vec2, Vec<context_menu::Cell>),
|
OpenContextMenu(glam::Vec2, Vec<context_menu::Cell>),
|
||||||
UpdateThreshold(Rc<str>, XrInputSide, f32, f32),
|
UpdateThreshold(Rc<str>, XrInputSide, usize, f32),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Params<'a> {
|
pub struct Params<'a> {
|
||||||
|
|
@ -88,17 +90,18 @@ impl ViewTrait for View {
|
||||||
blueprint: context_menu::Blueprint::Cells(cells),
|
blueprint: context_menu::Blueprint::Cells(cells),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
Task::UpdateThreshold(action_name, side, lo, hi) => {
|
Task::UpdateThreshold(action_name, side, i, val) => {
|
||||||
log::warn!("UpdateThreshold {action_name} {lo:.2} {hi:.2}");
|
|
||||||
|
|
||||||
let cur_profile = &mut self.profiles[self.cur_profile_idx];
|
let cur_profile = &mut self.profiles[self.cur_profile_idx];
|
||||||
let action_mut = get_action_mut(cur_profile, &*action_name);
|
let action_mut = get_action_mut(cur_profile, &*action_name);
|
||||||
|
|
||||||
if matches!(side, XrInputSide::Right) {
|
let threshold = if matches!(side, XrInputSide::Right) {
|
||||||
action_mut.threshold_right = Some([lo, hi]);
|
action_mut.threshold_right.get_or_insert(DEFAULT_BUTTON_THRESHOLDS)
|
||||||
} else {
|
} else {
|
||||||
action_mut.threshold_left = Some([lo, hi]);
|
action_mut.threshold_left.get_or_insert(DEFAULT_BUTTON_THRESHOLDS)
|
||||||
}
|
};
|
||||||
|
|
||||||
|
threshold[i] = val;
|
||||||
|
log::warn!("UpdateThreshold {action_name} {side:?} {threshold:?}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -552,7 +555,7 @@ fn threshold_slider(
|
||||||
let id = mp.idx.to_string();
|
let id = mp.idx.to_string();
|
||||||
mp.idx += 1;
|
mp.idx += 1;
|
||||||
|
|
||||||
let current = current.unwrap_or([0.5, 0.7]);
|
let current = current.unwrap_or(DEFAULT_BUTTON_THRESHOLDS);
|
||||||
|
|
||||||
let mut params: HashMap<Rc<str>, Rc<str>> = HashMap::new();
|
let mut params: HashMap<Rc<str>, Rc<str>> = HashMap::new();
|
||||||
params.insert(Rc::from("id"), Rc::from(id.as_ref()));
|
params.insert(Rc::from("id"), Rc::from(id.as_ref()));
|
||||||
|
|
@ -571,9 +574,9 @@ fn threshold_slider(
|
||||||
let tasks = mp.tasks.clone();
|
let tasks = mp.tasks.clone();
|
||||||
move |_common, e| {
|
move |_common, e| {
|
||||||
if matches!(e.index, wgui::components::slider::ValueIndex::Primary) {
|
if matches!(e.index, wgui::components::slider::ValueIndex::Primary) {
|
||||||
tasks.push(Task::UpdateThreshold(action.clone(), side, e.value, current[1]));
|
tasks.push(Task::UpdateThreshold(action.clone(), side, 0, e.value));
|
||||||
} else {
|
} else {
|
||||||
tasks.push(Task::UpdateThreshold(action.clone(), side, current[0], e.value));
|
tasks.push(Task::UpdateThreshold(action.clone(), side, 1, e.value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ use openxr::{self as xr, Quaternionf, Vector2f, Vector3f};
|
||||||
use wlx_common::{
|
use wlx_common::{
|
||||||
config::HandsfreePointer,
|
config::HandsfreePointer,
|
||||||
openxr_actions::{OneOrMany, load_xr_input_profiles},
|
openxr_actions::{OneOrMany, load_xr_input_profiles},
|
||||||
|
openxr_bindings_schema::DEFAULT_BUTTON_THRESHOLDS,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
|
@ -128,7 +129,7 @@ impl CustomClickAction {
|
||||||
single,
|
single,
|
||||||
double,
|
double,
|
||||||
triple,
|
triple,
|
||||||
threshold: [0.5, 0.7],
|
threshold: DEFAULT_BUTTON_THRESHOLDS,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use strum::{AsRefStr, EnumProperty, EnumString};
|
use strum::{AsRefStr, EnumProperty, EnumString};
|
||||||
|
|
||||||
|
pub const DEFAULT_BUTTON_THRESHOLDS: [f32; 2] = [0.5, 0.7];
|
||||||
|
|
||||||
pub struct XrControllerProfile {
|
pub struct XrControllerProfile {
|
||||||
pub display_name: &'static str,
|
pub display_name: &'static str,
|
||||||
pub profile_id: &'static str,
|
pub profile_id: &'static str,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue