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

Remove Event::Scroll and handle it in egui (#4524)

For integrations: just emit `egui::Event::MouseWheel` (like before).
egui will interpret that as zoom or pan.

On the way towards https://github.com/emilk/egui/issues/4401
This commit is contained in:
Emil Ernerfeldt
2024-05-22 21:35:15 +02:00
committed by GitHub
parent c8578c9a6b
commit 48045e57da
4 changed files with 44 additions and 77 deletions

View File

@@ -694,29 +694,6 @@ impl State {
modifiers,
});
}
let delta = match delta {
winit::event::MouseScrollDelta::LineDelta(x, y) => {
let points_per_scroll_line = 50.0; // Scroll speed decided by consensus: https://github.com/emilk/egui/issues/461
egui::vec2(x, y) * points_per_scroll_line
}
winit::event::MouseScrollDelta::PixelDelta(delta) => {
egui::vec2(delta.x as f32, delta.y as f32) / pixels_per_point
}
};
if self.egui_input.modifiers.ctrl || self.egui_input.modifiers.command {
// Treat as zoom instead:
let factor = (delta.y / 200.0).exp();
self.egui_input.events.push(egui::Event::Zoom(factor));
} else if self.egui_input.modifiers.shift {
// Treat as horizontal scrolling.
// Note: one Mac we already get horizontal scroll events when shift is down.
self.egui_input
.events
.push(egui::Event::Scroll(egui::vec2(delta.x + delta.y, 0.0)));
} else {
self.egui_input.events.push(egui::Event::Scroll(delta));
}
}
fn on_keyboard_input(&mut self, event: &winit::event::KeyEvent) {