Skip to content

Commit fa23246

Browse files
committed
fix: enable touch drag scroll for mobile picker
1 parent c117d77 commit fa23246

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

vizmat-core/src/ui/picker.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use gloo::utils::window;
99
use web_sys::Event;
1010

1111
use super::{
12-
themed_button_bg, CatalogLoadChannel, HudButton, HudButtonLabel, ThemeMode, UiTheme,
13-
DEFAULT_STRUCTURE_PATH,
12+
themed_button_bg, CatalogLoadChannel, HudButton, HudButtonLabel, ThemeMode, TouchGestureState,
13+
UiTheme, DEFAULT_STRUCTURE_PATH,
1414
};
1515

1616
#[derive(Component)]
@@ -646,8 +646,17 @@ pub(crate) fn structure_picker_scroll(
646646
scroll_nodes: Query<Entity, With<StructurePickerResultsScroll>>,
647647
mut scroll_positions: Query<&mut ScrollPosition>,
648648
parents: Query<&ChildOf>,
649+
touch_gesture_state: Res<TouchGestureState>,
649650
keyboard_input: Res<ButtonInput<KeyCode>>,
650651
) {
652+
let picker_hovered = scroll_nodes.iter().any(|scroll_root| {
653+
hover_map.iter().any(|(_, pointer_map)| {
654+
pointer_map
655+
.iter()
656+
.any(|(hovered, _)| is_descendant_or_self(*hovered, scroll_root, &parents))
657+
})
658+
});
659+
651660
for mouse_wheel in mouse_wheel_events.read() {
652661
let (mut dx, mut dy) = match mouse_wheel.unit {
653662
MouseScrollUnit::Line => (mouse_wheel.x * 12.0, mouse_wheel.y * 12.0),
@@ -682,6 +691,16 @@ pub(crate) fn structure_picker_scroll(
682691
}
683692
}
684693
}
694+
695+
if picker_hovered && touch_gesture_state.rotate.length_squared() > 0.0004 {
696+
for scroll_root in scroll_nodes.iter() {
697+
if let Ok(mut scroll_position) = scroll_positions.get_mut(scroll_root) {
698+
scroll_position.offset_x -= touch_gesture_state.rotate.x;
699+
scroll_position.offset_y -= touch_gesture_state.rotate.y;
700+
break;
701+
}
702+
}
703+
}
685704
}
686705

687706
fn is_descendant_or_self(mut entity: Entity, ancestor: Entity, parents: &Query<&ChildOf>) -> bool {

0 commit comments

Comments
 (0)