Skip to main content

Module drag

Module drag 

Source
Expand description

Drag primitive: threshold + state machine.

State per entity tracked via the DragState component:

  • Pending { start } - pointer pressed on entity, hasn’t moved past threshold yet.
  • Active { start, last } - threshold crossed, drag is in progress.

Transitions:

(no state)
  --(PointerPressed on Hovered)--> Pending
Pending
  --(PointerMoved, dist > threshold)--> Active + DragStartEvent
  --(PointerReleased)--> (no state)
Active
  --(PointerMoved)--> Active + DragMoveEvent
  --(PointerReleased)--> (no state) + DragEndEvent

Threshold is configured via DragConfig (default 4 px).

Reads PointerPressed from lumen-input::dispatch_clicks indirectly: we look at entities that gain Pressed (so the existing dispatch pipeline already filters to the hovered entity).

Structs§

DragConfig
Tunables for the drag recognizer.
DragPlugin
Plugin: installs DragConfig and registers the three drag systems.
Draggable
Opt-in: entities with this marker have their Transform::absolute translated by each DragMoveEvent delta. Without this, drag events still fire but the entity stays put - apps that want different drag semantics (scrollbars, marquee selection) read DragMove themselves.

Enums§

DragState
Per-entity drag state. Attached on Pressed insert, removed on release.

Constants§

DEFAULT_DRAG_THRESHOLD_PX
Default pixel threshold before a press graduates to a drag.

Functions§

attach_drag_pending
On Pressed-without-DragState: attach DragState::Pending with the current pointer position as the press anchor.
release_drag_on_unpress
On Pressed -> not-Pressed: remove DragState; if it was Active, emit DragEndEvent with the final pointer position.
translate_draggable
Generic system: every DragMoveEvent for an entity carrying the Draggable marker adds the delta to its Transform::absolute.
update_drag_on_move
Walk PointerMoved events: promote Pending -> Active when distance exceeds threshold; emit DragMoveEvent while Active.