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 forSubmenuButtons andMenuItemButtons.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 thevisual_densityfor all widgets within aTheme.
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
impl MenuStyle
Sourcepub fn background_color(
self,
background_color: WidgetStatePropertyRef<Option<Color>>,
) -> MenuStyle
pub fn background_color( self, background_color: WidgetStatePropertyRef<Option<Color>>, ) -> MenuStyle
Dart MenuStyle(backgroundColor:).
Sourcepub fn shadow_color(
self,
shadow_color: WidgetStatePropertyRef<Option<Color>>,
) -> MenuStyle
pub fn shadow_color( self, shadow_color: WidgetStatePropertyRef<Option<Color>>, ) -> MenuStyle
Dart MenuStyle(shadowColor:).
Sourcepub fn surface_tint_color(
self,
surface_tint_color: WidgetStatePropertyRef<Option<Color>>,
) -> MenuStyle
pub fn surface_tint_color( self, surface_tint_color: WidgetStatePropertyRef<Option<Color>>, ) -> MenuStyle
Dart MenuStyle(surfaceTintColor:).
Sourcepub fn elevation(
self,
elevation: WidgetStatePropertyRef<Option<f64>>,
) -> MenuStyle
pub fn elevation( self, elevation: WidgetStatePropertyRef<Option<f64>>, ) -> MenuStyle
Dart MenuStyle(elevation:).
Sourcepub fn padding(
self,
padding: WidgetStatePropertyRef<Option<EdgeInsetsGeometry>>,
) -> MenuStyle
pub fn padding( self, padding: WidgetStatePropertyRef<Option<EdgeInsetsGeometry>>, ) -> MenuStyle
Dart MenuStyle(padding:).
Sourcepub fn minimum_size(
self,
minimum_size: WidgetStatePropertyRef<Option<Size>>,
) -> MenuStyle
pub fn minimum_size( self, minimum_size: WidgetStatePropertyRef<Option<Size>>, ) -> MenuStyle
Dart MenuStyle(minimumSize:).
Sourcepub fn fixed_size(
self,
fixed_size: WidgetStatePropertyRef<Option<Size>>,
) -> MenuStyle
pub fn fixed_size( self, fixed_size: WidgetStatePropertyRef<Option<Size>>, ) -> MenuStyle
Dart MenuStyle(fixedSize:).
Sourcepub fn maximum_size(
self,
maximum_size: WidgetStatePropertyRef<Option<Size>>,
) -> MenuStyle
pub fn maximum_size( self, maximum_size: WidgetStatePropertyRef<Option<Size>>, ) -> MenuStyle
Dart MenuStyle(maximumSize:).
Sourcepub fn side(self, side: WidgetStatePropertyRef<Option<BorderSide>>) -> MenuStyle
pub fn side(self, side: WidgetStatePropertyRef<Option<BorderSide>>) -> MenuStyle
Dart MenuStyle(side:).
Sourcepub fn shape(
self,
shape: WidgetStatePropertyRef<Option<OutlinedBorderRef>>,
) -> MenuStyle
pub fn shape( self, shape: WidgetStatePropertyRef<Option<OutlinedBorderRef>>, ) -> MenuStyle
Dart MenuStyle(shape:).
Sourcepub fn mouse_cursor(
self,
mouse_cursor: WidgetStatePropertyRef<Option<MouseCursorRef>>,
) -> MenuStyle
pub fn mouse_cursor( self, mouse_cursor: WidgetStatePropertyRef<Option<MouseCursorRef>>, ) -> MenuStyle
Dart MenuStyle(mouseCursor:).
Sourcepub fn visual_density(self, visual_density: VisualDensity) -> MenuStyle
pub fn visual_density(self, visual_density: VisualDensity) -> MenuStyle
Dart MenuStyle(visualDensity:).
Sourcepub fn alignment(self, alignment: AlignmentGeometry) -> MenuStyle
pub fn alignment(self, alignment: AlignmentGeometry) -> MenuStyle
Dart MenuStyle(alignment:).
Sourcepub fn copy_with(&self) -> MenuStyle
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).
Trait Implementations§
Source§impl Diagnosticable for MenuStyle
impl Diagnosticable for MenuStyle
Source§fn debug_fill_properties(&self, properties: &mut DiagnosticPropertiesBuilder)
fn debug_fill_properties(&self, properties: &mut DiagnosticPropertiesBuilder)
Source§fn type_name(&self) -> &'static str
fn type_name(&self) -> &'static str
Object.runtimeType as diagnostics print it: the last segment of
the Rust type path, without generic arguments.Source§fn identity_hash(&self) -> u64
fn identity_hash(&self) -> u64
Object.hashCode as diagnostics print it: the object’s address.Source§fn to_string_short(&self) -> String
fn to_string_short(&self) -> String
Source§fn to_diagnostics_node(&self) -> DiagnosticableNode
fn to_diagnostics_node(&self) -> DiagnosticableNode
DiagnosticsNode::to_string_deep.Source§fn to_diagnostics_node_with(
&self,
name: Option<String>,
style: Option<DiagnosticsTreeStyle>,
) -> DiagnosticableNode
fn to_diagnostics_node_with( &self, name: Option<String>, style: Option<DiagnosticsTreeStyle>, ) -> DiagnosticableNode
toDiagnosticsNode(name:, style:).Source§fn to_string(&self) -> String
fn to_string(&self) -> String
toString: a single-line description with properties and no
children. Read moreSource§fn to_string_at(&self, min_level: DiagnosticLevel) -> String
fn to_string_at(&self, min_level: DiagnosticLevel) -> String
toString(minLevel:).Source§impl MenuStyleGetters for MenuStyle
impl MenuStyleGetters for MenuStyle
super(...)
arguments a defaults struct keeps.Source§fn background_color(
&self,
app: &mut App,
) -> Option<WidgetStatePropertyRef<Option<Color>>>
fn background_color( &self, app: &mut App, ) -> Option<WidgetStatePropertyRef<Option<Color>>>
background_color getter.Source§fn shadow_color(
&self,
app: &mut App,
) -> Option<WidgetStatePropertyRef<Option<Color>>>
fn shadow_color( &self, app: &mut App, ) -> Option<WidgetStatePropertyRef<Option<Color>>>
shadow_color getter.Source§fn surface_tint_color(
&self,
app: &mut App,
) -> Option<WidgetStatePropertyRef<Option<Color>>>
fn surface_tint_color( &self, app: &mut App, ) -> Option<WidgetStatePropertyRef<Option<Color>>>
surface_tint_color getter.Source§fn elevation(
&self,
app: &mut App,
) -> Option<WidgetStatePropertyRef<Option<f64>>>
fn elevation( &self, app: &mut App, ) -> Option<WidgetStatePropertyRef<Option<f64>>>
elevation getter.Source§fn padding(
&self,
app: &mut App,
) -> Option<WidgetStatePropertyRef<Option<EdgeInsetsGeometry>>>
fn padding( &self, app: &mut App, ) -> Option<WidgetStatePropertyRef<Option<EdgeInsetsGeometry>>>
padding getter.Source§fn minimum_size(
&self,
app: &mut App,
) -> Option<WidgetStatePropertyRef<Option<Size>>>
fn minimum_size( &self, app: &mut App, ) -> Option<WidgetStatePropertyRef<Option<Size>>>
minimum_size getter.Source§fn fixed_size(
&self,
app: &mut App,
) -> Option<WidgetStatePropertyRef<Option<Size>>>
fn fixed_size( &self, app: &mut App, ) -> Option<WidgetStatePropertyRef<Option<Size>>>
fixed_size getter.Source§fn maximum_size(
&self,
app: &mut App,
) -> Option<WidgetStatePropertyRef<Option<Size>>>
fn maximum_size( &self, app: &mut App, ) -> Option<WidgetStatePropertyRef<Option<Size>>>
maximum_size getter.Source§fn side(
&self,
app: &mut App,
) -> Option<WidgetStatePropertyRef<Option<BorderSide>>>
fn side( &self, app: &mut App, ) -> Option<WidgetStatePropertyRef<Option<BorderSide>>>
side getter.Source§fn shape(
&self,
app: &mut App,
) -> Option<WidgetStatePropertyRef<Option<OutlinedBorderRef>>>
fn shape( &self, app: &mut App, ) -> Option<WidgetStatePropertyRef<Option<OutlinedBorderRef>>>
shape getter.Source§fn mouse_cursor(
&self,
app: &mut App,
) -> Option<WidgetStatePropertyRef<Option<MouseCursorRef>>>
fn mouse_cursor( &self, app: &mut App, ) -> Option<WidgetStatePropertyRef<Option<MouseCursorRef>>>
mouse_cursor getter.Source§fn visual_density(&self, app: &mut App) -> Option<VisualDensity>
fn visual_density(&self, app: &mut App) -> Option<VisualDensity>
visual_density getter.