Skip to main content

WidgetEvent

Enum WidgetEvent 

Source
pub enum WidgetEvent {
Show 16 variants PointerDown { position: Point, button: PointerButton, modifiers: Modifiers, pointer: PointerInfo, }, PointerUp { position: Point, button: PointerButton, modifiers: Modifiers, pointer: PointerInfo, }, PointerMove { position: Point, modifiers: Modifiers, pointer: PointerInfo, }, PointerEnter { pointer: PointerInfo, }, PointerLeave { pointer: PointerInfo, }, Scroll { delta: ScrollDelta, modifiers: Modifiers, window_position: Option<Point>, phase: ScrollPhase, pointer: PointerInfo, }, PointerCancel { window_position: Option<Point>, reason: CancelReason, pointer: PointerInfo, }, KeyDown { key: Key, modifiers: Modifiers, text: Option<String>, }, KeyUp { key: Key, modifiers: Modifiers, }, ImeComposition { text: String, cursor: Option<Range<usize>>, }, ImeCommit { text: String, }, FocusGained { origin: FocusOrigin, }, FocusLost, AccessAction { action: Action, target: Option<WidgetId>, target_node: NodeId, data: Option<ActionData>, }, ScrollIntoView { target_bounds: Rect, margin: f32, align: ScrollAlign, motion: ScrollMotion, applied_scroll: Option<Arc<Mutex<Point>>>, }, Gesture { gesture: GestureEvent, },
}
Expand description

Events dispatched to widgets.

Variants§

§

PointerDown

A button went down.

Fields

§position: Point

Where, in the receiving widget’s own coordinate space (the router localises it on delivery — see WidgetTree::dispatch_pointer).

§button: PointerButton

Which button. A direct pointer reports PointerButton::Primary for a contact.

§modifiers: Modifiers

Modifier keys held when the press landed.

§pointer: PointerInfo

Who pressed — identity, kind, buttons, axes and timestamp.

Read it through EventContext::pointer or its pointer_kind() shorthand rather than by destructuring, so a widget that only needs “was this a finger?” does not have to name the whole struct. Defaults to PointerInfo::mouse at the epoch for every legacy construction site and for pointer_down, so a site that says nothing about pointers keeps meaning what it meant before the touch programme.

§

PointerUp

A button came up.

Fields

§position: Point

Where, in the receiving widget’s own coordinate space.

§button: PointerButton

Which button was released.

§modifiers: Modifiers

Modifier keys held when the release landed.

§pointer: PointerInfo

Who released. See PointerDown::pointer.

§

PointerMove

A pointer moved. Sent whether or not a button is held; a contact only ever moves with its button held, since a finger cannot hover.

Fields

§position: Point

Where, in the receiving widget’s own coordinate space.

§modifiers: Modifiers

Modifier keys held during the move.

A drag decides what it means from the modifiers at the move, not at the press — Shift extends a selection and Ctrl makes a marquee additive from the moment the key goes down, mid-drag included. Defaults to Modifiers::NONE for pointer_move and for a producer that tracks no modifier state.

§pointer: PointerInfo

Who moved. See PointerDown::pointer.

§

PointerEnter

The hover owner came onto this widget. Never sent for a contact: a finger writes no hover (see PointerTable::hover_owner).

Fields

§pointer: PointerInfo

Who entered — a mouse, or a pen in proximity.

§

PointerLeave

The hover owner left this widget.

Fields

§pointer: PointerInfo

Who left. See PointerEnter.

§

Scroll

Fields

§modifiers: Modifiers

Modifier keys held at the time of the scroll event. Defaults to Modifiers::NONE for synthesized events (tests, keyboard-driven scroll requests). Real-platform scroll events populate this from the platform’s tracked modifier state — apps detect Ctrl-wheel-to-zoom by inspecting modifiers.ctrl().

§window_position: Option<Point>

Where the pointer was when the scroll happened, in window-logical coordinates, or None when the producer has no position for it.

The frame is in the name because it is the one positional field a handler receives that is not localised to the receiving widget (localize_event deliberately has no Scroll arm), and a widget that reads it as a local point silently lands a cell or a row out. Convert with the receiver’s own bounds before using it as content coordinates.

It is window-space because both of its frame-sensitive uses need it to be. The router routes by it — Some hit-tests, None falls back to the hovered (else focused) widget — and hit-testing is necessarily window-space. And common/scrollable.rs’s handle_scroll_event feeds it to pan_stepKineticScroller::pan, whose tracker follows the pointer: localisation resolves against the captor’s current bounds on every event, so a localised position would feed that tracker samples polluted by the motion of the very widget being measured.

A mouse wheel has always been positionless and stays so — hover is under the cursor, so hit-testing would find the same widget anyway. A pan synthesised from a direct pointer must carry one, because a contact never writes hover and a positionless pan would route nowhere.

§phase: ScrollPhase

Where in a continuous scroll gesture this sample sits. ScrollPhase::Discrete — a self-contained wheel notch — for everything Teksilo produced before the touch programme.

§pointer: PointerInfo

Who scrolled. Defaults to PointerInfo::mouse at the epoch for every legacy construction site; a real sample carries the pointer’s identity, kind and timestamp.

§

PointerCancel

A pointer interaction was revoked by the system rather than completed by the user — see CancelReason.

Distinct from PointerUp on purpose: an Up means the user finished, so a drag drops and a tap fires; a cancel means the interaction is being taken away, so state must be unwound and nothing may activate.

Terminal: no PointerUp follows for that pointer, and one that arrives anyway is swallowed. Delivered by the cancel funnel, WidgetTree::cancel_pointer, to the widget holding the pointer — or, failing that, to the last one that accepted an event from it. A widget receives it through .on_pointer_cancel(..) or through its raw on_pointer_event hook.

