pub struct EventCtx<'a> { /* private fields */ }
Expand description
A context provided to event handling methods of widgets.
Widgets should call request_paint
whenever an event causes a change
in the widget’s appearance, to schedule a repaint.
Implementations§
source§impl EventCtx<'_>
impl EventCtx<'_>
sourcepub fn skip_child(&self, child: &mut WidgetPod<impl Widget>)
pub fn skip_child(&self, child: &mut WidgetPod<impl Widget>)
Skip iterating over the given child.
Normally, container widgets are supposed to iterate over each of their child widgets in their methods. By default, the framework treats not doing so as a mistake, and panics if debug assertions are on.
This tells the framework that a child was deliberately skipped.
source§impl EventCtx<'_>
impl EventCtx<'_>
sourcepub fn size(&self) -> Size
pub fn size(&self) -> Size
The layout size.
This is the layout size as ultimately determined by the parent container, on the previous layout pass.
Generally it will be the same as the size returned by the child widget’s
layout
method.
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 to_window(&self, widget_point: Point) -> Point
pub fn to_window(&self, widget_point: Point) -> Point
Convert a point from the widget’s coordinate space to the window’s.
The returned point is relative to the content area; it excludes window chrome.
sourcepub fn is_hot(&self) -> bool
pub fn is_hot(&self) -> bool
The “hot” (aka hover) status of a widget.
A widget is “hot” when the mouse is hovered over it. Widgets will often change their appearance as a visual indication that they will respond to mouse interaction.
The hot status is computed from the widget’s layout rect. In a container hierarchy, all widgets with layout rects containing the mouse position have hot status.
Discussion: there is currently some confusion about whether a widget can be considered hot when some other widget is active (for example, when clicking to one widget and dragging to the next). The documentation should clearly state the resolution.
sourcepub fn is_active(&self) -> bool
pub fn is_active(&self) -> bool
The active status of a widget.
Active status generally corresponds to a mouse button down. Widgets
with behavior similar to a button will call set_active
on mouse
down and then up.
When a widget is active, it gets mouse events even when the mouse is dragged away.
sourcepub fn is_focused(&self) -> bool
pub fn is_focused(&self) -> bool
The focus status of a widget.
Returns true
if this specific widget is focused.
To check if any descendants are focused use has_focus
.
Focus means that the widget receives keyboard events.
A widget can request focus using the request_focus
method.
It’s also possible to register for automatic focus via register_for_focus
.
If a widget gains or loses focus it will get a LifeCycle::FocusChanged
event.
Only one widget at a time is focused. However due to the way events are routed, all ancestors of that widget will also receive keyboard events.
sourcepub fn has_focus(&self) -> bool
pub fn has_focus(&self) -> bool
The (tree) focus status of a widget.
Returns true
if either this specific widget or any one of its descendants is focused.
To check if only this specific widget is focused use is_focused
.
sourcepub fn is_disabled(&self) -> bool
pub fn is_disabled(&self) -> bool
The disabled state of a widget.
Returns true
if this widget or any of its ancestors is explicitly disabled.
To make this widget explicitly disabled use set_disabled
.
Disabled means that this widget should not change the state of the application. What
that means is not entirely clear but in any it should not change its data. Therefore
others can use this as a safety mechanism to prevent the application from entering an
illegal state.
For an example the decrease button of a counter of type usize
should be disabled if the
value is 0
.
sourcepub fn is_stashed(&self) -> bool
pub fn is_stashed(&self) -> bool
Check is widget is stashed.
Note: Stashed widgets are a WIP feature
source§impl EventCtx<'_>
impl EventCtx<'_>
sourcepub fn set_cursor(&mut self, cursor: &CursorIcon)
pub fn set_cursor(&mut self, cursor: &CursorIcon)
Set the cursor icon.
This setting will be retained until clear_cursor
is called, but it will only take
effect when this widget is either hot
or active
. If a child widget also sets a
cursor, the child widget’s cursor will take precedence. (If that isn’t what you want, use
override_cursor
instead.)
sourcepub fn override_cursor(&mut self, cursor: &CursorIcon)
pub fn override_cursor(&mut self, cursor: &CursorIcon)
Override the cursor icon.
This setting will be retained until clear_cursor
is called, but it will only take
effect when this widget is either hot
or active
. This will override the cursor
preferences of a child widget. (If that isn’t what you want, use set_cursor
instead.)
sourcepub fn clear_cursor(&mut self)
pub fn clear_cursor(&mut self)
Clear the cursor icon.
This undoes the effect of set_cursor
and override_cursor
.
source§impl EventCtx<'_>
impl EventCtx<'_>
sourcepub fn request_paint(&mut self)
pub fn request_paint(&mut self)
Request a paint
pass.
sourcepub fn request_layout(&mut self)
pub fn request_layout(&mut self)
Request a layout pass.
A Widget’s layout
method is always called when the widget tree
changes, or the window is resized.
If your widget would like to have layout called at any other time, (such as if it would like to change the layout of children in response to some event) it must call this method.
pub fn request_accessibility_update(&mut self)
sourcepub fn request_anim_frame(&mut self)
pub fn request_anim_frame(&mut self)
Request an animation frame.
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 or removing a child.
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.
Calling this method during LifeCycle::DisabledChanged
has no effect.
sourcepub fn set_stashed(&mut self, child: &mut WidgetPod<impl Widget>, stashed: bool)
pub fn set_stashed(&mut self, child: &mut WidgetPod<impl Widget>, stashed: bool)
Mark child widget as stashed.
Note: Stashed widgets are a WIP feature
sourcepub fn invalidate_text_input(&mut self, event: ImeChangeSignal)
pub fn invalidate_text_input(&mut self, event: ImeChangeSignal)
Indicate that text input state has changed.
A widget that accepts text input should call this anytime input state (such as the text or the selection) changes as a result of a non text-input event.
source§impl EventCtx<'_>
impl EventCtx<'_>
sourcepub fn submit_action(&mut self, action: Action)
pub fn submit_action(&mut self, action: Action)
Submit an Action
.
Note: Actions are still a WIP feature.
sourcepub fn run_in_background(
&mut self,
_background_task: impl FnOnce(WorkerCtx<'_>) + Send + 'static
)
pub fn run_in_background( &mut self, _background_task: impl FnOnce(WorkerCtx<'_>) + Send + 'static )
Run the provided function in the background.
The function takes a [WorkerCtx
] which it can use to
communicate with the main thread.
sourcepub fn compute_in_background<T: Any + Send>(
&mut self,
_background_task: impl FnOnce(WorkerCtx<'_>) -> T + Send + 'static
) -> PromiseToken<T>
pub fn compute_in_background<T: Any + Send>( &mut self, _background_task: impl FnOnce(WorkerCtx<'_>) -> T + Send + 'static ) -> PromiseToken<T>
Run the provided function in the background, and send its result once it’s done.
The function takes a [WorkerCtx
] which it can use to
communicate with the main thread.
Once the function returns, an Event::PromiseResult
is emitted with the return value.
sourcepub fn request_timer(&mut self, _deadline: Duration) -> TimerToken
pub fn request_timer(&mut self, _deadline: Duration) -> TimerToken
Request a timer event.
The return value is a token, which can be used to associate the request with the event.
source§impl EventCtx<'_>
impl EventCtx<'_>
sourcepub fn request_pan_to_this(&mut self)
pub fn request_pan_to_this(&mut self)
Send a signal to parent widgets to scroll this widget into view.
sourcepub fn set_active(&mut self, active: bool)
pub fn set_active(&mut self, active: bool)
Set the “active” state of the widget.
See EventCtx::is_active
.
sourcepub fn set_handled(&mut self)
pub fn set_handled(&mut self)
Set the event as “handled”, which stops its propagation to other widgets.
sourcepub fn is_handled(&self) -> bool
pub fn is_handled(&self) -> bool
Determine whether the event has been handled by some other widget.
sourcepub fn request_focus(&mut self)
pub fn request_focus(&mut self)
Request keyboard 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.
See is_focused
for more information about focus.
sourcepub fn set_focus(&mut self, target: WidgetId)
pub fn set_focus(&mut self, target: WidgetId)
Transfer focus to the widget with the given WidgetId
.
See is_focused
for more information about focus.
sourcepub fn resign_focus(&mut self)
pub fn resign_focus(&mut self)
Give up focus.
This should only be called by a widget that currently has focus.
See is_focused
for more information about focus.
Auto Trait Implementations§
impl<'a> Freeze for EventCtx<'a>
impl<'a> !RefUnwindSafe for EventCtx<'a>
impl<'a> !Send for EventCtx<'a>
impl<'a> !Sync for EventCtx<'a>
impl<'a> Unpin for EventCtx<'a>
impl<'a> !UnwindSafe for EventCtx<'a>
Blanket Implementations§
source§impl<T> AsAny for Twhere
T: Any,
impl<T> AsAny for Twhere
T: Any,
source§fn as_dyn_any(&self) -> &(dyn Any + 'static)
fn as_dyn_any(&self) -> &(dyn Any + 'static)
source§fn as_mut_dyn_any(&mut self) -> &mut (dyn Any + 'static)
fn as_mut_dyn_any(&mut self) -> &mut (dyn Any + 'static)
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.