Skip to main content

Actions

Struct Actions 

Source
pub struct Actions {
    pub key: Option<KeyRef>,
    pub dispatcher: Option<ActionDispatcherRef>,
    pub actions: HashMap<TypeId, ActionRef>,
    pub child: WidgetRef,
}
Expand description

A widget that maps Intents to Actions to be used by its descendants when invoking an Action.

Actions are typically invoked using Shortcuts. They can also be invoked using Actions::invoke on a context containing an ambient Actions widget.

See also:

  • Shortcuts, a widget used to bind key combinations to Intents.
  • Intent, a trait for values that contain configuration information for running an Action.
  • Action, a trait for containing and defining an invocation of a user action.
  • ActionDispatcher, the object that this widget uses to manage actions.

Fields§

§key: Option<KeyRef>§dispatcher: Option<ActionDispatcherRef>

The ActionDispatcher object that invokes actions.

This is what is returned from Actions::of, and used by Actions::invoke.

If this dispatcher is None, then Actions::of and Actions::invoke will look up the tree until they find an Actions widget that has a dispatcher set. If no such widget is found, then they will return/use a PlainActionDispatcher.

§actions: HashMap<TypeId, ActionRef>

A map of Intent types to Action objects that defines which actions this widget knows about.

For performance reasons, it is recommended that a pre-built map is passed in here instead of defining it inline in the build function.

§child: WidgetRef

The widget below this widget in the tree.

Implementations§

Source§

impl Actions

Source

pub fn new<K>( actions: HashMap<TypeId, ActionRef>, child: impl IntoWidget<K>, ) -> Actions

Creates an Actions widget.

Source

pub fn key(self, key: KeyRef) -> Actions

Dart Actions(key:).

Source

pub fn dispatcher(self, dispatcher: ActionDispatcherRef) -> Actions

Dart Actions(dispatcher:).

Source

pub fn handler( app: &mut App, context: BuildContext, intent: IntentRef, ) -> Option<Listener>

Returns a handler that invokes the bound action for the given intent if the action is enabled, and returns None if the action is not enabled, or no matching action is found.

This is intended to be used in widgets which have something similar to an on_tap handler, which takes a GestureTapCallback, and can be set to the result of calling this function.

Creates a dependency on the Actions widget that maps the bound action so that if the actions change, the context will be rebuilt and find the updated action.

The value returned from Action::invoke is discarded when the returned callback is called. If the return value is needed, consider using Actions::invoke instead.

Source

pub fn find( app: &mut App, context: BuildContext, intent_type: TypeId, ) -> AnyAction

Finds the Action bound to the given intent_type in the given context.

Creates a dependency on the Actions widget that maps the bound action so that if the actions change, the context will be rebuilt and find the updated action.

If no Actions widget surrounds the given context, or no action is bound to intent_type, this function panics.

See also:

  • maybe_find, which is similar to this function, but will return None if no Actions ancestor is found.
Source

pub fn maybe_find( app: &mut App, context: BuildContext, intent_type: TypeId, ) -> Option<AnyAction>

Finds the Action bound to the given intent_type in the given context.

Creates a dependency on the Actions widget that maps the bound action so that if the actions change, the context will be rebuilt and find the updated action.

If no Actions widget surrounds the given context, this function returns None.

See also:

  • find, which is similar to this function, but will panic if no Actions ancestor is found.
Source

pub fn of(app: &mut App, context: BuildContext) -> ActionDispatcherRef

Returns the ActionDispatcher associated with the Actions widget that most tightly encloses the given BuildContext.

Will return a newly created PlainActionDispatcher if no ambient Actions widget is found.

Source

pub fn invoke( app: &mut App, context: BuildContext, intent: &dyn Intent, ) -> Option<Rc<dyn Any>>

Invokes the action associated with the given Intent using the Actions widget that most tightly encloses the given BuildContext.

This method returns the result of invoking the action’s Action::invoke method.

If the given intent doesn’t map to an action, then it will look to the next ancestor Actions widget in the hierarchy until it reaches the root.

This method panics if no ambient Actions widget is found.

Source

pub fn maybe_invoke( app: &mut App, context: BuildContext, intent: &dyn Intent, ) -> Option<Rc<dyn Any>>

Invokes the action associated with the given Intent using the Actions widget that most tightly encloses the given BuildContext.

This method returns the result of invoking the action’s Action::invoke method. If no action mapping was found for the specified intent, or if the first action found was disabled, or the action itself returns None from Action::invoke, then this method returns None.

If the given intent doesn’t map to an action, then it will look to the next ancestor Actions widget in the hierarchy until it reaches the root. If a suitable Action is found but its AnyAction::is_enabled returns false, the search will stop and this method will return None.

Trait Implementations§

Source§

impl Debug for Actions

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl StatefulWidget for Actions

Source§

type State = ActionsState

The state this widget creates.
Source§

fn key(&self) -> Option<&KeyRef>

Source§

fn debug_fill_properties( &self, _app: &App, properties: &mut DiagnosticPropertiesBuilder, )

Dart’s debugFillProperties: the properties a dump shows for this widget, in Dart’s order. Dart’s Widget base only sets the dense tree style, which the framework does.
Source§

fn create_state(&self) -> ActionsState

Creates the mutable state for this widget at a given location in the tree. Read more
Source§

fn debug_check_constructor(&self)

Source§

fn as_preferred_size_widget(&self) -> Option<&dyn PreferredSizeWidget>

Source§

fn type_name(&self) -> &'static str

See Widget::type_name. A stateful form another widget kind becomes (an animated or status transition widget) names the widget it wraps.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Actions

§

impl !Send for Actions

§

impl !Sync for Actions

§

impl !UnwindSafe for Actions

§

impl Forget for Actions

§

impl Freeze for Actions
where *const RcInner<dyn Key> is !null: Freeze, PhantomData<RcInner<dyn Key>>: Freeze, *const RcInner<dyn ActionDispatcher> is !null: Freeze, PhantomData<RcInner<dyn ActionDispatcher>>: Freeze, *const u8 is !null: Freeze, PhantomData<(TypeId, Retained<AnyAction>)>: Freeze, *const RcInner<dyn Widget> is !null: Freeze, PhantomData<RcInner<dyn Widget>>: Freeze,

§

impl Move for Actions

§

impl Unpin for Actions
where Rc<dyn Key>: Unpin, Rc<dyn ActionDispatcher>: Unpin, *const u8 is !null: Unpin, *const (): Unpin, NonZero<u32>: Unpin, &'static ActionVTable: Unpin, Rc<Keep>: Unpin, Rc<dyn Widget>: Unpin,

§

impl UnsafeUnpin for Actions
where *const RcInner<dyn Key> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Key>>: UnsafeUnpin, *const RcInner<dyn ActionDispatcher> is !null: UnsafeUnpin, PhantomData<RcInner<dyn ActionDispatcher>>: UnsafeUnpin, *const u8 is !null: UnsafeUnpin, PhantomData<(TypeId, Retained<AnyAction>)>: UnsafeUnpin, *const RcInner<dyn Widget> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Widget>>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<W> IntoWidget<StatefulKind> for W
where W: StatefulWidget,

Source§

fn into_widget(self) -> Rc<dyn Widget>

The widget as a tree node, made where this is called: its creation_location.
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>