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>
impl<'a, H> EventCtx<'a, H>
Sourcepub fn platform(&self) -> &H
pub fn platform(&self) -> &H
Returns a handle provided by the platform integration.
The default platform integration returns a rosin::handle::WindowHandle.
Sourcepub fn set_active(&mut self, id: Option<NodeId>)
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.
Sourcepub fn is_enabled(&self) -> bool
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.
Sourcepub fn set_focus(&mut self, id: Option<NodeId>)
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.
Sourcepub fn focus_next(&mut self)
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.
Sourcepub fn focus_previous(&mut self)
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.
Sourcepub fn is_focused(&self) -> bool
pub fn is_focused(&self) -> bool
Returns true if the current node is focused.
Sourcepub fn viewport_size(&self) -> Size
pub fn viewport_size(&self) -> Size
Returns the size of the total drawable area of the viewport in logical pixels.
Sourcepub fn rect(&self) -> &RoundedRect
pub fn rect(&self) -> &RoundedRect
Returns the final laid-out rectangle of this node.
Sourcepub fn id(&self) -> Option<NodeId>
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.
Sourcepub fn event_type(&self) -> On
pub fn event_type(&self) -> On
Returns the type of event that triggered this callback.
Sourcepub fn pointer_delta(&self) -> Option<Vec2>
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.
Sourcepub fn perf_info(&self) -> &PerfInfo
pub fn perf_info(&self) -> &PerfInfo
Returns some information about how long it took to render the previous frame.
Sourcepub fn get_translation_map(&self) -> TranslationMap
pub fn get_translation_map(&self) -> TranslationMap
Returns the global map of translations.
Sourcepub fn begin_pointer_capture(&mut self)
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.
Sourcepub fn end_pointer_capture(&mut self)
pub fn end_pointer_capture(&mut self)
Releases the pointer capture, so other nodes can start receiving pointer events again.
Sourcepub fn is_pointer_captured(&self) -> bool
pub fn is_pointer_captured(&self) -> bool
Returns true if this node has captured the pointer.
Sourcepub fn stop_propagation(&mut self)
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.
Sourcepub fn emit_change(&mut self)
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.
Sourcepub fn stop_window_close(&mut self)
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::WindowClosehandler.
Sourcepub fn pointer(&self) -> Option<&PointerEvent>
pub fn pointer(&self) -> Option<&PointerEvent>
In pointer event handlers, this returns the complete pointer event info.
Sourcepub fn local_pointer_pos(&self) -> Option<Point>
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.
Sourcepub fn keyboard(&self) -> Option<&KeyboardEvent>
pub fn keyboard(&self) -> Option<&KeyboardEvent>
In On::Keyboard handlers, this returns the keyboard event info.
Sourcepub fn dt(&self) -> Option<&Duration>
pub fn dt(&self) -> Option<&Duration>
In On::AnimationFrame handlers, this returns the duration since the last animation frame.
Sourcepub fn file_dialog_response(&self) -> Option<&FileDialogResponse>
pub fn file_dialog_response(&self) -> Option<&FileDialogResponse>
In On::FileDialog handlers, this returns the information returned by the requested file dialog.
Sourcepub fn command_id(&self) -> Option<CommandId>
pub fn command_id(&self) -> Option<CommandId>
In On::Command handlers, this returns the CommandId associated with the menu item picked.
Sourcepub fn action_request(&self) -> Option<&ActionRequest>
pub fn action_request(&self) -> Option<&ActionRequest>
In On::AccessibilityAction handlers, this returns the AccessKit action request info.
Sourcepub fn info(&self) -> &EventInfo
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.
Sourcepub fn padding_box(&self) -> Rect
pub fn padding_box(&self) -> Rect
Returns the rect just inside the borders of the node. Doesn’t account for rounded corners.
Sourcepub fn max_content_width(&self) -> f32
pub fn max_content_width(&self) -> f32
Returns the maximum width content could be before overflowing the node.