Skip to main content

EventCtx

Struct EventCtx 

Source
pub struct EventCtx<'a> { /* private fields */ }
Expand description

Context threaded into crate::widget::Widget::event: mutate the type-erased app state (EventCtx::state_mut), request a redraw or layout, capture the pointer or focus, and read the widget’s own geometry (event positions are already local).

Implementations§

Source§

impl<'a> EventCtx<'a>

Source

pub fn new( state: &'a mut (dyn Any + 'static), origin: Point, size: Size, ) -> EventCtx<'a>

Build a root event context over the erased state for a widget at origin with size.

Source

pub fn state_mut<T>(&mut self) -> &mut T
where T: Any,

Recover the application state as &mut T. Panics if T is not the type the root erased — a wiring bug, not a data condition.

Source

pub fn request_redraw(&mut self)

Request that the shell schedule a repaint after this event pass.

Source

pub fn needs_redraw(&self) -> bool

Whether a redraw was requested during this (sub)dispatch.

Source

pub fn request_layout(&mut self)

Request layout for state this widget changed itself: marks every pod up to the root layout-dirty, reaches the root’s pending ChangeFlags::LAYOUT, and implies a redraw.

Source

pub fn needs_layout(&self) -> bool

Whether a layout was requested during this (sub)dispatch.

Source

pub fn capture_pointer(&mut self)

Capture the pointer: later moves/releases route back to this widget along the recorded active path until Up/Cancel. Only a hit-tested Down (or an overlay surface’s input) sets the root’s capture mirror, so a capture from a Move routes while the root still reads uncaptured; a drag wanting hover chrome throughout keeps its own pressed flag.

Source

pub fn is_pointer_captured(&self) -> bool

Whether the widget requested pointer capture during this (sub)dispatch.

Source

pub fn pointer_id(&self) -> PointerId

Which pointer contact this event comes from: PointerId::MOUSE unless the root unwrapped an InputEvent::PointerContact.

Source

pub fn capture_contacts(&mut self)

Opt into the gesture’s other contacts: call on the Down that calls EventCtx::capture_pointer; while that capture lives, each other contact arrives here as a plain pointer event with its own EventCtx::pointer_id. Another contact’s Up/Cancel ends nothing; when the claimant’s does, drop every other contact being tracked.

Source

pub fn is_contact_capture_requested(&self) -> bool

Whether a widget called EventCtx::capture_contacts during this (sub)dispatch; bubbles like EventCtx::is_pointer_captured.

Source

pub fn release_captured_child(&mut self, child: &mut ChildPod)

Take the gesture over: clear child’s active path (after sending it Cancel). If its subtree held the contact opt-in, the root stops routing other contacts; the capture stays with the claimant. A no-op while child is inactive, during a non-claimant delivery, or when the opt-in holder is this container or an ancestor.

Source

pub fn is_capture_released(&self) -> bool

Whether EventCtx::release_captured_child voided the opt-in during this (sub)dispatch.

Source

pub fn request_focus(&mut self)

Request focus: the enclosing pods record the focus path, and keyboard, IME and edit-command events are then delivered down it with no hit test.

Source

pub fn release_focus(&mut self)

Release focus: drop the recorded focus path (e.g. Escape / blur).

Source

pub fn has_focus(&self) -> bool

Whether the receiving widget holds the focus path (always, for a focus-routed event).

Source

pub fn forward_declined_keys_to(&mut self, key: OverlayKey)

From an editable’s owner: forward the keys the focused editable declines to the floated pod key, as OverlayEventKind::Key, before the shortcut table sees them. Recorded on the focus session live at the end of this pass; a new claim or a release ends it.

Source

pub fn consume_overlay_key(&mut self)

Consume an OverlayEventKind::Key delivery, which stops its walk to the shortcut table: the delivery is a broadcast, whose Handled no container carries back.

Source

pub fn claim_hover(&mut self)

Claim the hover link for this widget and, via the recorded path, its ancestors; the next paint reports PaintCtx::is_hovered for them. Ignored outside an uncaptured Move or after the pass’s first claim; requests no redraw.

§The consumer contract
  1. Claim from the Move arm on every move the local hit test passes, not just on entry.
  2. A container claims after routing to its children: the first recorded claim wins.
  3. Keep an internal hovered flag from that hit test; request_redraw only when it changes.
  4. In paint, self-correct that flag from PaintCtx::is_hovered, which is authoritative.
Source

pub fn is_hovered(&self) -> bool

Whether this widget or a descendant holds the hover link, as of before this dispatch; PaintCtx::is_hovered is the authoritative read for hover chrome.

Source

pub fn set_cursor(&mut self, icon: CursorIcon)

Ask the host to show icon; per pass, last writer wins, and a widget that stops asking falls back to CursorIcon::Default. Only a pointer Move (captured included) resolves it, so a drag re-asks on each captured Move, and a container overriding its child asks after routing (the reverse of claim_hover’s order). Requests no redraw.

Source

pub fn write_clipboard(&mut self, text: String)

Ask the shell to put text on the host clipboard — a widget’s answer to EditCommand::Copy or Cut. Per pass, last writer wins; drained by RenderRoot::take_clipboard_write.

Source

pub fn request_paste(&mut self)

Ask the shell to read the host clipboard and dispatch it back as EditCommand::Paste on a later pass; idempotent per pass. The answer lands wherever focus is at delivery, so an async read binds it to RenderRoot::focus_epoch and drops a mismatch (never focus_ime_generation, which edits also move).

Source

pub fn dispatch_edit_command(&mut self, cmd: EditCommand)

Queue cmd for whichever widget drains EventCtx::take_edit_commands later in this pass — the route from a floated toolbar back to its field. A command nobody takes is dropped.

Source

pub fn take_edit_commands(&mut self) -> Vec<EditCommand>

Drain this pass’s queued edit commands in dispatch order; an overlay owner calls it right after forwarding into its floated pod.

Source

pub fn publish_ime_state(&mut self, state: ImeState)

Publish this widget’s IME surface after an editing change; it bubbles up the focus chain to crate::app::RenderRoot::ime_state, carried opaquely.

Source

pub fn origin(&self) -> Point

The widget’s origin in its parent’s space, not window space (unlike PaintCtx::origin). Event positions are already local; compute window-anchored rects from PaintCtx in paint.

Source

pub fn size(&self) -> Size

The receiving widget’s resolved size.

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for EventCtx<'a>

§

impl<'a> !Send for EventCtx<'a>

§

impl<'a> !Sync for EventCtx<'a>

§

impl<'a> !UnwindSafe for EventCtx<'a>

§

impl<'a> Freeze for EventCtx<'a>

§

impl<'a> Unpin for EventCtx<'a>

§

impl<'a> UnsafeUnpin for EventCtx<'a>

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> ErasedDestructor for T
where T: 'static,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(_simd: S, value: T) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

Source§

impl<T> StorageAccess<T> for T

Source§

fn as_borrowed(&self) -> &T

Borrows the value.
Source§

fn into_taken(self) -> T

Takes the value.
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.
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