Skip to main content

MenuItemButton

Struct MenuItemButton 

Source
pub struct MenuItemButton {
Show 17 fields pub key: Option<KeyRef>, pub on_pressed: Option<Listener>, pub on_hover: Option<ValueChanged<bool>>, pub request_focus_on_hover: bool, pub on_focus_change: Option<ValueChanged<bool>>, pub focus_node: Option<FocusNodeRef>, pub autofocus: bool, pub shortcut: Option<MenuSerializableShortcutRef>, pub semantics_label: Option<String>, pub style: Option<ButtonStyle>, pub states_controller: Option<Ref<WidgetStatesController>>, pub clip_behavior: Clip, pub leading_icon: Option<WidgetRef>, pub trailing_icon: Option<WidgetRef>, pub close_on_activate: bool, pub overflow_axis: Axis, pub child: Option<WidgetRef>,
}
Expand description

A button for use in a MenuBar, in a menu created with MenuAnchor, or on its own, that can be activated by click or keyboard navigation.

This widget represents a leaf entry in a menu hierarchy that is typically part of a MenuBar, but may be used independently, or as part of a menu created with a MenuAnchor.

Menus using MenuItemButton can have a SingleActivator or CharacterActivator assigned to them as their shortcut, which will display an appropriate shortcut hint. Even though the shortcut labels are displayed in the menu, shortcuts are not automatically handled. They must be available in whatever context they are appropriate, and handled via another mechanism.

See also:

  • MenuBar, a class that creates a top level menu bar in a Material Design style.
  • MenuAnchor, a widget that creates a region with a submenu and shows it when requested.
  • SubmenuButton, a menu item similar to this one which manages a submenu.
  • PlatformMenuBar, which creates a menu bar that is rendered by the host platform instead of by Flutter (on macOS, for example).
  • ShortcutRegistry, a registry of shortcuts that apply for the entire application.
  • VoidCallbackIntent, to define intents that will call a VoidCallback and work with the Actions and Shortcuts system.
  • CallbackShortcuts to define shortcuts that call a callback without involving Actions.

Fields§

§key: Option<KeyRef>

See Widget::key.

§on_pressed: Option<Listener>

Called when the button is tapped or otherwise activated.

If this callback is null, then the button will be disabled.

See also:

  • enabled, which is true if the button is enabled.
§on_hover: Option<ValueChanged<bool>>

Called when a pointer enters or exits the button response area.

The value passed to the callback is true if a pointer has entered button area and false if a pointer has exited.

§request_focus_on_hover: bool

Determine if hovering can request focus.

Defaults to true.

§on_focus_change: Option<ValueChanged<bool>>

Handler called when the focus changes.

Called with true if this widget’s node gains focus, and false if it loses focus.

§focus_node: Option<FocusNodeRef>

An optional focus node to use as the focus node for this widget.

§autofocus: bool

True if this widget will be selected as the initial focus when no other node in its scope is currently focused.

§shortcut: Option<MenuSerializableShortcutRef>

The optional shortcut that selects this MenuItemButton.

Even though the shortcut label is displayed in the menu, the shortcut is not automatically handled; see MenuBar.

§semantics_label: Option<String>

An optional Semantics label, applied to the entire MenuItemButton.

A screen reader will default to reading the derived text on the MenuItemButton itself, which is not guaranteed to be readable. (For some shortcuts, such as comma, semicolon, and other punctuation, screen readers read silence).

Setting this label overwrites the semantics properties of the entire Widget, including its children. Consider wrapping this widget in Semantics if you want to customize other properties besides just the label.

Null by default.

§style: Option<ButtonStyle>

Customizes this button’s appearance.

Non-null properties of this style override the corresponding properties in theme_style_of and default_style_of. WidgetStatePropertys that resolve to non-null values will similarly override the corresponding WidgetStatePropertys in theme_style_of and default_style_of.

Null by default.

§states_controller: Option<Ref<WidgetStatesController>>

Represents the interactive “state” of this widget in terms of a set of WidgetStates, including WidgetState::Pressed, WidgetState::Hovered, WidgetState::Focused.

§clip_behavior: Clip

The content will be clipped (or not) according to this option.

Defaults to Clip::None.

