Skip to main content

GestureDetector

GestureDetector is the low-level input wrapper for pointer-style interactions.

It lets you attach actions for taps, secondary clicks, long presses, drag lifecycle events, hover enter and exit, and drop interactions. That makes it useful for custom surfaces, dismissal backdrops, context menus, drag targets, and other interaction patterns that are not already covered by a higher-level widget.

Use GestureDetector when you need this level of control. Do not reach for it first when a higher-level widget already expresses the interaction. A Button, Checkbox, or dedicated input widget usually gives you clearer semantics with less work.

Example

use fission::core::ui::{Container, GestureDetector, Text};

let node = GestureDetector {
child: Box::new(
Container::new(Text::new("Open context menu").into_node())
.padding_all(12.0)
.into_node(),
),
on_secondary_click: Some(show_context_menu_action),
..Default::default()
}
.into_node();

This is a good use case because the interaction is more specific than a plain button press.

Field table

FieldTypeMeaningNotes / default behavior
idOption<NodeId>Stable node identity.Defaults to None.
childBox<Node>The wrapped child that receives gesture detection.Required. Default uses an empty spacer child.
on_tapOption<ActionEnvelope>Action for a normal tap.When present, the lowered semantics become focusable.
on_double_tapOption<ActionEnvelope>Action for a double tap.Defaults to None.
on_long_pressOption<ActionEnvelope>Action for a long press.Defaults to None.
on_drag_startOption<ActionEnvelope>Action for drag start.Defaults to None.
on_drag_updateOption<ActionEnvelope>Action for drag movement.Defaults to None.
on_drag_endOption<ActionEnvelope>Action for drag end.Defaults to None.
on_hover_enterOption<ActionEnvelope>Action when the pointer enters the bounds.Useful on desktop and web.
on_hover_exitOption<ActionEnvelope>Action when the pointer leaves the bounds.Useful on desktop and web.
on_dropOption<ActionEnvelope>Action when a drag payload is dropped on this node.Defaults to None.
on_secondary_clickOption<ActionEnvelope>Action for right click or equivalent secondary click.Defaults to None.
on_drag_enterOption<ActionEnvelope>Action when a drag enters the target bounds.Defaults to None.
on_drag_leaveOption<ActionEnvelope>Action when a drag leaves the target bounds.Defaults to None.
drag_payloadOption<Vec<u8>>Opaque bytes attached to drag sources.Defaults to None. Also marks the node as draggable.

Interaction and semantics behavior

GestureDetector lowers to a semantics node rather than a visual node. That matters because it means the wrapped child keeps its layout and appearance, while the detector adds interaction triggers around it.

The lowered semantics also advertise drag capability when drag handlers or drag payload are present. That is what makes it a useful building block for custom drag-and-drop flows.

Specific advice

Prefer higher-level widgets when possible. If a control is conceptually a button, use a button. If a control is conceptually a text input, use a text input. GestureDetector is best when the gesture itself is the important abstraction, not when it is only a way to simulate a more specific control.

For drop targets, keep the payload format documented and stable. The runtime only carries opaque bytes here; your application still needs a clear meaning for those bytes.

Button, Overlay, Positioned, and CustomNode.