Expand description
A formal state machine for pointer-driven drag gestures.
The lifecycle every synthesized drag goes through - press, threshold
promotion, tracking, release or abort - is modeled here as a pure
transition function over explicit states and events, so every edge
(stray pointer ids, release before the threshold, cancellation mid-drag)
is an exhaustive match arm with a test, not an ad-hoc if.
crate::core::Draggable drives this machine; you can drive it yourself
to build custom pointer interactions with the same rigor:
use dioxus_dnd::core::{transition, GestureEffect, GesturePhase, GestureEvent, Point};
let mut phase = GesturePhase::Idle;
let (next, fx) = transition(phase, GestureEvent::Down { at: Point::new(10.0, 10.0), pointer_id: 1 }, 8.0);
phase = next;
assert_eq!(fx, GestureEffect::None); // pressed, not yet a drag
let (next, fx) = transition(phase, GestureEvent::Move { at: Point::new(30.0, 10.0), pointer_id: 1 }, 8.0);
assert!(matches!(fx, GestureEffect::Begin { .. })); // crossed the thresholdEnums§
- Gesture
Effect - What the caller should do after a transition.
- Gesture
Event - An input to the machine.
- Gesture
Phase - Where a pointer gesture currently stands.
- Promotion
- How a press gets promoted to a drag - the policy half of the touch auto-sensor.
Functions§
- transition
- Advance the machine with the default
Promotion::Distancepolicy. Pure: same inputs, same outputs, no side effects. - transition_
with - Advance the machine under an explicit
Promotionpolicy. Pure: same inputs, same outputs, no side effects.