pub struct EventCtx<'a> { /* private fields */ }Expand description
A context provided to event-handling Widget methods.
Implementations§
Source§impl EventCtx<'_>
impl EventCtx<'_>
Sourcepub fn text_contexts(
&mut self,
) -> (&mut FontContext, &mut LayoutContext<BrushIndex>)
pub fn text_contexts( &mut self, ) -> (&mut FontContext, &mut LayoutContext<BrushIndex>)
Get the Parley contexts needed to build and paint text sections.
Most users should embed a pre-built label widget
(such as masonry::widgets::Label)
as a child for non-interactive text.
These contexts could however be useful for custom text editing, such as for rich text editing.
Any cached text layouts should be invalidated in the layout pass when Self::fonts_changed
returns true.
Sourcepub fn fonts_changed(&mut self) -> bool
pub fn fonts_changed(&mut self) -> bool
Whether the set of loaded fonts has changed since layout was most recently called.
Any cached text layouts should be invalidated in the layout pass when this is true.
Source§impl EventCtx<'_>
impl EventCtx<'_>
Sourcepub fn capture_pointer(&mut self)
pub fn capture_pointer(&mut self)
Capture the pointer in the current widget.
Pointer capture is only allowed during a Down event. It is a logic error to
capture the pointer during any other event.
A widget normally only receives pointer events when the pointer is inside the widget’s layout box. Pointer capture causes widget layout boxes to be ignored: when the pointer is captured by a widget, that widget will continue receiving pointer events when the pointer is outside the widget’s layout box. Other widgets the pointer is over will not receive events. Events that are not marked as handled by the capturing widget, bubble up to the widget’s ancestors, ignoring their layout boxes as well.
The pointer cannot be captured by multiple widgets at the same time. If a widget has captured the pointer and another widget captures it, the first widget loses the pointer capture.
§Releasing the pointer
Any widget can release the pointer during any event.
The pointer is automatically released after handling of a Up or Cancel event completes.
A widget holding the pointer capture will be the target of these events.
If pointer capture is lost for external reasons (the widget is disabled, the window lost focus,
etc), the widget will still get a Cancel event.
Sourcepub fn release_pointer(&mut self)
pub fn release_pointer(&mut self)
Release the pointer previously captured through capture_pointer.
Sourcepub fn request_scroll_to_this(&mut self)
pub fn request_scroll_to_this(&mut self)
Send a signal to parent widgets to scroll this widget into view.
Sourcepub fn request_scroll_to(&mut self, rect: Rect)
pub fn request_scroll_to(&mut self, rect: Rect)
Send a signal to parent widgets to scroll this area into view.
rect is in local coordinates.
Sourcepub fn set_handled(&mut self)
pub fn set_handled(&mut self)
Set the event as “handled”, which stops its propagation to parent widgets.
Sourcepub fn is_handled(&self) -> bool
pub fn is_handled(&self) -> bool
Determine whether the event has been handled.
Sourcepub fn target(&self) -> WidgetId
pub fn target(&self) -> WidgetId
The widget originally targeted by the event.
This will be different from widget_id during event bubbling.
Sourcepub fn request_focus(&mut self)
pub fn request_focus(&mut self)
Request text focus.
Because only one widget can be focused at a time, multiple focus requests from different widgets during a single event cycle means that the last widget that requests focus will override the previous requests.
Sourcepub fn set_focus(&mut self, target: WidgetId)
pub fn set_focus(&mut self, target: WidgetId)
Transfer text focus to the widget with the given WidgetId.
Sourcepub fn resign_focus(&mut self)
pub fn resign_focus(&mut self)
Give up text focus.
This should only be called by a widget that currently has focus.
Sourcepub fn local_position(&self, p: PhysicalPosition<f64>) -> Point
pub fn local_position(&self, p: PhysicalPosition<f64>) -> Point
Translate window position to widget local position.
Source§impl EventCtx<'_>
impl EventCtx<'_>
Sourcepub fn size(&self) -> Size
pub fn size(&self) -> Size
The layout size.
This is roughly the layout size returned by the layout method on
the previous layout pass, with some adjustment for pixel snapping.
Sourcepub fn baseline_offset(&self) -> f64
pub fn baseline_offset(&self) -> f64
The offset of the baseline relative to the bottom of the widget.
Sourcepub fn window_origin(&self) -> Point
pub fn window_origin(&self) -> Point
The origin of the widget in window coordinates, relative to the top left corner of the content area.
Sourcepub fn window_transform(&self) -> Affine
pub fn window_transform(&self) -> Affine
Global transform of this widget in the window coordinate space.
Computed from all transform and scroll_translation values from this to the root widget.
Sourcepub fn bounding_rect(&self) -> Rect
pub fn bounding_rect(&self) -> Rect
The bounding rect of the widget in window coordinates.
See bounding rect documentation for details.
Sourcepub fn paint_rect(&self) -> Rect
pub fn paint_rect(&self) -> Rect
The paint rect of the widget.
Covers the area we expect to be invalidated when the widget is painted.
Sourcepub fn clip_path(&self) -> Option<Rect>
pub fn clip_path(&self) -> Option<Rect>
The clip path of the widget, if any was set.
For more information, see
LayoutCtx::set_clip_path.
Source§impl EventCtx<'_>
impl EventCtx<'_>
Sourcepub fn get_scale_factor(&self) -> f64
pub fn get_scale_factor(&self) -> f64
Get DPI scaling factor.
This is not required for most widgets, and should be used only for precise
rendering, such as rendering single pixel lines or selecting image variants.
This is currently only provided in the render stages, as these are the only passes which
are re-run when the scale factor changes, except EventCtx where it is necessary to
translate pointer events which are currently in physical coordinates.
Note that accessibility nodes and paint results will automatically be scaled by Masonry. This also doesn’t account for the widget’s current transform, which cannot currently be accessed by widgets directly.
Source§impl EventCtx<'_>
impl EventCtx<'_>
Sourcepub fn is_hovered(&self) -> bool
pub fn is_hovered(&self) -> bool
The “hovered” status of a widget.
A widget is “hovered” when a pointer is hovering over it. Widgets will often change their appearance as a visual indication that they will respond to pointer (usually mouse) interaction.
If the pointer is captured, then only the capturing widget can have hovered status. If the pointer is captured but not hovering over the captured widget, then no widget has the hovered status.
Sourcepub fn has_hovered(&self) -> bool
pub fn has_hovered(&self) -> bool
Whether this widget or any of its descendants are hovered.
To check if only this specific widget is hovered use is_hovered.
Sourcepub fn is_active(&self) -> bool
pub fn is_active(&self) -> bool
The “active” status of a widget.
A widget is “active” when the user is “actively” interacting with it. Currently, a widget is determined to be active when it has captured a pointer, but this may change in the future to account for e.g. keyboard interactions.
Sourcepub fn has_active(&self) -> bool
pub fn has_active(&self) -> bool
Whether this widget or any of its descendants are active.
To check if only this specific widget is active use is_active.
Sourcepub fn is_pointer_capture_target(&self) -> bool
pub fn is_pointer_capture_target(&self) -> bool
Whether a pointer is captured by this widget.
The pointer will usually be the mouse. In future versions, this function will take a pointer id as input to test a specific pointer.
Sourcepub fn is_focus_target(&self) -> bool
pub fn is_focus_target(&self) -> bool
The text focus status of a widget.
The focused widget is the one that receives keyboard events.
Returns true if this specific widget is focused.
To check if any descendants are focused use has_focus_target.
Sourcepub fn has_focus_target(&self) -> bool
pub fn has_focus_target(&self) -> bool
Whether this widget or any of its descendants are focused.
To check if only this specific widget is focused use is_focus_target.
Sourcepub fn is_window_focused(&self) -> bool
pub fn is_window_focused(&self) -> bool
Whether the window is focused.
Sourcepub fn accepts_pointer_interaction(&self) -> bool
pub fn accepts_pointer_interaction(&self) -> bool
Whether this widget gets pointer events and hovered status.
Sourcepub fn accepts_focus(&self) -> bool
pub fn accepts_focus(&self) -> bool
Whether this widget gets text focus.
Sourcepub fn accepts_text_input(&self) -> bool
pub fn accepts_text_input(&self) -> bool
Whether this widget gets IME events.
Sourcepub fn is_disabled(&self) -> bool
pub fn is_disabled(&self) -> bool
Whether this widget is disabled.
Returns true if this widget or any of its ancestors is explicitly disabled.
To make this widget explicitly disabled use set_disabled.
Sourcepub fn is_stashed(&self) -> bool
pub fn is_stashed(&self) -> bool
Whether this widget is stashed.
Source§impl EventCtx<'_>
impl EventCtx<'_>
Sourcepub fn request_render(&mut self)
pub fn request_render(&mut self)
Request a paint and an accessibility pass.
Sourcepub fn request_paint_only(&mut self)
pub fn request_paint_only(&mut self)
Request a paint pass, specifically for the paint method.
Unlike request_render, this does not request an accessibility pass or a call to post_paint.
Use request_render unless you’re sure neither is needed.
Sourcepub fn request_post_paint(&mut self)
pub fn request_post_paint(&mut self)
Request a paint pass for the post_paint method.
Sourcepub fn request_accessibility_update(&mut self)
pub fn request_accessibility_update(&mut self)
Request an accessibility pass.
This doesn’t request a paint pass.
If you want to request both an accessibility pass and a paint pass, use request_render.
Sourcepub fn request_layout(&mut self)
pub fn request_layout(&mut self)
Request a layout pass.
Call this method if the widget has changed in a way that requires a layout pass.
Sourcepub fn request_compose(&mut self)
pub fn request_compose(&mut self)
Request a compose pass.
The compose pass is often cheaper than the layout pass, because it can only transform individual widgets’ position.
Sourcepub fn request_anim_frame(&mut self)
pub fn request_anim_frame(&mut self)
Request an animation frame.
Sourcepub fn request_cursor_icon_change(&mut self)
pub fn request_cursor_icon_change(&mut self)
Notifies Masonry that the cursor returned by Widget::get_cursor has changed.
This is mostly meant for cases where the cursor changes even if the pointer doesn’t move, because the nature of the widget has changed somehow.
Sourcepub fn children_changed(&mut self)
pub fn children_changed(&mut self)
Indicate that your children have changed.
Widgets must call this method after adding a new child.
Sourcepub fn remove_child(&mut self, child: WidgetPod<impl Widget + ?Sized>)
pub fn remove_child(&mut self, child: WidgetPod<impl Widget + ?Sized>)
Indicate that a child is about to be removed from the tree.
Container widgets should avoid dropping WidgetPods. Instead, they should
pass them to this method.
Sourcepub fn set_disabled(&mut self, disabled: bool)
pub fn set_disabled(&mut self, disabled: bool)
Set the disabled state for this widget.
Setting this to false does not mean a widget is not still disabled; for instance it may
still be disabled by an ancestor. See is_disabled for more information.
Sourcepub fn set_transform(&mut self, transform: Affine)
pub fn set_transform(&mut self, transform: Affine)
Set the transform for this widget.
It behaves similarly as CSS transforms
Source§impl EventCtx<'_>
impl EventCtx<'_>
Sourcepub fn set_stashed(
&mut self,
child: &mut WidgetPod<impl Widget + ?Sized>,
stashed: bool,
)
pub fn set_stashed( &mut self, child: &mut WidgetPod<impl Widget + ?Sized>, stashed: bool, )
Mark child widget as stashed.
If stashed is true, the child will not be painted or listed in the accessibility tree.
This will not trigger a layout pass.
Sourcepub fn mutate_self_later(
&mut self,
f: impl FnOnce(WidgetMut<'_, dyn Widget>) + Send + 'static,
)
pub fn mutate_self_later( &mut self, f: impl FnOnce(WidgetMut<'_, dyn Widget>) + Send + 'static, )
Queue a callback that will be called with a WidgetMut for this widget.
The callbacks will be run in the order they were submitted during the mutate pass.
Sourcepub fn mutate_later<W: Widget + FromDynWidget + ?Sized>(
&mut self,
child: &mut WidgetPod<W>,
f: impl FnOnce(WidgetMut<'_, W>) + Send + 'static,
)
pub fn mutate_later<W: Widget + FromDynWidget + ?Sized>( &mut self, child: &mut WidgetPod<W>, f: impl FnOnce(WidgetMut<'_, W>) + Send + 'static, )
Queue a callback that will be called with a WidgetMut for the given child widget.
The callbacks will be run in the order they were submitted during the mutate pass.
Sourcepub fn get_raw<Child: Widget + FromDynWidget + ?Sized>(
&mut self,
child: &mut WidgetPod<Child>,
) -> (&Child, RawCtx<'_>)
pub fn get_raw<Child: Widget + FromDynWidget + ?Sized>( &mut self, child: &mut WidgetPod<Child>, ) -> (&Child, RawCtx<'_>)
Get direct reference to the stored child, and a context handle for that child.
Sourcepub fn get_raw_mut<Child: Widget + FromDynWidget + AllowRawMut + ?Sized>(
&mut self,
child: &mut WidgetPod<Child>,
) -> (&mut Child, RawCtx<'_>)
pub fn get_raw_mut<Child: Widget + FromDynWidget + AllowRawMut + ?Sized>( &mut self, child: &mut WidgetPod<Child>, ) -> (&mut Child, RawCtx<'_>)
Get direct mutable reference to the stored child, and a context handle for that child.
This context lets you set pass flags for the child widget, which may be tricky. In general, you should avoid setting the flags of a pass that runs before the pass you’re currently in. Not doing so might lead to performance cliffs and, hypothetically, panics.
This method is an escape hatch for cases where a parent widget completely
controls their child, but needs it to be a separate widget for user interaction to
behave as expected.
As such, the child widget must opt-in using the AllowRawMut trait.
See pass documentation for the pass order.
Sourcepub fn submit_action<Action: AnyDebug + Send>(
&mut self,
action: impl Into<Action>,
)
pub fn submit_action<Action: AnyDebug + Send>( &mut self, action: impl Into<Action>, )
Submit an action, which indicates that this widget requires something be handled by the application, such as user input.
The Action type parameter should always be the Self::Action associated type
of the widget you’re calling this method from.
Masonry will validate this, and this method may panic if this isn’t the case.
For further details see ErasedAction.
Sourcepub fn submit_untyped_action(&mut self, action: ErasedAction)
pub fn submit_untyped_action(&mut self, action: ErasedAction)
Submit a type-erased action.
Unlike Self::submit_action, this method lets you submit an action with an
arbitrary type, which may not match Self::Action.
This may act as an escape hatch in some situations.
For further details see ErasedAction.
Sourcepub fn set_ime_area(&mut self, ime_area: Rect)
pub fn set_ime_area(&mut self, ime_area: Rect)
Set the IME cursor area.
When this widget is focused and accepts text input, the reported IME area is sent to the platform. The area can be used by the platform to, for example, place a candidate box near that area, while ensuring the area is not obscured.
If no IME area is set, the platform will use the widget’s layout rect.
Sourcepub fn clear_ime_area(&mut self)
pub fn clear_ime_area(&mut self)
Remove the IME cursor area.
See LayoutCtx::set_ime_area for more details.
Sourcepub fn set_clipboard(&mut self, contents: String)
pub fn set_clipboard(&mut self, contents: String)
Set the contents of the platform clipboard.
For example, text widgets should call this for “cut” and “copy” user interactions. Note that we currently don’t support the “Primary” selection buffer on X11/Wayland.
Sourcepub fn drag_window(&mut self)
pub fn drag_window(&mut self)
Start a window drag.
Moves the window with the left mouse button until the button is released.
Sourcepub fn drag_resize_window(&mut self, direction: ResizeDirection)
pub fn drag_resize_window(&mut self, direction: ResizeDirection)
Start a window resize.
Resizes the window with the left mouse button until the button is released.
Sourcepub fn toggle_maximized(&mut self)
pub fn toggle_maximized(&mut self)
Toggle the maximized state of the window.
Show the window menu at a specified position.
Sourcepub fn create_layer<W: Widget + ?Sized>(
&mut self,
root_widget: NewWidget<W>,
position: Point,
)
pub fn create_layer<W: Widget + ?Sized>( &mut self, root_widget: NewWidget<W>, position: Point, )
Create a new layer at a specified position.
Sourcepub fn remove_layer(&mut self, root_widget_id: WidgetId)
pub fn remove_layer(&mut self, root_widget_id: WidgetId)
Remove the layer with the specified widget as root.
Sourcepub fn reposition_layer(&mut self, root_widget_id: WidgetId, position: Point)
pub fn reposition_layer(&mut self, root_widget_id: WidgetId, position: Point)
Reposition the layer with the specified widget as root.