fix(input): don't limit to closest handler
This commit is contained in:
@@ -9,7 +9,10 @@ use crate::nodes::{
|
|||||||
spatial::Spatial,
|
spatial::Spatial,
|
||||||
};
|
};
|
||||||
use glam::vec3;
|
use glam::vec3;
|
||||||
use std::sync::{Arc, Weak};
|
use std::{
|
||||||
|
collections::VecDeque,
|
||||||
|
sync::{Arc, Weak},
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct CaptureManager {
|
pub struct CaptureManager {
|
||||||
@@ -64,11 +67,12 @@ pub fn find_closest_capture(
|
|||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// sorts them greatest to least distance (so you can pop off the closest ones easily)
|
||||||
pub fn get_sorted_handlers(
|
pub fn get_sorted_handlers(
|
||||||
method: &InputMethod,
|
method: &InputMethod,
|
||||||
distance_calculator: DistanceCalculator,
|
distance_calculator: DistanceCalculator,
|
||||||
) -> Vec<Arc<InputHandler>> {
|
) -> Vec<(Arc<InputHandler>, f32)> {
|
||||||
INPUT_HANDLER_REGISTRY
|
let mut handlers = INPUT_HANDLER_REGISTRY
|
||||||
.get_valid_contents()
|
.get_valid_contents()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter(|handler| handler.spatial.node().is_some_and(|node| node.enabled()))
|
.filter(|handler| handler.spatial.node().is_some_and(|node| node.enabled()))
|
||||||
@@ -81,19 +85,9 @@ pub fn get_sorted_handlers(
|
|||||||
})
|
})
|
||||||
.filter_map(|handler| {
|
.filter_map(|handler| {
|
||||||
distance_calculator(&method.spatial, &method.data.lock(), &handler.field)
|
distance_calculator(&method.spatial, &method.data.lock(), &handler.field)
|
||||||
.map(|distance| (vec![handler], distance))
|
.map(|distance| (handler, distance))
|
||||||
})
|
})
|
||||||
.filter(|(_, distance)| *distance > 0.0)
|
.collect::<Vec<_>>();
|
||||||
.reduce(|(mut handlers_a, distance_a), (handlers_b, distance_b)| {
|
handlers.sort_by(|(_, dist_a), (_, dist_b)| dist_a.partial_cmp(dist_b).unwrap());
|
||||||
if (distance_a - distance_b).abs() < 0.001 {
|
handlers
|
||||||
handlers_a.extend(handlers_b);
|
|
||||||
(handlers_a, distance_a)
|
|
||||||
} else if distance_a < distance_b {
|
|
||||||
(handlers_a, distance_a)
|
|
||||||
} else {
|
|
||||||
(handlers_b, distance_b)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.map(|(handlers, _)| handlers)
|
|
||||||
.unwrap_or_default()
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -146,8 +146,18 @@ impl MousePointer {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let sorted_handlers = get_sorted_handlers(&self.pointer, distance_calculator);
|
let mut handlers = get_sorted_handlers(&self.pointer, distance_calculator);
|
||||||
self.pointer.set_handler_order(sorted_handlers.iter());
|
let first_distance = handlers
|
||||||
|
.first()
|
||||||
|
.map(|(_, distance)| *distance)
|
||||||
|
.unwrap_or(std::f32::NEG_INFINITY);
|
||||||
|
|
||||||
|
self.pointer.set_handler_order(
|
||||||
|
handlers
|
||||||
|
.iter()
|
||||||
|
.filter(|(handler, distance)| (distance - first_distance).abs() <= 0.001)
|
||||||
|
.map(|(handler, _)| handler),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn send_keyboard_input(
|
pub fn send_keyboard_input(
|
||||||
|
|||||||
@@ -133,6 +133,7 @@ impl SkController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let sorted_handlers = get_sorted_handlers(&self.input, distance_calculator);
|
let sorted_handlers = get_sorted_handlers(&self.input, distance_calculator);
|
||||||
self.input.set_handler_order(sorted_handlers.iter());
|
self.input
|
||||||
|
.set_handler_order(sorted_handlers.iter().map(|(handler, _)| handler));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -179,7 +179,8 @@ impl SkHand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let sorted_handlers = get_sorted_handlers(&self.input, distance_calculator);
|
let sorted_handlers = get_sorted_handlers(&self.input, distance_calculator);
|
||||||
self.input.set_handler_order(sorted_handlers.iter());
|
self.input
|
||||||
|
.set_handler_order(sorted_handlers.iter().map(|(handler, _)| handler));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl Drop for SkHand {
|
impl Drop for SkHand {
|
||||||
|
|||||||
Reference in New Issue
Block a user