Struct druid::Notification

source ·
pub struct Notification { /* private fields */ }
Expand description

A message passed up the tree from a Widget to its ancestors.

In the course of handling an event, a Widget may change some internal state that is of interest to one of its ancestors. In this case, the widget may submit a Notification.

In practice, a Notification is very similar to a Command; the main distinction relates to delivery. Commands are delivered from the root of the tree down towards the target, and this delivery occurs after the originating event call has returned. Notifications are delivered up the tree, and this occurs during event handling; immediately after the child widget’s event method returns, the notification will be delivered to the child’s parent, and then the parent’s parent, until the notification is handled.

Implementations§

Returns true if self matches this Selector.

Returns the payload for this Selector, if the selector matches.

Panics

Panics when the payload has a different type, than what the selector is supposed to carry. This can happen when two selectors with different types but the same key are used.

The [WidgetId] of the Widget that sent this Notification.

Builder-style method to set warn_if_unused.

The default is true.

Returns whether there should be a warning when no widget handles this notification.

The [WidgetId] of the last Widget that this Notification was passed through.

Example
fn event(&mut self, ctx: &mut EventCtx, event: &Event, data: &mut (), env: &Env) {
    if let Event::Notification(notification) = event {
        if notification.route() == self.widget1.id() {
            // the notification came from inside of widget1
        }
        if notification.route() == self.widget2.id() {
            // the notification came from inside of widget2
        }
    }
}

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Performs the conversion.
Performs the conversion.
Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more