pub struct PointerEvent {Show 13 fields
pub id: u64,
pub kind: PointerEventKind,
pub phase: PointerPhase,
pub position: Point,
pub global_position: Point,
pub screen_position: Option<Point>,
pub scroll_delta: Point,
pub buttons: PointerButtons,
pub time_ms: Option<i64>,
pub animation_time_nanos: Option<u64>,
pub zoom_delta: f32,
pub source: PointerSource,
pub modifiers: Option<Modifiers>,
/* private fields */
}Expand description
Pointer event with consumption tracking for gesture disambiguation.
Events can be consumed by handlers (e.g., scroll) to prevent other handlers (e.g., clicks) from receiving them. This enables proper gesture disambiguation matching Jetpack Compose’s event consumption pattern.
Fields§
§id: u64§kind: PointerEventKind§phase: PointerPhase§position: Point§global_position: Point§screen_position: Option<Point>Where the pointer is on the screen, in logical pixels, when the
platform told the shell where the window drawing this event’s root
sits. None on platforms without window positions and for events a
test dispatches without one. A gesture that crosses windows, such as
a tab torn out of one window and dropped on another, compares this
with the windows’ positions instead of translating global_position
itself.
scroll_delta: PointScroll delta in logical pixels.
This is non-zero for PointerEventKind::Scroll events and zero for
button/move events.
time_ms: Option<i64>Platform timestamp of the input sample in milliseconds, when available.
The time base is platform specific (e.g. Android’s uptime clock); only differences between events of the same gesture are meaningful. Gesture velocity trackers must prefer this over the delivery time because platforms like Android deliver input batched/frame-aligned: several samples arrive back-to-back and delivery-time stamping makes computed velocities wildly wrong.
animation_time_nanos: Option<u64>Timestamp in the animation frame-clock domain at input dispatch.
Unlike time_ms, this has the same origin as frame callbacks and can
anchor input-driven animations without a wall/platform clock conversion.
zoom_delta: f32Multiplicative zoom factor for PointerEventKind::Zoom events
(> 1.0 zooms in, < 1.0 zooms out). 1.0 for all other events.
source: PointerSourceThe kind of device that produced this event (touch, mouse, stylus), when
the platform reports it. Defaults to PointerSource::Unknown.
modifiers: Option<Modifiers>Keyboard modifiers held at the time of this sample, when the platform can report them.
None means the platform never told the shell what the keyboard state
was — touch-only Android/iOS input has no channel for it today — and is
deliberately distinct from Some(Modifiers::NONE), which means the
platform looked and nothing was held. An app that wants shift/ctrl-click
multi-select reads this field directly; it must not treat None as
“nothing held” or it silently drops the gesture on the platforms that
cannot yet report it instead of visibly doing nothing.
Implementations§
Source§impl PointerEvent
impl PointerEvent
pub fn new( kind: PointerEventKind, position: Point, global_position: Point, ) -> PointerEvent
Sourcepub fn with_id(self, id: u64) -> PointerEvent
pub fn with_id(self, id: u64) -> PointerEvent
Set the pointer id for this event (0 is the primary pointer).
Sourcepub fn with_zoom_delta(self, zoom_delta: f32) -> PointerEvent
pub fn with_zoom_delta(self, zoom_delta: f32) -> PointerEvent
Set the multiplicative zoom factor for a PointerEventKind::Zoom event.
Sourcepub fn with_scroll_delta(self, scroll_delta: Point) -> PointerEvent
pub fn with_scroll_delta(self, scroll_delta: Point) -> PointerEvent
Set the scroll delta for this event.
Sourcepub fn with_time_ms(self, time_ms: Option<i64>) -> PointerEvent
pub fn with_time_ms(self, time_ms: Option<i64>) -> PointerEvent
Set the platform timestamp (milliseconds) for this event.
Sourcepub fn with_animation_time_nanos(self, time_nanos: u64) -> PointerEvent
pub fn with_animation_time_nanos(self, time_nanos: u64) -> PointerEvent
Set the timestamp in the animation frame-clock domain.
Sourcepub fn with_screen_position(
self,
screen_position: Option<Point>,
) -> PointerEvent
pub fn with_screen_position( self, screen_position: Option<Point>, ) -> PointerEvent
Set where the pointer is on the screen, when the platform knows.
Sourcepub fn travelled_to(&self) -> Point
pub fn travelled_to(&self) -> Point
Where the pointer is in the steadiest frame the platform offers: on the screen where it reports window positions, and in the composition where it does not.
Two events compared this way say how far the hand travelled even when the window under it travelled too, which is what a drag threshold has to measure: a press that drags a borderless window never moves within that window, because the window follows it.
Set the buttons state for this event
Sourcepub fn with_source(self, source: PointerSource) -> PointerEvent
pub fn with_source(self, source: PointerSource) -> PointerEvent
Set the device source (touch/mouse/stylus) for this event.
Sourcepub fn with_modifiers(self, modifiers: Modifiers) -> PointerEvent
pub fn with_modifiers(self, modifiers: Modifiers) -> PointerEvent
Sourcepub fn rotary(
kind: PointerEventKind,
rotary: RotaryScrollEvent,
position: Point,
) -> PointerEvent
pub fn rotary( kind: PointerEventKind, rotary: RotaryScrollEvent, position: Point, ) -> PointerEvent
Builds a rotary pointer event for one dispatch pass.
kind must be PointerEventKind::RotaryScrollPre (capture) or
PointerEventKind::RotaryScroll (bubble). The rotary payload rides on
the existing scroll_delta/time_ms fields so rotary reuses the
pointer dispatch path without widening PointerEvent.
Sourcepub fn rotary_scroll_event(&self) -> Option<RotaryScrollEvent>
pub fn rotary_scroll_event(&self) -> Option<RotaryScrollEvent>
Reads this event back as a RotaryScrollEvent, or None when it is
not a rotary event.
Copies three scalars out of the event; it never allocates.
Sourcepub fn consume(&self)
pub fn consume(&self)
Mark this event as consumed, preventing other handlers from processing it.
Example: Scroll gestures consume events once dragging starts to prevent child buttons from firing clicks.
Sourcepub fn is_consumed(&self) -> bool
pub fn is_consumed(&self) -> bool
Check if this event has been consumed by another handler.
Handlers should check this before processing events. For example, clickable should not fire if the event was consumed by a scroll gesture.
pub fn defer_post_dispatch_action<F>(&self, action: F)
pub fn finish_post_dispatch(&self)
Sourcepub fn copy_with_local_position(&self, position: Point) -> PointerEvent
pub fn copy_with_local_position(&self, position: Point) -> PointerEvent
Creates a copy of this event with a new local position, sharing the consumption state.
Trait Implementations§
Source§impl Clone for PointerEvent
impl Clone for PointerEvent
Source§fn clone(&self) -> PointerEvent
fn clone(&self) -> PointerEvent
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more