Skip to main content

MenuStyle

Struct MenuStyle 

Source
pub struct MenuStyle {
Show 13 fields pub background_color: Option<WidgetStatePropertyRef<Option<Color>>>, pub shadow_color: Option<WidgetStatePropertyRef<Option<Color>>>, pub surface_tint_color: Option<WidgetStatePropertyRef<Option<Color>>>, pub elevation: Option<WidgetStatePropertyRef<Option<f64>>>, pub padding: Option<WidgetStatePropertyRef<Option<EdgeInsetsGeometry>>>, pub minimum_size: Option<WidgetStatePropertyRef<Option<Size>>>, pub fixed_size: Option<WidgetStatePropertyRef<Option<Size>>>, pub maximum_size: Option<WidgetStatePropertyRef<Option<Size>>>, pub side: Option<WidgetStatePropertyRef<Option<BorderSide>>>, pub shape: Option<WidgetStatePropertyRef<Option<OutlinedBorderRef>>>, pub mouse_cursor: Option<WidgetStatePropertyRef<Option<MouseCursorRef>>>, pub visual_density: Option<VisualDensity>, pub alignment: Option<AlignmentGeometry>,
}
Expand description

The visual properties that menus have in common.

Menus created by MenuBar and MenuAnchor and their themes have a MenuStyle property which defines the visual properties whose default values are to be overridden. The default values are defined by the individual menu widgets and are typically based on overall theme’s ThemeData::color_scheme and ThemeData::text_theme.

All of the MenuStyle properties are null by default.

Many of the MenuStyle properties are WidgetStateProperty objects which resolve to different values depending on the menu’s state. For example the Color properties are defined with WidgetStateProperty<Option<Color>> and can resolve to different colors depending on if the menu is pressed, hovered, focused, disabled, etc.

These properties can override the default value for just one state or all of them. For example to create a SubmenuButton whose background color is the color scheme’s primary color with 50% opacity, but only when the menu is pressed, one could write:

SubmenuButton::new(menu_children, Text::new("Fly me to the moon")).menu_style(
    MenuStyle::new().background_color(
        <dyn WidgetStateProperty<Option<Color>>>::resolve_with(move |states| {
            if states.contains(&WidgetState::Focused) {
                return Some(primary.with_values(Some(0.5), None, None, None, None));
            }
            None // Use the component's default.
        }),
    ),
)

In this case the background color for all other menu states would fall back to the SubmenuButton’s default values. To unconditionally set the menu’s background_color for all states one could write:

SubmenuButton::new(menu_children, Text::new("Let me play among the stars")).menu_style(
    MenuStyle::new().background_color(Rc::new(WidgetStatePropertyAll::new(Some(
        Colors::GREEN.primary(),
    )))),
)

To configure all of the application’s menus in the same way, specify the overall theme’s menu_theme:

MaterialApp::new().theme(ThemeData::new().menu_theme(MenuThemeData::new().style(
    MenuStyle::new().background_color(Rc::new(WidgetStatePropertyAll::new(Some(
        Colors::RED.primary(),
    )))),
)))

See also:

  • MenuAnchor, a widget which hosts cascading menus.
  • MenuBar, a widget which defines a menu bar of buttons hosting cascading menus.
  • MenuButtonTheme, the theme for SubmenuButtons and MenuItemButtons.
  • ButtonStyle, a similar configuration object for button styles.

Fields§

§background_color: Option<WidgetStatePropertyRef<Option<Color>>>

The menu’s background fill color.

§shadow_color: Option<WidgetStatePropertyRef<Option<Color>>>

The shadow color of the menu’s Material.

The material’s elevation shadow can be difficult to see for dark themes, so by default the menu classes add a semi-transparent overlay to indicate elevation. See ThemeData::apply_elevation_overlay_color.

§surface_tint_color: Option<WidgetStatePropertyRef<Option<Color>>>

The surface tint color of the menu’s Material.

See Material::surface_tint_color for more details.

§elevation: Option<WidgetStatePropertyRef<Option<f64>>>

The elevation of the menu’s Material.

§padding: Option<WidgetStatePropertyRef<Option<EdgeInsetsGeometry>>>

The padding between the menu’s boundary and its child.

§minimum_size: Option<WidgetStatePropertyRef<Option<Size>>>

The minimum size of the menu itself.

This value must be less than or equal to maximum_size.

§fixed_size: Option<WidgetStatePropertyRef<Option<Size>>>

The menu’s size.