§leading_icon: Option<WidgetRef>

An optional icon to display before the child label.

§trailing_icon: Option<WidgetRef>

An optional icon to display after the child label.

§close_on_activate: bool

Determines if the menu will be closed when a MenuItemButton is pressed.

Defaults to true.

§overflow_axis: Axis

The direction in which the menu item expands.

If the menu item button is a descendant of MenuAnchor or MenuBar, then this property is ignored.

If overflow_axis is Axis::Vertical, the menu will be expanded vertically. If overflow_axis is Axis::Horizontal, then the menu will be expanded horizontally.

Defaults to Axis::Horizontal.

§child: Option<WidgetRef>

The widget displayed in the center of this button.

Typically this is the button’s label, using a Text widget.

Implementations§

Source§

impl MenuItemButton

Source

pub fn new() -> MenuItemButton

Creates a const MenuItemButton.

Source

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

Dart MenuItemButton(key:).

Source

pub fn on_pressed(self, on_pressed: Listener) -> MenuItemButton

Dart MenuItemButton(onPressed:).

Source

pub fn on_hover(self, on_hover: ValueChanged<bool>) -> MenuItemButton

Dart MenuItemButton(onHover:).

Source

pub fn request_focus_on_hover( self, request_focus_on_hover: bool, ) -> MenuItemButton

Dart MenuItemButton(requestFocusOnHover:).

Source

pub fn on_focus_change( self, on_focus_change: ValueChanged<bool>, ) -> MenuItemButton

Dart MenuItemButton(onFocusChange:).

Source

pub fn focus_node(self, focus_node: FocusNodeRef) -> MenuItemButton

Dart MenuItemButton(focusNode:).

Source

pub fn autofocus(self, autofocus: bool) -> MenuItemButton

Dart MenuItemButton(autofocus:).

Source

pub fn shortcut(self, shortcut: MenuSerializableShortcutRef) -> MenuItemButton

Dart MenuItemButton(shortcut:).

Source

pub fn semantics_label( self, semantics_label: impl Into<String>, ) -> MenuItemButton

Dart MenuItemButton(semanticsLabel:).

Source

pub fn style(self, style: ButtonStyle) -> MenuItemButton

Dart MenuItemButton(style:).

Source

pub fn states_controller( self, states_controller: Ref<WidgetStatesController>, ) -> MenuItemButton

Dart MenuItemButton(statesController:).

Source

pub fn clip_behavior(self, clip_behavior: Clip) -> MenuItemButton

Dart MenuItemButton(clipBehavior:).

Source

pub fn leading_icon<K>(self, leading_icon: impl IntoWidget<K>) -> MenuItemButton

Dart MenuItemButton(leadingIcon:).

Source

pub fn trailing_icon<K>( self, trailing_icon: impl IntoWidget<K>, ) -> MenuItemButton

Dart MenuItemButton(trailingIcon:).

Source

pub fn close_on_activate(self, close_on_activate: bool) -> MenuItemButton

Dart MenuItemButton(closeOnActivate:).

Source

pub fn overflow_axis(self, overflow_axis: Axis) -> MenuItemButton

Dart MenuItemButton(overflowAxis:).

Source

pub fn child<K>(self, child: impl IntoWidget<K>) -> MenuItemButton

Dart MenuItemButton(child:).

Source

pub fn enabled(&self) -> bool

Whether the button is enabled or disabled.

To enable a button, set its on_pressed property to a non-null value.

Source

pub fn default_style_of( &self, app: &mut App, context: BuildContext, ) -> Box<dyn ButtonStyleGetters>

Defines the button’s default appearance.

The button child’s Text and Icon widgets are rendered with the ButtonStyle’s foreground color. The button’s InkWell adds the style’s overlay color when the button is focused, hovered or pressed. The button’s background color becomes its Material color and is transparent by default.

Source

pub fn theme_style_of( &self, app: &mut App, context: BuildContext, ) -> Option<ButtonStyle>

Returns the MenuButtonThemeData::style of the closest MenuButtonTheme ancestor.

Source

pub fn style_from() -> MenuButtonStyleFromBuilder

A static convenience method that constructs a MenuItemButton’s ButtonStyle given simple values.

