Skip to content

Commit

Permalink
Implement new winit 0.30 gestures
Browse files Browse the repository at this point in the history
This has only been tested on Wayland against
rust-windowing/winit#3656 and allows much nicer
interactions when using a touchpad.

The values have been chosen based on what felt pleasant to use on my
Thinkpad x280, I haven’t given it much thought otherwise, and I expect
other touchpads would feel different.
  • Loading branch information
linkmauve committed Apr 27, 2024
1 parent de56694 commit 86b613a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/controls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,12 @@ impl OrbitControls {
self.pan_offset.y -= distance
}

pub fn pan_both(&mut self, delta: PhysicalPosition<f32>) {
self.pan_offset.x += delta.x;
self.pan_offset.y += delta.y;
self.update();
}

// Processes input received from a mouse scroll-wheel event. Only requires input on the vertical wheel-axis
pub fn process_mouse_scroll(&mut self, mut yoffset: f32) {
yoffset *= ZOOM_SENSITIVITY;
Expand Down
15 changes: 15 additions & 0 deletions src/viewer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,21 @@ impl winit::application::ApplicationHandler<()> for GltfViewer {
self.orbit_controls.process_mouse_scroll(lines * 3.0);
self.window.as_ref().unwrap().request_redraw();
}
WindowEvent::PanGesture { delta, .. } => {
let mut delta = delta;
delta.x /= 1024.;
delta.y /= 1024.;
self.orbit_controls.pan_both(delta);
self.window.as_ref().unwrap().request_redraw();
}
WindowEvent::PinchGesture { delta, .. } => {
self.orbit_controls.process_mouse_scroll(1024. * delta as f32);
self.window.as_ref().unwrap().request_redraw();
}
WindowEvent::RotationGesture { delta, .. } => {
self.orbit_controls.rotate_object(-delta * std::f32::consts::PI / 180.);
self.window.as_ref().unwrap().request_redraw();
}
WindowEvent::KeyboardInput { event, .. } => {
let pressed = match event.state {
Pressed => true,
Expand Down

0 comments on commit 86b613a

Please sign in to comment.