[][src]Struct druid::EventCtx

pub struct EventCtx<'a, 'b> { /* fields omitted */ }

A mutable 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

impl EventCtx<'_, '_>[src]

pub fn widget_id(&self) -> WidgetId[src]

get the WidgetId of the current widget.

pub fn window(&self) -> &WindowHandle[src]

Returns a reference to the current WindowHandle.

pub fn window_id(&self) -> WindowId[src]

Get the WindowId of the current window.

pub fn text(&mut self) -> &mut PietText[src]

Get an object which can create text layouts.

impl EventCtx<'_, '_>[src]

pub fn size(&self) -> Size[src]

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.

pub fn is_hot(&self) -> bool[src]

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.

pub fn is_active(&self) -> bool[src]

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.

pub fn is_focused(&self) -> bool[src]

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.

pub fn has_focus(&self) -> bool[src]

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,

impl EventCtx<'_, '_>[src]

pub fn set_cursor(&mut self, cursor: &Cursor)[src]

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.)

pub fn override_cursor(&mut self, cursor: &Cursor)[src]

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.)

pub fn clear_cursor(&mut self)[src]

Clear the cursor icon.

This undoes the effect of set_cursor and override_cursor.

impl EventCtx<'_, '_>[src]

pub fn request_paint(&mut self)[src]

Request a paint pass. This is equivalent to calling request_paint_rect for the widget's paint_rect.

pub fn request_paint_rect(&mut self, rect: Rect)[src]

Request a paint pass for redrawing a rectangle, which is given relative to our layout rectangle.

pub fn request_layout(&mut self)[src]

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_anim_frame(&mut self)[src]

Request an animation frame.

pub fn children_changed(&mut self)[src]

Indicate that your children have changed.

Widgets must call this method after adding a new child.

pub fn set_menu<T: Any>(&mut self, menu: MenuDesc<T>)[src]

Set the menu of the window containing the current widget. T must be the application's root Data type (the type provided to AppLauncher::launch).

impl EventCtx<'_, '_>[src]

pub fn submit_command(&mut self, cmd: impl Into<Command>)[src]

Submit a Command to be run after this event is handled.

Commands are run in the order they are submitted; all commands submitted during the handling of an event are executed before the update method is called; events submitted during update are handled after painting.

Target::Auto commands will be sent to the window containing the widget.

pub fn get_external_handle(&self) -> ExtEventSink[src]

Returns an ExtEventSink that can be moved between threads, and can be used to submit commands back to the application.

pub fn request_timer(&mut self, deadline: Duration) -> TimerToken[src]

Request a timer event.

The return value is a token, which can be used to associate the request with the event.

impl EventCtx<'_, '_>[src]

pub fn submit_notification(&mut self, note: impl Into<Command>)[src]

Submit a Notification.

The provided argument can be a Selector or a Command; this lets us work with the existing API for addding a payload to a Selector.

If the argument is a Command, the command's target will be ignored.

Examples

const IMPORTANT_EVENT: Selector<String> = Selector::new("druid-example.important-event");

fn check_event(ctx: &mut EventCtx, event: &Event) {
    if is_this_the_event_we_were_looking_for(event) {
        ctx.submit_notification(IMPORTANT_EVENT.with("That's the one".to_string()))
    }
}

pub fn set_active(&mut self, active: bool)[src]

Set the "active" state of the widget.

See EventCtx::is_active.

pub fn new_window<T: Any>(&mut self, desc: WindowDesc<T>)[src]

Create a new window. T must be the application's root Data type (the type provided to AppLauncher::launch).

pub fn show_context_menu<T: Any>(&mut self, menu: ContextMenu<T>)[src]

Show the context menu in the window containing the current widget. T must be the application's root Data type (the type provided to AppLauncher::launch).

pub fn set_handled(&mut self)[src]

Set the event as "handled", which stops its propagation to other widgets.

pub fn is_handled(&self) -> bool[src]

Determine whether the event has been handled by some other widget.

pub fn request_focus(&mut self)[src]

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.

pub fn set_focus(&mut self, target: WidgetId)[src]

Transfer focus to the widget with the given WidgetId.

See is_focused for more information about focus.

pub fn focus_next(&mut self)[src]

Transfer focus to the next focusable widget.

This should only be called by a widget that currently has focus.

See is_focused for more information about focus.

pub fn focus_prev(&mut self)[src]

Transfer focus to the previous focusable widget.

This should only be called by a widget that currently has focus.

See is_focused for more information about focus.

pub fn resign_focus(&mut self)[src]

Give up focus.

This should only be called by a widget that currently has focus.

See is_focused for more information about focus.

pub fn request_update(&mut self)[src]

Request an update cycle.

After this, update will be called on the widget in the next update cycle, even if there's not a data change.

The use case for this method is when a container widget synthesizes data for its children. This is appropriate in specialized cases, but before reaching for this method, consider whether it might be better to refactor to be more idiomatic, in particular to make that data available in the app state.

Auto Trait Implementations

impl<'a, 'b> !RefUnwindSafe for EventCtx<'a, 'b>[src]

impl<'a, 'b> !Send for EventCtx<'a, 'b>[src]

impl<'a, 'b> !Sync for EventCtx<'a, 'b>[src]

impl<'a, 'b> Unpin for EventCtx<'a, 'b> where
    'b: 'a, 
[src]

impl<'a, 'b> !UnwindSafe for EventCtx<'a, 'b>[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> RoundFrom<T> for T

impl<T, U> RoundInto<U> for T where
    U: RoundFrom<T>, 

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.