The foreground_color color is used to create a WidgetStateProperty ButtonStyle::foreground_color value. Specify a value for foreground_color to specify the color of the button’s icons. Use background_color for the button’s background fill color. Use disabled_foreground_color and disabled_background_color to specify the button’s disabled icon and fill color.

Similarly, the enabled_mouse_cursor and disabled_mouse_cursor parameters are used to construct ButtonStyle::mouse_cursor.

The icon_color, disabled_icon_color are used to construct ButtonStyle::icon_color and icon_size is used to construct ButtonStyle::icon_size.

All of the other parameters are either used directly or used to create a WidgetStateProperty with a single value for all states.

All parameters default to null, by default this method returns a ButtonStyle that doesn’t override anything.

For example, to override the default foreground color for a MenuItemButton, as well as its overlay color, with all of the standard opacity adjustments for the pressed, focused, and hovered states, one could write:

MenuItemButton::new()
    .leading_icon(Icon::new(Some(Icons::pets())))
    .style(MenuItemButton::style_from().foreground_color(Colors::GREEN.primary()).build())
    .on_pressed(Listener::new(|_app| {
        // ...
    }))
    .child(Text::new("Button Label"))

Trait Implementations§

Source§

impl Debug for MenuItemButton

Source§

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

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

impl Default for MenuItemButton

Source§

fn default() -> MenuItemButton

Returns the “default value” for a type. Read more
Source§

impl StatefulWidget for MenuItemButton

Source§

type State = MenuItemButtonState

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

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 + 'static)>

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 MenuItemButton

§

impl !Send for MenuItemButton

§

impl !Sync for MenuItemButton

§

impl !UnwindSafe for MenuItemButton

§

impl Forget for MenuItemButton

§

impl Freeze for MenuItemButton
where *const RcInner<dyn Key> is !null: Freeze, PhantomData<RcInner<dyn Key>>: Freeze, *const RcInner<dyn Fn(&mut App)> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App)>>: Freeze, NonZero<u32>: Freeze, *const (): Freeze, *const RcInner<dyn Fn(&mut App, bool)> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App, bool)>>: Freeze, &'static FocusNodeVTable: Freeze, *const RcInner<Keep> is !null: Freeze, PhantomData<RcInner<Keep>>: Freeze, *const RcInner<dyn MenuSerializableShortcut> is !null: Freeze, PhantomData<RcInner<dyn MenuSerializableShortcut>>: Freeze, *const u8 is !null: Freeze, PhantomData<u8>: Freeze, *const RcInner<dyn WidgetStateProperty<Option<TextStyle>>> is !null: Freeze, PhantomData<RcInner<dyn WidgetStateProperty<Option<TextStyle>>>>: Freeze, *const RcInner<dyn WidgetStateProperty<Option<Color>>> is !null: Freeze, PhantomData<RcInner<dyn WidgetStateProperty<Option<Color>>>>: Freeze, *const RcInner<dyn WidgetStateProperty<Option<f64>>> is !null: Freeze, PhantomData<RcInner<dyn WidgetStateProperty<Option<f64>>>>: Freeze, *const RcInner<dyn WidgetStateProperty<Option<EdgeInsetsGeometry>>> is !null: Freeze, PhantomData<RcInner<dyn WidgetStateProperty<Option<EdgeInsetsGeometry>>>>: Freeze, *const RcInner<dyn WidgetStateProperty<Option<Size>>> is !null: Freeze, PhantomData<RcInner<dyn WidgetStateProperty<Option<Size>>>>: Freeze, *const RcInner<dyn WidgetStateProperty<Option<BorderSide>>> is !null: Freeze, PhantomData<RcInner<dyn WidgetStateProperty<Option<BorderSide>>>>: Freeze, *const RcInner<dyn WidgetStateProperty<Option<OutlinedBorderRef>>> is !null: Freeze, PhantomData<RcInner<dyn WidgetStateProperty<Option<OutlinedBorderRef>>>>: Freeze, *const RcInner<dyn WidgetStateProperty<Option<Rc<dyn MouseCursor>>>> is !null: Freeze, PhantomData<RcInner<dyn WidgetStateProperty<Option<Rc<dyn MouseCursor>>>>>: Freeze, *const RcInner<dyn InteractiveInkFeatureFactory> is !null: Freeze, PhantomData<RcInner<dyn InteractiveInkFeatureFactory>>: Freeze, *const RcInner<dyn Fn(&mut App, AnyElement, &HashSet<WidgetState>, Option<Rc<dyn Widget>>) -> Rc<dyn Widget>> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App, AnyElement, &HashSet<WidgetState>, Option<Rc<dyn Widget>>) -> Rc<dyn Widget>>>: Freeze, PhantomData<fn() -> WidgetStatesController>: Freeze, *const RcInner<dyn Widget> is !null: Freeze, PhantomData<RcInner<dyn Widget>>: Freeze,

