mirror of
https://github.com/storytold/egui.git
synced 2026-11-20 17:42:29 +01:00
Lets you tell what is driving a scroll: a mouse wheel, fingers on a
trackpad (not a touch screen), or the OS continuing a trackpad swipe
with momentum.
```rust
pub enum MouseWheelSource {
Unknown,
Wheel,
Trackpad,
Momentum,
}
```
* `Event::MouseWheel` gains `source: MouseWheelSource`. Integrations set
it to `Unknown` if they don't know.
* `InputState::scroll_source() -> Option<MouseWheelSource>`: what is
driving the current scrolling, `Some` while `is_scrolling()`. For a
trackpad that covers the whole gesture (`TouchPhase::Start`…`End`); for
a mouse wheel, until the smoothing of the last notch is done. Touch
screens scroll by dragging with the pointer, not with wheel events, so
`None` there.
Use cases: a `ScrollArea` can rubber-band and hold while fingers rest on
the trackpad, but bounce during momentum (#8663, built on this). A
slider or plot can ignore `Momentum` so a flick doesn't keep changing a
value after the fingers lift.
**Where the source is known**
* macOS (eframe): `Wheel`, `Trackpad` or `Momentum`. winit folds the
macOS momentum phase into the regular `TouchPhase`, so egui-winit reads
`NSEvent::momentumPhase` itself through a local event monitor
(`macos_scroll_momentum.rs`, owned by `State`, removed on drop). Precise
deltas are `Trackpad`, line deltas `Wheel`. Goes away once we are on a
winit with rust-windowing/winit#4732; marked with TODOs.
* winit `PanGesture`: `Trackpad`.
* Everywhere else: `Unknown`. Web `WheelEvent`s carry no phase or source
at all.
**Also**: the 150 ms scroll-action timeout from #8636 is tuned for
flowing events. Fingers resting on a trackpad produce none, so a known
`Trackpad` gesture now survives a 1 s gap before being considered over.
The enum mirrors the one proposed for winit.
* [x] I have followed the instructions in the PR template
🤖 Generated with [Claude Code](https://claude.com/claude-code)