1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-01 06:10:06 -04:00

Implement trackpad pinch-to-zoom for plots in egui_web (#333)

This adds a new `zoom_delta` to input.
This is hooked up to ctrl-scroll on egui_web and egui_glium.

Browsers convert trackpad pinch gestures to ctrl-scroll,
so this means you can not pinch-to-zoom plots (on trackpad).

In the future we can support multitouch pinch-to-zoom via the same
`InputState::zoom_factor()` function
This commit is contained in:
Emil Ernerfeldt
2021-04-25 17:04:34 +02:00
committed by GitHub
parent 7f0689e566
commit c2744a1437
8 changed files with 72 additions and 29 deletions

View File

@@ -163,15 +163,26 @@ pub fn input_to_egui(
}
}
WindowEvent::MouseWheel { delta, .. } => {
match delta {
let mut delta = match delta {
glutin::event::MouseScrollDelta::LineDelta(x, y) => {
let line_height = 24.0; // TODO
input_state.raw.scroll_delta = vec2(x, y) * line_height;
let line_height = 8.0; // magic value!
vec2(x, y) * line_height
}
glutin::event::MouseScrollDelta::PixelDelta(delta) => {
// Actually point delta
input_state.raw.scroll_delta = vec2(delta.x as f32, delta.y as f32);
vec2(delta.x as f32, delta.y as f32) / pixels_per_point
}
};
if cfg!(target_os = "macos") {
// This is still buggy in winit despite
// https://github.com/rust-windowing/winit/issues/1695 being closed
delta.x *= -1.0;
}
if input_state.raw.modifiers.ctrl {
// Treat as zoom instead:
input_state.raw.zoom_delta *= (delta.y / 200.0).exp();
} else {
input_state.raw.scroll_delta += delta;
}
}
_ => {