§

impl Move for MenuItemButton

§

impl Unpin for MenuItemButton

§

impl UnsafeUnpin for MenuItemButton
where *const RcInner<dyn Key> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Key>>: UnsafeUnpin, *const RcInner<dyn Fn(&mut App)> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&mut App)>>: UnsafeUnpin, NonZeroU32Inner: UnsafeUnpin, *const (): UnsafeUnpin, *const RcInner<dyn Fn(&mut App, bool)> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&mut App, bool)>>: UnsafeUnpin, &'static FocusNodeVTable: UnsafeUnpin, *const RcInner<Keep> is !null: UnsafeUnpin, PhantomData<RcInner<Keep>>: UnsafeUnpin, *const RcInner<dyn MenuSerializableShortcut> is !null: UnsafeUnpin, PhantomData<RcInner<dyn MenuSerializableShortcut>>: UnsafeUnpin, *const u8 is !null: UnsafeUnpin, PhantomData<u8>: UnsafeUnpin, *const RcInner<dyn WidgetStateProperty<Option<TextStyle>>> is !null: UnsafeUnpin, PhantomData<RcInner<dyn WidgetStateProperty<Option<TextStyle>>>>: UnsafeUnpin, *const RcInner<dyn WidgetStateProperty<Option<Color>>> is !null: UnsafeUnpin, PhantomData<RcInner<dyn WidgetStateProperty<Option<Color>>>>: UnsafeUnpin, *const RcInner<dyn WidgetStateProperty<Option<f64>>> is !null: UnsafeUnpin, PhantomData<RcInner<dyn WidgetStateProperty<Option<f64>>>>: UnsafeUnpin, *const RcInner<dyn WidgetStateProperty<Option<EdgeInsetsGeometry>>> is !null: UnsafeUnpin, PhantomData<RcInner<dyn WidgetStateProperty<Option<EdgeInsetsGeometry>>>>: UnsafeUnpin, *const RcInner<dyn WidgetStateProperty<Option<Size>>> is !null: UnsafeUnpin, PhantomData<RcInner<dyn WidgetStateProperty<Option<Size>>>>: UnsafeUnpin, *const RcInner<dyn WidgetStateProperty<Option<BorderSide>>> is !null: UnsafeUnpin, PhantomData<RcInner<dyn WidgetStateProperty<Option<BorderSide>>>>: UnsafeUnpin, *const RcInner<dyn WidgetStateProperty<Option<OutlinedBorderRef>>> is !null: UnsafeUnpin, PhantomData<RcInner<dyn WidgetStateProperty<Option<OutlinedBorderRef>>>>: UnsafeUnpin, *const RcInner<dyn WidgetStateProperty<Option<Rc<dyn MouseCursor>>>> is !null: UnsafeUnpin, PhantomData<RcInner<dyn WidgetStateProperty<Option<Rc<dyn MouseCursor>>>>>: UnsafeUnpin, *const RcInner<dyn InteractiveInkFeatureFactory> is !null: UnsafeUnpin, PhantomData<RcInner<dyn InteractiveInkFeatureFactory>>: UnsafeUnpin, *const RcInner<dyn Fn(&mut App, AnyElement, &HashSet<WidgetState>, Option<Rc<dyn Widget>>) -> Rc<dyn Widget>> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&mut App, AnyElement, &HashSet<WidgetState>, Option<Rc<dyn Widget>>) -> Rc<dyn Widget>>>: UnsafeUnpin, PhantomData<fn() -> WidgetStatesController>: 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>