Skip to main content

EventCtx

Struct EventCtx 

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

A context provided to event handlers registered with Ui::event.

EventCtx is the primary interface for nodes to respond to user input. It provides:

  • State Updates: Methods to set focus, capture the pointer, or mark a node as active.
  • Event Data: Access to specific event details like pointer coordinates or keyboard keys.
  • Propagation Control: Ability to stop events from bubbling up the tree or to prevent default window actions.
  • Layout Info: Access to the node’s computed size and position.

It also provides a handle to the platform, allowing the callback to trigger system-level actions like opening URLs or changing the cursor.

Implementations§

Source§

impl<'a, H> EventCtx<'a, H>

Source

pub fn platform(&self) -> &H

Returns a handle provided by the platform integration. The default platform integration returns a rosin::handle::WindowHandle.

Source

pub fn set_active(&mut self, id: Option<NodeId>)

Sets the currently active node. This makes :active CSS selectors apply to the node. Purely cosmetic.

You can pass None to deactivate.

Source

pub fn is_active(&self) -> bool

Returns true if the current node is active.

Source

pub fn is_enabled(&self) -> bool

Returns true if the current node is enabled.

A node’s enabled status is controlled by a UIParam passed to Ui::enabled when building the tree.

Source

pub fn set_focus(&mut self, id: Option<NodeId>)

Sets the currently focused node. This makes :focus CSS selectors apply to the node, and routes On::Keyboard events to it.

You can pass None to unfocus.

Source

pub fn focus_next(&mut self)

Transfers focus to the next focusable node node in the tree. If nothing is focused, the first focusable node in the tree will gain focus.

Source

pub fn focus_previous(&mut self)

Transfers focus to the previous focusable node node in the tree. If nothing is focused, the last focusable node in the tree will gain focus.

Source

pub fn is_focused(&self) -> bool

Returns true if the current node is focused.

Source

pub fn viewport_size(&self) -> Size

Returns the size of the total drawable area of the viewport in logical pixels.

Source

pub fn style(&self) -> &Style

Returns the computed style for this node.

Source

pub fn rect(&self) -> &RoundedRect

Returns the final laid-out rectangle of this node.

Source

pub fn id(&self) -> Option<NodeId>

Return the current node’s id, if it has one.

  • In debug builds, this will log an error if there is no id for the node.
Source

pub fn event_type(&self) -> On

Returns the type of event that triggered this callback.

Source

pub fn pointer_delta(&self) -> Option<Vec2>

Returns the change in position between this pointer event and the previous, if available. The first pointer event fired when the cursor enters the viewport will not have a delta.

Source

pub fn perf_info(&self) -> &PerfInfo

Returns some information about how long it took to render the previous frame.

Source

pub fn get_translation_map(&self) -> TranslationMap

Returns the global map of translations.

Source

pub fn begin_pointer_capture(&mut self)

Begins capturing pointer events. When captured, the pointer is treated as if it is always inside the node, so On::PointerEnter and On::PointerLeave events will never fire.

  • In debug builds, this will log an error if there is no id for the node.
Source

pub fn end_pointer_capture(&mut self)

Releases the pointer capture, so other nodes can start receiving pointer events again.

Source

pub fn is_pointer_captured(&self) -> bool

Returns true if this node has captured the pointer.

Source

pub fn stop_propagation(&mut self)

Stop a pointer event from bubbling up to ancestor nodes. On::PointerEnter and On::PointerLeave events do not bubble.

  • In debug builds, this will log an error if called from a non-pointer event.
Source

pub fn emit_change(&mut self)

Requests an On::Change dispatch after this callback returns.

The dispatcher will queue On::Change on this node (if it handles it), otherwise on the first ancestor with an On::Change handler. If the current event is On::Change, it will only look for an ancestor to avoid re-queuing the same handler.

Source

pub fn stop_window_close(&mut self)

Stops the window from closing.

  • In debug builds, this will log an error if not called from the root node’s On::WindowClose handler.
Source

pub fn pointer(&self) -> Option<&PointerEvent>

In pointer event handlers, this returns the complete pointer event info.

Source

pub fn local_pointer_pos(&self) -> Option<Point>

If available, returns the position of the pointer event relative to the top-left of the current node.

Source

pub fn keyboard(&self) -> Option<&KeyboardEvent>

In On::Keyboard handlers, this returns the keyboard event info.

Source

pub fn dt(&self) -> Option<&Duration>

In On::AnimationFrame handlers, this returns the duration since the last animation frame.

Source

pub fn file_dialog_response(&self) -> Option<&FileDialogResponse>

In On::FileDialog handlers, this returns the information returned by the requested file dialog.

Source

pub fn command_id(&self) -> Option<CommandId>

In On::Command handlers, this returns the CommandId associated with the menu item picked.

Source

pub fn action_request(&self) -> Option<&ActionRequest>

In On::AccessibilityAction handlers, this returns the AccessKit action request info.

Source

pub fn info(&self) -> &EventInfo

Returns the raw event payload for this callback.

This is the same data accessed by the typed helpers like EventCtx::pointer, EventCtx::keyboard, etc.

Source

pub fn padding_box(&self) -> Rect

Returns the rect just inside the borders of the node. Doesn’t account for rounded corners.

Source

pub fn max_content_width(&self) -> f32

Returns the maximum width content could be before overflowing the node.

Auto Trait Implementations§

§

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

§

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

§

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

§

impl<'a, H> Send for EventCtx<'a, H>
where H: Sync,

§

impl<'a, H> Sync for EventCtx<'a, H>
where H: Sync,

§

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

§

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

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<T> for T

Source§

fn downcast(&self) -> &T

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, 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> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,