mirror of
https://github.com/emilk/egui.git
synced 2026-08-30 21:30:03 -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:
@@ -963,13 +963,20 @@ fn install_canvas_events(runner_ref: &AppRunnerRef) -> Result<(), JsValue> {
|
||||
canvas_size_in_points(runner_ref.0.lock().canvas_id()).y
|
||||
}
|
||||
web_sys::WheelEvent::DOM_DELTA_LINE => {
|
||||
24.0 // TODO: tweak this
|
||||
8.0 // magic value!
|
||||
}
|
||||
_ => 1.0,
|
||||
};
|
||||
|
||||
runner_lock.input.raw.scroll_delta.x -= scroll_multiplier * event.delta_x() as f32;
|
||||
runner_lock.input.raw.scroll_delta.y -= scroll_multiplier * event.delta_y() as f32;
|
||||
let delta = -scroll_multiplier
|
||||
* egui::Vec2::new(event.delta_x() as f32, event.delta_y() as f32);
|
||||
|
||||
if event.ctrl_key() {
|
||||
runner_lock.input.raw.zoom_delta *= (delta.y / 200.0).exp();
|
||||
} else {
|
||||
runner_lock.input.raw.scroll_delta += delta;
|
||||
}
|
||||
|
||||
runner_lock.needs_repaint.set_true();
|
||||
event.stop_propagation();
|
||||
event.prevent_default();
|
||||
|
||||
Reference in New Issue
Block a user