Skip to main content

SubmenuButton

Struct SubmenuButton 

Source
pub struct SubmenuButton {
Show 21 fields pub key: Option<KeyRef>, pub on_hover: Option<ValueChanged<bool>>, pub on_focus_change: Option<ValueChanged<bool>>, pub on_open: Option<VoidCallback>, pub on_close: Option<VoidCallback>, pub controller: Option<MenuControllerRef>, pub style: Option<ButtonStyle>, pub menu_style: Option<MenuStyle>, pub alignment_offset: Option<Offset>, pub clip_behavior: Clip, pub focus_node: Option<FocusNodeRef>, pub states_controller: Option<Ref<WidgetStatesController>>, pub leading_icon: Option<WidgetRef>, pub submenu_icon: Option<WidgetStatePropertyRef<Option<WidgetRef>>>, pub trailing_icon: Option<WidgetRef>, pub use_root_overlay: bool, pub on_animation_status_changed: Option<ValueChanged<AnimationStatus>>, pub menu_children: Vec<WidgetRef>, pub hover_open_delay: Duration, pub animated: bool, pub child: Option<WidgetRef>,
}
Expand description

A menu button that displays a cascading menu.

It can be used as part of a MenuBar, or as a standalone widget.

This widget represents a menu item that has a submenu. Like the leaf MenuItemButton, it shows a label with an optional leading or trailing icon, but additionally shows an arrow icon showing that it has a submenu.

By default the submenu will appear to the side of the controlling button. The alignment and offset of the submenu can be controlled by setting MenuStyle::alignment on the style and the alignment_offset argument, respectively.

When activated (by being clicked, through keyboard navigation, or via hovering with a mouse), it will open a submenu containing the menu_children.

If menu_children is empty, then this menu item will appear disabled.

See also:

  • MenuItemButton, a widget that represents a leaf menu item that does not host a submenu.
  • MenuBar, a widget that renders menu items in a row in a Material Design style.
  • MenuAnchor, a widget that creates a region with a submenu and shows it when requested.
  • PlatformMenuBar, a widget that renders similar menu bar items from a PlatformMenuItem using platform-native APIs instead of Flutter.

Fields§

§key: Option<KeyRef>

See Widget::key.

§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 this part of the button and false if a pointer has exited.

§on_focus_change: Option<ValueChanged<bool>>

Handler called when the focus changes.

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

§on_open: Option<VoidCallback>

A callback that is invoked when the menu is opened.

§on_close: Option<VoidCallback>

A callback that is invoked when the menu is closed.

§controller: Option<MenuControllerRef>

An optional MenuController for this submenu.

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

§menu_style: Option<MenuStyle>

The MenuStyle of the menu specified by menu_children.

Defaults to the value of MenuThemeData::style of the ambient MenuTheme.

§alignment_offset: Option<Offset>

The offset of the menu relative to the alignment origin determined by MenuStyle::alignment on the style attribute.

Use this for fine adjustments of the menu placement.

Defaults to an offset that takes into account the padding of the menu so that the top starting corner of the first menu item is aligned with the top of the MenuAnchor region.

§clip_behavior: Clip

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

Defaults to Clip::HardEdge.

§focus_node: Option<FocusNodeRef>

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

§states_controller: Option<Ref<WidgetStatesController>>

Represents the interactive “state” of this widget in terms of a set of WidgetStates.

§leading_icon: Option<WidgetRef>

An optional icon to display before the child.

§submenu_icon: Option<WidgetStatePropertyRef<Option<WidgetRef>>>

If provided, the widget replaces the default SubmenuButton arrow icon.

Resolves in the following states:

  • WidgetState::Disabled.
  • WidgetState::Hovered.
  • WidgetState::Focused.

If this is null, then the value of MenuThemeData::submenu_icon is used. If that is also null, then defaults to a right arrow icon with the size of 24 pixels.

§trailing_icon: Option<WidgetRef>

An optional icon to display after the child.

§use_root_overlay: bool

Whether the menu panel should be rendered in the root Overlay.

See RawMenuAnchor::use_root_overlay.

Defaults to false.

§on_animation_status_changed: Option<ValueChanged<AnimationStatus>>

An optional callback that is invoked when the AnimationStatus of the menu changes during open and close animations.

If animated is false, this callback will only be invoked with AnimationStatus::Completed when the menu is opened, and AnimationStatus::Dismissed when the menu is closed.

Because the [MenuControllerLeaf::is_open] property is true while the menu is opening, opened, and closing, it cannot be used to determine whether the menu is in the process of closing or opening. As such, this callback provides a way to determine when the menu is opening or closing.

Defaults to null.

§menu_children: Vec<WidgetRef>

The list of widgets that appear in the menu when it is opened.

These can be any widget, but are typically either MenuItemButton or SubmenuButton widgets.

If menu_children is empty, then the button for this menu item will be disabled.

§hover_open_delay: Duration

The duration to wait before opening the menu when the button is hovered.

Because MenuBar children can only be opened by hover if a sibling SubmenuButton is already open, providing a hover_open_delay to direct children of a MenuBar will panic in a debug build. This is to avoid the case where the hover_open_delay for a SubmenuButton is longer than the duration of a sibling’s closing animation, which leads to that menu never opening.

Defaults to Duration::ZERO.

§animated: bool

Whether the menu should open and close with an animation.

Defaults to false.

§child: Option<WidgetRef>

The widget displayed in the middle portion of this button.

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

Implementations§

Source§

impl SubmenuButton

Source

