Expand description
Touch → mouse emulation for the primary finger.
Companion to crate::touch_state: while TouchState aggregates
two-plus-finger gestures into a per-frame crate::MultiTouchInfo,
this module makes SINGLE-finger touches drive the existing mouse
event pipeline so every widget keeps working without touch-specific
code. crate::widget::App owns a TouchMouseEmu and feeds it
from App::on_touch_start/move/end/cancel; the returned EmuCmds
are replayed through App::on_mouse_*. Platform shells (web JS,
native winit) therefore forward RAW touches only — they must not
synthesize mouse events themselves, or every event would fire twice.
The gesture contract (ported from the original JS shell in
demo/src/app.ts):
- A tap (release before moving
TOUCH_SCROLL_THRESHOLDpx) is a left click at the release point. - A drag past the threshold becomes a MIDDLE-button drag starting
at the touch-down point —
ScrollViewpans on middle-drag, so a finger drag scrolls by the exact finger delta. Canvas-style widgets that want to own finger drags (e.g. the lion demo) consume middle-drag instead of left-drag. - The moment a second finger lands, single-finger emulation is
suppressed until every finger lifts: an in-flight middle drag is
released immediately, and the eventual release emits no click.
(The multi-finger gesture is reported via
MultiTouchInfoinstead.) This also kills the phantom click a pinch used to fire when the first finger barely moved.
All coordinates are the same screen-space (Y-down, physical-pixel)
units the App::on_mouse_* entry points accept.
Structs§
- Touch
Mouse Emu - State machine tracking the primary finger. Self-contained (keeps
its own active-finger set) so it can be unit-tested without an
App.
Enums§
- EmuCmd
- A mouse event the emulator wants replayed through
App::on_mouse_*. Coordinates are screen-space, matching those entry points.
Constants§
- TOUCH_
SCROLL_ THRESHOLD - Distance (physical px) the primary finger must travel before the gesture stops being a potential tap and becomes a middle-drag.