Skip to main content

EventCtx

Struct EventCtx 

Source
pub struct EventCtx { /* private fields */ }
Expand description

Capabilities granted to a widget while it handles an event.

Widgets do not mutate the runtime directly: they set request flags here, and the runtime applies them after dispatch completes.

Implementations§

Source§

impl EventCtx

Source

pub fn is_consumed(&self) -> bool

Returns true if a widget has called Self::consume_event during this dispatch. Used by parent containers to decide whether to keep routing the event.

Source

pub fn consume_event(&mut self)

Mark the current event as handled. Parent containers stop routing once they see this flag, so the same keystroke doesn’t fire two actions (e.g., a default button’s Enter accelerator stopping the focused list from also reacting to the keypress).

Source

pub fn swallow_key_until_release(&mut self)

Ask the runtime to discard the remainder of the current key press: any text (Char) it still produces and every later event for the same key — autorepeats and the release — up to and including that release.

Unlike Self::consume_event, which only stops routing this event, this reaches across the separate KeyDown / Char / KeyUp events a single press generates. A menu item fired by its mnemonic uses it: the keystroke that picked the item must not also land in whatever the item opens on the spot — e.g. the freshly focused field of a dialog — which otherwise receives the trailing Char and types the letter.

Source

pub fn request_paint(&mut self)

Mark the window dirty so the runtime repaints on the next idle tick.

Source

pub fn request_tick(&mut self)

Ask the runtime to deliver at least one more Event::Tick soon.

This is the push counterpart to Widget::wants_ticks: where wants_ticks is a steady-state flag the runtime pulls by walking the widget tree (so every container in the path must forward it), this request rides the shared EventCtx straight back to the runtime — no ancestor has to know or forward anything, exactly like Self::request_paint. A widget buried under custom wrappers can thus drive an animation without its parents cooperating.

It is one-shot: it guarantees the next tick, not a stream. A widget that needs continuous ticks (e.g. a scrollbar auto-repeating while its arrow button is held) simply calls this again each time it handles a Event::Tick, for as long as it still needs them; the moment it stops re-requesting, the ticks wind down on their own.

Source

pub fn close(&mut self)

Ask the runtime to close the window after this dispatch completes.

Source

pub fn is_focus_requested(&self) -> bool

true if a widget called Self::request_focus during this dispatch. Custom container widgets (outside saudade) read this after forwarding an event to a child to learn the child wants focus, then call Self::clear_focus_flags and move focus to it — the same protocol the built-in Container / Column use internally.

Source

pub fn is_focus_released(&self) -> bool

true if a widget called Self::release_focus during this dispatch.

Source

pub fn clear_focus_flags(&mut self)

Reset both focus-change flags after a custom container has acted on them.

Source

pub fn request_focus(&mut self)

The widget asks to become the keyboard-focused widget. Parent containers observe this flag during pointer dispatch and route subsequent keyboard events here.

Source

pub fn release_focus(&mut self)

The widget asks to drop keyboard focus. Useful when an editor wants the window to stop sending it characters.

Source

pub fn request_focus_next(&mut self)

A mnemonic-bearing widget (typically a FocusLabel) asks its parent container to move keyboard focus to the next focusable sibling after it — the classic buddy-label behaviour, where "Last &name:" hands focus to the text field that follows it. Call this from the widget’s event handler when its accelerator letter is pressed; the container performs the move once dispatch unwinds. The requesting widget needs no knowledge of its own position in the tree.

Source

pub fn is_focus_next_requested(&self) -> bool

true if a widget called Self::request_focus_next during this dispatch. Read by container widgets — including custom ones outside saudade — to learn a buddy label’s accelerator was matched, so they can move focus to the next focusable child after the requester.

Source

pub fn request_dismiss(&mut self)

Content inside a modal dialog calls this to ask the hosting Modal to close — e.g. from an OK / Close button’s on_click. The modal runs its on_dismiss handler and dismisses after the current event finishes dispatching.

Source

pub fn is_dismiss_requested(&self) -> bool

true if a widget called Self::request_dismiss during this dispatch. Read by Modal after forwarding an event to its content.

Source

pub fn request_window_size(&mut self, width: i32, height: i32)

Ask the runtime to resize the window to width × height logical pixels, applied after the current event finishes dispatching (and followed by a repaint, so callers needn’t also call Self::request_paint). Handy for a window that should grow or shrink to fit a mode the user just toggled. The window’s size is the app’s to set — unlike the logical→physical scale factor, which only the OS controls.

Source

pub fn start_drag(&mut self, data: DragData)

Begin dragging data out of this window as an OS drag-and-drop operation — the mirror of receiving a Event::Drop. Call this from a widget’s event handler once a press-then-move gesture is recognized (typically on Event::PointerMove after the pointer has travelled a few pixels from a Event::PointerDown), so a plain click still reads as a click rather than starting a drag.

Wayland only. The winit backends (macOS, Windows, X11) expose no API to initiate a drag, so this is a no-op there; only the Wayland backend turns it into a real drag whose text/uri-list payload other applications can drop. Receiving drops, by contrast, works on every backend. The drag copies (never moves) the referenced files.

Source

pub fn accept_drop(&mut self)

Signal, while handling an incoming Event::DragEnter or Event::DragMove, that this widget will accept a drop at the current position. A drop target must call this to receive drops: the runtime treats a widget that doesn’t as not interested, so the drag falls through it. Re-evaluated on every move, so a target can accept only over its hot region and decline elsewhere in the same window.

On Wayland this is what tells the source app the spot is a valid target (its drag cursor / feedback reflects it) and is the prerequisite for a later Event::Drop landing here. On the winit backends the OS has already committed to offering the drop, so this is advisory there — Event::Drop arrives regardless — but calling it keeps drop targets portable.

Source

pub fn set_cursor(&mut self, cursor: Cursor)

Ask the runtime to show cursor as the mouse-pointer shape while it rests over this widget. Call it while handling a pointer event — almost always Event::PointerMove.

The runtime reconciles the pointer shape after every move: whatever a widget requests during that move’s dispatch becomes the cursor, and a move no widget answers falls back to Cursor::Default (the arrow). A widget that wants a non-default cursor therefore simply re-requests it on each PointerMove it receives — the cost is one enum write, and there’s nothing to “unset” on the way out: moving onto another widget, or off this one, re-runs the reconciliation. Because only moves drive it, a request made while handling a press, key, or tick is ignored.

Buttons request Cursor::Hand and text fields Cursor::Text this way; a widget that never calls this keeps the normal arrow.

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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more