This size is still constrained by the style’s minimum_size and maximum_size. Fixed size dimensions whose value is f64::INFINITY are ignored.

To specify menus with a fixed width and the default height use fixed_size(Size::from_width(320.0)). Similarly, to specify a fixed height and the default width use fixed_size(Size::from_height(100.0)).

§maximum_size: Option<WidgetStatePropertyRef<Option<Size>>>

The maximum size of the menu itself.

A Size::INFINITE or null value for this property means that the menu’s maximum size is not constrained.

This value must be greater than or equal to minimum_size.

§side: Option<WidgetStatePropertyRef<Option<BorderSide>>>

The color and weight of the menu’s outline.

This value is combined with shape to create a shape decorated with an outline.

§shape: Option<WidgetStatePropertyRef<Option<OutlinedBorderRef>>>

The shape of the menu’s underlying Material.

This shape is combined with side to create a shape decorated with an outline.

§mouse_cursor: Option<WidgetStatePropertyRef<Option<MouseCursorRef>>>

The cursor for a mouse pointer when it enters or is hovering over this menu’s InkWell.

§visual_density: Option<VisualDensity>

Defines how compact the menu’s layout will be.

See also:

  • ThemeData::visual_density, which specifies the visual_density for all widgets within a Theme.
§alignment: Option<AlignmentGeometry>

Determines the desired alignment of the submenu when opened relative to the button that opens it.

If there isn’t sufficient space to open the menu with the given alignment, and there’s space on the other side of the button, then the alignment is swapped to it’s opposite (1 becomes -1, etc.), and the menu will try to appear on the other side of the button. If there isn’t enough space there either, then the menu will be pushed as far over as necessary to display as much of itself as possible, possibly overlapping the parent button.

Implementations§

Source§

impl MenuStyle

Source

pub fn new() -> MenuStyle

Create a MenuStyle.

Source

pub fn background_color( self, background_color: WidgetStatePropertyRef<Option<Color>>, ) -> MenuStyle

Dart MenuStyle(backgroundColor:).

Source

pub fn shadow_color( self, shadow_color: WidgetStatePropertyRef<Option<Color>>, ) -> MenuStyle

Dart MenuStyle(shadowColor:).

Source

pub fn surface_tint_color( self, surface_tint_color: WidgetStatePropertyRef<Option<Color>>, ) -> MenuStyle

Dart MenuStyle(surfaceTintColor:).

Source

pub fn elevation( self, elevation: WidgetStatePropertyRef<Option<f64>>, ) -> MenuStyle

Dart MenuStyle(elevation:).

Source

pub fn padding( self, padding: WidgetStatePropertyRef<Option<EdgeInsetsGeometry>>, ) -> MenuStyle

Dart MenuStyle(padding:).

Source

pub fn minimum_size( self, minimum_size: WidgetStatePropertyRef<Option<Size>>, ) -> MenuStyle

Dart MenuStyle(minimumSize:).

Source

pub fn fixed_size( self, fixed_size: WidgetStatePropertyRef<Option<Size>>, ) -> MenuStyle

Dart MenuStyle(fixedSize:).

Source

pub fn maximum_size( self, maximum_size: WidgetStatePropertyRef<Option<Size>>, ) -> MenuStyle

Dart MenuStyle(maximumSize:).

Source

pub fn side(self, side: WidgetStatePropertyRef<Option<BorderSide>>) -> MenuStyle

Dart MenuStyle(side:).

Source

pub fn shape( self, shape: WidgetStatePropertyRef<Option<OutlinedBorderRef>>, ) -> MenuStyle

Dart MenuStyle(shape:).

Source

pub fn mouse_cursor( self, mouse_cursor: WidgetStatePropertyRef<Option<MouseCursorRef>>, ) -> MenuStyle

Dart MenuStyle(mouseCursor:).

Source

pub fn visual_density(self, visual_density: VisualDensity) -> MenuStyle

Dart MenuStyle(visualDensity:).

Source

pub fn alignment(self, alignment: AlignmentGeometry) -> MenuStyle

Dart MenuStyle(alignment:).

Source

pub fn copy_with(&self) -> MenuStyle

Returns a copy of this MenuStyle with the given fields replaced with the new values.

Chain setters: style.copy_with().elevation(e).

Source

pub fn merge(&self, style: Option<&MenuStyle>) -> MenuStyle

Returns a copy of this MenuStyle where the non-null fields in style have replaced the corresponding null fields in this MenuStyle.

In other words, style is used to fill in unspecified (null) fields this MenuStyle.