Fields

§window_position: Option<Point>

Where the pointer was last seen, in window-logical coordinates, when the revoking path knows. A platform cancel usually carries no position at all.

Window-space, and named for it, for the same reason as Scroll::window_position — but kept there by a different mechanism, worth knowing before “fixing” either. The cancel funnel delivers through the router’s non-localising route (dispatch_to_widget_direct), so what puts this value in window space is simply that the funnel records the pointer table’s own position verbatim; localize_event having no PointerCancel arm is true but would not matter on this path. A widget whose PointerDown/Move/Up handling works in local coordinates must convert before feeding this to the same sink.

§reason: CancelReason

Why the interaction was revoked.

§pointer: PointerInfo

Which pointer was revoked.

§

KeyDown

Fields

§key: Key
§modifiers: Modifiers
§

KeyUp

Fields

§key: Key
§modifiers: Modifiers
§

ImeComposition

Fields

§text: String
§cursor: Option<Range<usize>>
§

ImeCommit

Fields

§text: String
§

FocusGained

Fields

§

FocusLost

§

AccessAction

Fields

§action: Action
§target_node: NodeId

Raw AccessKit NodeId from the original ActionRequest. May be a synthetic (widget-emitted child) NodeId — use crate::accessibility::is_synthetic to distinguish it from a widget-derived NodeId. The widget that registered the parent (retrieved via tree.widget_for_synthetic) is the one set in target.

§data: Option<ActionData>

Payload carried by the ActionRequest. For Action::SetTextSelection this is ActionData::SetTextSelection(TextSelection), for Action::SetValue it’s ActionData::Value(Box<str>), for scroll actions it carries scroll offsets, etc. Widgets that declare these actions must read the payload to honour screen-reader-initiated requests.

§

ScrollIntoView

Dispatched by the framework to a clipping ancestor when a child gains focus but is outside the viewport. The scroll area adjusts its offset to make the target bounds visible, with an optional margin around the target.

Fields

§target_bounds: Rect
§margin: f32

Extra margin (in logical pixels) to keep around the target when scrolling it into view. Defaults to 0.0.

§align: ScrollAlign

Where the target should end up on the scroll container’s vertical axis. ScrollAlign::Minimal (the default, and what every focus-driven reveal uses) only scrolls when the target is not already fully visible; ScrollAlign::Fraction pins it to a fixed height in the viewport whether or not it was already visible.

§motion: ScrollMotion

Whether the container should jump to the new offset or glide to it. See ScrollMotion.

§applied_scroll: Option<Arc<Mutex<Point>>>

Optional back-channel for the handling scroll container to report how far it actually scrolled ((dx, dy) in content pixels). When several nested scroll containers must each reveal the same target, the ancestor walk (scroll_rect_into_view) reads this after dispatching to an inner container and shifts target_bounds by the negated delta before asking the next (outer) one — so the outer sees where the target will land once the inner’s (deferred) scroll applies, not its pre-scroll position. None disables reporting (the nested-reveal refinement is unavailable). A handler that ignores it still works for the common single-container case.

Arc<Mutex<..>> (not Rc<Cell<..>>) so WidgetEvent stays Send — some events are posted across threads. This one is only ever touched on the dispatch thread, so the lock is always uncontended.

§

Gesture

A recognized gesture event, routed through the same preview/bubble system.

Fields

Implementations§

Source§

impl WidgetEvent

Source

pub fn scroll(delta: ScrollDelta, modifiers: Modifiers) -> Self

A wheel notch with no position — routed by the hovered (else focused) widget, exactly as every scroll in Teksilo was before the touch programme.

It exists so that the three fields Scroll gained cost each of its construction sites one line rather than five. The pointer defaults to PointerInfo::mouse at EventTime::ZERO: a free constructor has no tree and therefore no clock, and nothing reads the timestamp of a legacy-constructed event. A sample that has a real time enters through WidgetTree::dispatch_scroll instead.

Source

pub fn scroll_at( delta: ScrollDelta, modifiers: Modifiers, position: Point, ) -> Self

A wheel notch routed by hit test at position rather than by hover.

Use this where the producer genuinely knows where the pointer was; a mouse-wheel translator should keep using scroll, whose hover routing is what it has always had.

Source

pub fn pointer_down( position: Point, button: PointerButton, modifiers: Modifiers, ) -> Self

A mouse press: PointerInfo::mouse at the epoch.

This and its siblings are why adding pointer to the five Pointer* variants was a one-line-per-site sweep rather than a rewrite. Use them wherever the producer genuinely describes a mouse — every test that is pinning mouse behaviour, and every synthesizer that has no pointer of its own. A producer that does know which pointer it speaks for must write the variant out and thread the real PointerInfo, or ctx.pointer_kind() reads Mouse for a finger and every direct-pointer branch in the framework silently takes the indirect path.

Source

pub fn pointer_up( position: Point, button: PointerButton, modifiers: Modifiers, ) -> Self

A mouse release. See pointer_down.

Source

pub fn pointer_move(position: Point) -> Self

A mouse move with no modifiers held. See pointer_down; use pointer_move_with where the producer tracks modifier state, since a drag reads Shift and Ctrl from the move.

Source

pub fn pointer_move_with(position: Point, modifiers: Modifiers) -> Self

A mouse move carrying tracked modifier state. See pointer_down.

Source

pub fn pointer_enter() -> Self

The mouse entered a widget. See pointer_down.

Source

pub fn pointer_leave() -> Self

The mouse left a widget. See pointer_down.

Trait Implementations§

Source§

impl Clone for WidgetEvent

Source§

fn clone(&self) -> WidgetEvent

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for WidgetEvent

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.