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>
impl<'a> EventCtx<'a>
Sourcepub fn new(state: &'a mut dyn Any, origin: Point, size: Size) -> Self
pub fn new(state: &'a mut dyn Any, origin: Point, size: Size) -> Self
Build a root event context over the erased state for a widget at origin with size.
Sourcepub fn state_mut<T: Any>(&mut self) -> &mut T
pub fn state_mut<T: Any>(&mut self) -> &mut T
Recover the application state as &mut T. Panics if T is not the type the root erased —
a wiring bug, not a data condition.
Sourcepub fn request_redraw(&mut self)
pub fn request_redraw(&mut self)
Request that the shell schedule a repaint after this event pass.
Sourcepub fn needs_redraw(&self) -> bool
pub fn needs_redraw(&self) -> bool
Whether a redraw was requested during this (sub)dispatch.
Sourcepub fn request_layout(&mut self)
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.
Sourcepub fn needs_layout(&self) -> bool
pub fn needs_layout(&self) -> bool
Whether a layout was requested during this (sub)dispatch.
Sourcepub fn capture_pointer(&mut self)
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.
Sourcepub fn is_pointer_captured(&self) -> bool
pub fn is_pointer_captured(&self) -> bool
Whether the widget requested pointer capture during this (sub)dispatch.
Sourcepub fn pointer_id(&self) -> PointerId
pub fn pointer_id(&self) -> PointerId
Which pointer contact this event comes from: PointerId::MOUSE unless the root unwrapped
an InputEvent::PointerContact.
Sourcepub fn capture_contacts(&mut self)
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.
Sourcepub fn is_contact_capture_requested(&self) -> bool
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.
Sourcepub fn release_captured_child(&mut self, child: &mut ChildPod)
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.
Sourcepub fn is_capture_released(&self) -> bool
pub fn is_capture_released(&self) -> bool
Whether EventCtx::release_captured_child voided the opt-in during this (sub)dispatch.
Sourcepub fn request_focus(&mut self)
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.
Sourcepub fn release_focus(&mut self)
pub fn release_focus(&mut self)
Release focus: drop the recorded focus path (e.g. Escape / blur).
Sourcepub fn has_focus(&self) -> bool
pub fn has_focus(&self) -> bool
Whether the receiving widget holds the focus path (always, for a focus-routed event).
Sourcepub fn forward_declined_keys_to(&mut self, key: OverlayKey)
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.
Sourcepub fn consume_overlay_key(&mut self)
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.
Sourcepub fn claim_hover(&mut self)
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
- Claim from the
Movearm on every move the local hit test passes, not just on entry. - A container claims after routing to its children: the first recorded claim wins.
- Keep an internal hovered flag from that hit test;
request_redrawonly when it changes. - In
paint, self-correct that flag fromPaintCtx::is_hovered, which is authoritative.
Sourcepub fn is_hovered(&self) -> bool
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.
Sourcepub fn set_cursor(&mut self, icon: CursorIcon)
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.
Sourcepub fn write_clipboard(&mut self, text: String)
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.
Sourcepub fn request_paste(&mut self)
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).
Sourcepub fn dispatch_edit_command(&mut self, cmd: EditCommand)
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.
Sourcepub fn take_edit_commands(&mut self) -> Vec<EditCommand>
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.
Sourcepub fn publish_ime_state(&mut self, state: ImeState)
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.