pub fn new<K>( menu_children: Vec<WidgetRef>, child: Option<impl IntoWidget<K>>, ) -> SubmenuButton

Creates a const SubmenuButton.

The child and menu_children attributes are required.

Source

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

Dart SubmenuButton(key:).

Source

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

Dart SubmenuButton(onHover:).

Source

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

Dart SubmenuButton(onFocusChange:).

Source

pub fn on_open(self, on_open: VoidCallback) -> SubmenuButton

Dart SubmenuButton(onOpen:).

Source

pub fn on_close(self, on_close: VoidCallback) -> SubmenuButton

Dart SubmenuButton(onClose:).

Source

pub fn controller(self, controller: MenuControllerRef) -> SubmenuButton

Dart SubmenuButton(controller:).

Source

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

Dart SubmenuButton(style:).

Source

pub fn menu_style(self, menu_style: MenuStyle) -> SubmenuButton

Dart SubmenuButton(menuStyle:).

Source

pub fn alignment_offset(self, alignment_offset: Offset) -> SubmenuButton

Dart SubmenuButton(alignmentOffset:).

Source

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

Dart SubmenuButton(clipBehavior:).

Source

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

Dart SubmenuButton(focusNode:).

Source

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

Dart SubmenuButton(statesController:).

Source

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

Dart SubmenuButton(leadingIcon:).

Source

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

Dart SubmenuButton(trailingIcon:).

Source

pub fn submenu_icon( self, submenu_icon: WidgetStatePropertyRef<Option<WidgetRef>>, ) -> SubmenuButton

Dart SubmenuButton(submenuIcon:).

Source

pub fn use_root_overlay(self, use_root_overlay: bool) -> SubmenuButton

Dart SubmenuButton(useRootOverlay:).

Source

pub fn hover_open_delay(self, hover_open_delay: Duration) -> SubmenuButton

Dart SubmenuButton(hoverOpenDelay:).

Source

pub fn animated(self, animated: bool) -> SubmenuButton

Dart SubmenuButton(animated:).

Source

pub fn on_animation_status_changed( self, on_animation_status_changed: ValueChanged<AnimationStatus>, ) -> SubmenuButton

Dart SubmenuButton(onAnimationStatusChanged:).

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 SubmenuButton’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 SubmenuButton, as well as its overlay color, with all of the standard opacity adjustments for the pressed, focused, and hovered states, one could write:

SubmenuButton::new(menu_children, Some(Text::new("Button Label")))
    .leading_icon(Icon::new(Some(Icons::pets())))
    .style(SubmenuButton::style_from().foreground_color(Colors::GREEN.primary()).build())

Trait Implementations§

Source§

impl Debug for SubmenuButton

Source§

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

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

impl StatefulWidget for SubmenuButton

Source§

type State = SubmenuButtonState

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

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 SubmenuButton

§

impl !Send for SubmenuButton

§

impl !Sync for SubmenuButton

§

impl !UnwindSafe for SubmenuButton

§

impl Forget for SubmenuButton

§

impl Freeze for SubmenuButton
where *const RcInner<dyn Key> is !null: Freeze, PhantomData<RcInner<dyn Key>>: Freeze, *const RcInner<dyn Fn(&mut App, bool)> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App, bool)>>: Freeze, *const RcInner<dyn Fn(&mut App)> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App)>>: Freeze, NonZero<u32>: Freeze, &'static MenuControllerVTable: Freeze, *const RcInner<Keep> is !null: Freeze, PhantomData<RcInner<Keep>>: 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, *const (): Freeze, &'static FocusNodeVTable: Freeze, PhantomData<fn() -> WidgetStatesController>: Freeze, *const RcInner<dyn Widget> is !null: Freeze, PhantomData<RcInner<dyn Widget>>: Freeze, *const RcInner<dyn WidgetStateProperty<Option<Rc<dyn Widget>>>> is !null: Freeze, PhantomData<RcInner<dyn WidgetStateProperty<Option<Rc<dyn Widget>>>>>: Freeze, *const RcInner<dyn Fn(&mut App, AnimationStatus)> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App, AnimationStatus)>>: Freeze, *const u8 is !null: Freeze, PhantomData<Rc<dyn Widget>>: Freeze,

§

impl Move for SubmenuButton

§

impl Unpin for SubmenuButton

§

impl UnsafeUnpin for SubmenuButton
where *const RcInner<dyn Key> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Key>>: UnsafeUnpin, *const RcInner<dyn Fn(&mut App, bool)> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&mut App, bool)>>: UnsafeUnpin, *const RcInner<dyn Fn(&mut App)> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&mut App)>>: UnsafeUnpin, NonZeroU32Inner: UnsafeUnpin, &'static MenuControllerVTable: UnsafeUnpin, *const RcInner<Keep> is !null: UnsafeUnpin, PhantomData<RcInner<Keep>>: 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, *const (): UnsafeUnpin, &'static FocusNodeVTable: UnsafeUnpin, PhantomData<fn() -> WidgetStatesController>: UnsafeUnpin, *const RcInner<dyn Widget> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Widget>>: UnsafeUnpin, *const RcInner<dyn WidgetStateProperty<Option<Rc<dyn Widget>>>> is !null: UnsafeUnpin, PhantomData<RcInner<dyn WidgetStateProperty<Option<Rc<dyn Widget>>>>>: UnsafeUnpin, *const RcInner<dyn Fn(&mut App, AnimationStatus)> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&mut App, AnimationStatus)>>: UnsafeUnpin, *const u8 is !null: UnsafeUnpin, PhantomData<Rc<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>