Expand description
Wheel-delta normalization for shells: OS / DOM scroll deltas → the
notch count Event::MouseWheel carries.
Wheel-delta normalization: OS / DOM scroll deltas → agg-gui notches.
agg-gui’s Event::MouseWheel
carries a notch count, not pixels: every consumer scales it itself
(ScrollView multiplies by
[PIXELS_PER_NOTCH], text areas and tree views do the same, and zoom
consumers raise their per-notch factor to the power of the delta).
Shells are therefore responsible for converting whatever their
platform reports into notches, and this module is that conversion in
one testable place — the native shells (LineDelta through,
PixelDelta / 40) and the web shell (WheelEvent.deltaMode) had
drifted apart, and a shim that forwarded raw pixels multiplied every
scroll in the app by ~40-100×.
§Precision deltas are forwarded fractionally
A macOS trackpad (and a smooth-scrolling mouse) reports pixel deltas of
1-10 px per event, i.e. a fraction of a notch. Those fractions are
passed straight through: 4 px of finger travel is 0.1 notch, which a
ScrollView turns back into 4 px, so precision scrolling stays 1:1
and continuous — no banking into 40 px jumps. A classic wheel still
arrives as whole notches (one LineDelta line, or ~100 px per click
in browsers that report wheels in pixels), so consumers that want a
crisp per-click step get one; consumers must therefore scale by the
delta’s magnitude rather than reading only its sign, or a trackpad
would take a full step per 2-pixel event. Every consumer in agg-gui
does (scroll containers multiply, zooms use step.powf(delta)).
An earlier revision banked sub-notch travel and emitted only whole
notches. That made trackpads stutter in 40 px steps on the web while
the native shell — which never banked — was smooth; the two shells now
agree, via [to_notches] on both.
Structs§
- Wheel
Normalizer - Stateless per-event converter a shell keeps beside its wheel listener.
Enums§
- Wheel
Delta Mode - How a platform expressed its wheel delta. The discriminants match the
DOM’s
WheelEvent.deltaMode, so a web shell can convert withWheelDeltaMode::from_dom.
Constants§
- NOTCHES_
PER_ PAGE - Notches one “page” (DOM
deltaMode2) is worth. - PIXELS_
PER_ NOTCH - Pixels one wheel notch is worth. The scale
ScrollViewscrolls by, and the divisor the native shells apply to a trackpad’s pixel delta.
Functions§
- to_
notches - Raw delta → notches, before any accumulation. Pure; see
WheelNormalizerfor the part that keeps state.