Skip to main content

Module touch_emulation

Module touch_emulation 

Source
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_THRESHOLD px) is a left click at the release point.
  • A drag past the threshold becomes a MIDDLE-button drag starting at the touch-down point — ScrollView pans 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 MultiTouchInfo instead.) 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§

TouchMouseEmu
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.