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

Add is_scrolling/is_smooth_scrolling util, checking for active scroll action. (#7669)

* Closes #7657
* [x] I have followed the instructions in the PR template

On native this uses a new "touch phase" parameter of the mouse wheel
event to know if a scroll action is done.

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
This commit is contained in:
Isse
2025-10-27 11:46:51 +01:00
committed by GitHub
parent f6fa74c665
commit 999e943e59
4 changed files with 127 additions and 55 deletions

View File

@@ -312,8 +312,8 @@ impl State {
consumed: self.egui_ctx.wants_pointer_input(),
}
}
WindowEvent::MouseWheel { delta, .. } => {
self.on_mouse_wheel(window, *delta);
WindowEvent::MouseWheel { delta, phase, .. } => {
self.on_mouse_wheel(window, *delta, *phase);
EventResponse {
repaint: true,
consumed: self.egui_ctx.wants_pointer_input(),
@@ -545,12 +545,13 @@ impl State {
}
}
WindowEvent::PanGesture { delta, .. } => {
WindowEvent::PanGesture { delta, phase, .. } => {
let pixels_per_point = pixels_per_point(&self.egui_ctx, window);
self.egui_input.events.push(egui::Event::MouseWheel {
unit: egui::MouseWheelUnit::Point,
delta: Vec2::new(delta.x, delta.y) / pixels_per_point,
phase: to_egui_touch_phase(*phase),
modifiers: self.egui_input.modifiers,
});
EventResponse {
@@ -680,12 +681,7 @@ impl State {
self.egui_input.events.push(egui::Event::Touch {
device_id: egui::TouchDeviceId(egui::epaint::util::hash(touch.device_id)),
id: egui::TouchId::from(touch.id),
phase: match touch.phase {
winit::event::TouchPhase::Started => egui::TouchPhase::Start,
winit::event::TouchPhase::Moved => egui::TouchPhase::Move,
winit::event::TouchPhase::Ended => egui::TouchPhase::End,
winit::event::TouchPhase::Cancelled => egui::TouchPhase::Cancel,
},
phase: to_egui_touch_phase(touch.phase),
pos: egui::pos2(
touch.location.x as f32 / pixels_per_point,
touch.location.y as f32 / pixels_per_point,
@@ -738,7 +734,12 @@ impl State {
}
}
fn on_mouse_wheel(&mut self, window: &Window, delta: winit::event::MouseScrollDelta) {
fn on_mouse_wheel(
&mut self,
window: &Window,
delta: winit::event::MouseScrollDelta,
phase: winit::event::TouchPhase,
) {
let pixels_per_point = pixels_per_point(&self.egui_ctx, window);
{
@@ -754,10 +755,12 @@ impl State {
egui::vec2(x as f32, y as f32) / pixels_per_point,
),
};
let phase = to_egui_touch_phase(phase);
let modifiers = self.egui_input.modifiers;
self.egui_input.events.push(egui::Event::MouseWheel {
unit,
delta,
phase,
modifiers,
});
}
@@ -970,6 +973,15 @@ impl State {
}
}
fn to_egui_touch_phase(phase: winit::event::TouchPhase) -> egui::TouchPhase {
match phase {
winit::event::TouchPhase::Started => egui::TouchPhase::Start,
winit::event::TouchPhase::Moved => egui::TouchPhase::Move,
winit::event::TouchPhase::Ended => egui::TouchPhase::End,
winit::event::TouchPhase::Cancelled => egui::TouchPhase::Cancel,
}
}
fn to_egui_theme(theme: winit::window::Theme) -> Theme {
match theme {
winit::window::Theme::Dark => Theme::Dark,