Skip to main content

Module touch_state

Module touch_state 

Source
Expand description

Multi-touch gesture recogniser.

The platform shells (web JS, native winit) forward raw touch events to [App::on_touch_start/move/end/cancel]. TouchState maintains the set of active touches and, once two or more fingers are down, aggregates them each frame into a MultiTouchInfo describing zoom, rotation, pan, and average pressure relative to the previous frame.

Widgets that want to react to gestures read the current frame’s aggregate via current_multi_touch, a thread-local written by [App::publish_multi_touch] at the start of each paint. Single- finger touches continue to flow through the regular mouse-emulation path, so existing widgets keep working with no changes.

The API shape deliberately mirrors egui’s (zoom_delta, rotation_delta, translation_delta, num_touches, center_pos) so ports from egui code read cleanly.

Structs§

MultiTouchInfo
Gesture aggregate for the current frame, produced when two or more fingers are on the same device. All deltas are relative to the previous frame’s positions — the widget just accumulates them into its own angle / scale / translation state (see LionView for the canonical consumer).
TouchDeviceId
Stable per-device identifier. Different physical input surfaces (e.g. a laptop’s built-in touchscreen and a connected tablet) hash to different values. The web shell always uses 0 (the browser doesn’t expose multiple touch devices to pages); winit passes through its device id.
TouchId
Per-finger identifier, stable from Start through End/Cancel. Re- used after lift — browsers and winit both guarantee identifiers are unique only for the lifetime of the touch.
TouchState
Tracks every active touch across every known device. Lives on App; widgets never see this directly.

Enums§

TouchPhase
Which phase of the gesture this touch event represents.

Functions§

current_multi_touch
Fetch the current frame’s multi-touch aggregate. Returns None when fewer than two fingers are down on any device, so a widget writes: if let Some(mt) = current_multi_touch() { … }.
last_touch_event_age
Time elapsed since the most recent touch lifecycle event, or None if no touch event has ever fired. Mouse events synthesised from a touchstart / touchend by the web shell arrive within a millisecond of the touch event — widgets needing to tell touch-synthesised mouse events apart from real desktop clicks check this against a small threshold.
set_current
Publish this frame’s multi-touch aggregate. Called by App::paint right before painting begins.