Skip to main content

Module press

Module press 

Source
Expand description

Press primitive: long-press detection + double-click recognizer.

Both signals are derived from existing low-level state:

  • Long-press = entity carrying Pressed continuously for more than long_press_threshold (default 500 ms). Fires LongPressEvent once per press cycle. The marker PressStartedAt is auto-attached on Pressed insertion and removed on Pressed removal so a fresh press always starts a fresh timer.
  • Double-click = two consecutive ClickEvents on the same entity within double_click_threshold (default 300 ms). Tracked in the LastClick resource.

Apps consume LongPressEvent / DoubleClickEvent just like any other Message - MessageReader<LongPressEvent> / MessageReader<DoubleClickEvent>.

Structs§

LastClick
Last accepted click - drives the double-click detector.
PressConfig
Tunables. Re-read every frame so apps can mutate at runtime.
PressPlugin
Plugin: registers press-recognizer systems.
PressStartedAt
Auto-attached to every entity the moment it acquires Pressed. Carries the Instant the press began. Removed once the entity releases. Also marks whether a LongPressEvent has already fired for this press cycle so we don’t spam.

Constants§

DEFAULT_DOUBLE_CLICK_MS
Default double-click window. Matches GTK / Windows defaults (~300ms).
DEFAULT_LONG_PRESS_MS
Default long-press threshold. Matches the W3C touch UI guideline.
DOUBLE_CLICK_RADIUS_PX
Maximum pointer travel between two clicks for them to still count as a double-click. Matches the GTK / Qt double-click slop (~5px): two clicks at opposite corners of one large entity are two singles, not a double.

Functions§

attach_press_timer
Maintain PressStartedAt: attach on first frame an entity carries Pressed without a timer, remove when Pressed disappears.
detect_double_click
Detect double-click by tracking the last-seen ClickEvent target + time. Two clicks on the same entity within cfg.double_click fire a DoubleClickEvent; the cache resets so a third click within the window is a new first click.
detect_long_press
Emit LongPressEvent for entities pressed past the threshold. Once per press cycle (gated by PressStartedAt::long_fired).