Source

pub fn lerp( a: Option<&MenuStyle>, b: Option<&MenuStyle>, t: f64, ) -> Option<MenuStyle>

Linearly interpolate between two MenuStyles.

Trait Implementations§

Source§

impl Clone for MenuStyle

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MenuStyle

Source§

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

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

impl Default for MenuStyle

Source§

fn default() -> Self

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

impl Diagnosticable for MenuStyle

Source§

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

Add additional properties associated with the node.
Source§

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

Dart’s Object.runtimeType as diagnostics print it: the last segment of the Rust type path, without generic arguments.
Source§

fn identity_hash(&self) -> u64

Dart’s Object.hashCode as diagnostics print it: the object’s address.
Source§

fn to_string_short(&self) -> String

A brief description of this object, usually just the type and the hash.
Source§

fn to_diagnostics_node(&self) -> DiagnosticableNode

Returns a debug representation of the object used by debugging tools and by DiagnosticsNode::to_string_deep.
Source§

fn to_diagnostics_node_with( &self, name: Option<String>, style: Option<DiagnosticsTreeStyle>, ) -> DiagnosticableNode

Dart toDiagnosticsNode(name:, style:).
Source§

fn to_string(&self) -> String

Dart’s toString: a single-line description with properties and no children. Read more
Source§

fn to_string_at(&self, min_level: DiagnosticLevel) -> String

Dart’s toString(minLevel:).
Source§

impl Display for MenuStyle

Dart’s MenuStyle.toString, through its diagnostics.

Source§

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

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

impl MenuStyleGetters for MenuStyle

Source§

fn menu_style(&self) -> &MenuStyle

The fields Dart’s constructor sets: the struct itself, or the super(...) arguments a defaults struct keeps.
Source§

fn background_color( &self, app: &mut App, ) -> Option<WidgetStatePropertyRef<Option<Color>>>

Dart’s background_color getter.
Source§

fn shadow_color( &self, app: &mut App, ) -> Option<WidgetStatePropertyRef<Option<Color>>>

Dart’s shadow_color getter.
Source§

fn surface_tint_color( &self, app: &mut App, ) -> Option<WidgetStatePropertyRef<Option<Color>>>

Dart’s surface_tint_color getter.
Source§

fn elevation( &self, app: &mut App, ) -> Option<WidgetStatePropertyRef<Option<f64>>>

Dart’s elevation getter.
Source§

fn padding( &self, app: &mut App, ) -> Option<WidgetStatePropertyRef<Option<EdgeInsetsGeometry>>>

Dart’s padding getter.
Source§

fn minimum_size( &self, app: &mut App, ) -> Option<WidgetStatePropertyRef<Option<Size>>>

Dart’s minimum_size getter.
Source§

fn fixed_size( &self, app: &mut App, ) -> Option<WidgetStatePropertyRef<Option<Size>>>

Dart’s fixed_size getter.
Source§

fn maximum_size( &self, app: &mut App, ) -> Option<WidgetStatePropertyRef<Option<Size>>>

Dart’s maximum_size getter.
Source§

fn side( &self, app: &mut App, ) -> Option<WidgetStatePropertyRef<Option<BorderSide>>>

Dart’s side getter.
Source§

fn shape( &self, app: &mut App, ) -> Option<WidgetStatePropertyRef<Option<OutlinedBorderRef>>>

Dart’s shape getter.
Source§

fn mouse_cursor( &self, app: &mut App, ) -> Option<WidgetStatePropertyRef<Option<MouseCursorRef>>>

Dart’s mouse_cursor getter.
Source§

fn visual_density(&self, app: &mut App) -> Option<VisualDensity>

Dart’s visual_density getter.
Source§

fn alignment(&self, app: &mut App) -> Option<AlignmentGeometry>

Dart’s alignment getter.
Source§

fn copy_with(&self, app: &mut App) -> MenuStyle

Dart’s copyWith() with no arguments: a plain value holding what every getter answers, for the caller’s setters to change.
Source§

impl PartialEq for MenuStyle

Source§

fn eq(&self, other: &MenuStyle) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for MenuStyle

§

impl !Send for MenuStyle

§

impl !Sync for MenuStyle

§

impl !UnwindSafe for MenuStyle

§

impl Forget for MenuStyle

§

impl Freeze for MenuStyle

§

impl Move for MenuStyle

§

impl Unpin for MenuStyle

§

impl UnsafeUnpin for MenuStyle

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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>