Skip to main content

ButtonStyleButton

Trait ButtonStyleButton 

Source
pub trait ButtonStyleButton: 'static {
    // Required methods
    fn button_style_button_data(&self) -> &ButtonStyleButtonData;
    fn default_style_of(
        &self,
        app: &mut App,
        context: BuildContext,
    ) -> Box<dyn ButtonStyleGetters>;
    fn theme_style_of(
        &self,
        app: &mut App,
        context: BuildContext,
    ) -> Option<ButtonStyle>;

    // Provided method
    fn enabled(&self) -> bool { ... }
}
Expand description

The base widget for buttons whose style is defined by a ButtonStyle object; Dart’s abstract ButtonStyleButton, whose state is ButtonStyleState.

Concrete subclasses must override default_style_of and theme_style_of. A subclass is its own widget type: see the module documentation for its shape.

See also:

  • ElevatedButton, a filled button whose material elevates when pressed.
  • FilledButton, a filled button that doesn’t elevate when pressed.
  • FilledButton::tonal, a filled button variant that uses a secondary fill color.
  • OutlinedButton, a button with an outlined border and no fill color.
  • TextButton, a button with no outline or fill color.
  • https://m3.material.io/components/buttons/overview, an overview of each of the Material Design button types and how they should be used in designs.

Required Methods§

Source

fn button_style_button_data(&self) -> &ButtonStyleButtonData

Source

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

Returns a ButtonStyle that’s based primarily on the Theme’s ThemeData::text_theme and ThemeData::color_scheme, but has most values filled out (non-null).

The returned style can be overridden by the ButtonStyleButtonData::style parameter and by the style returned by theme_style_of that some button-specific themes like TextButtonTheme or ElevatedButtonTheme override. For example the default style of the TextButton subclass can be overridden with its TextButton::style constructor parameter, or with a TextButtonTheme.

Concrete button subclasses should return a ButtonStyle with as many non-null properties as possible, where all of the non-null WidgetStateProperty properties resolve to non-null values.

§Properties that can be null

Some properties, like ButtonStyle::fixed_size would override other values in the same ButtonStyle if set, so they are allowed to be null. Here is a summary of properties that are allowed to be null when returned in the ButtonStyle returned by this function, an why:

See also:

  • theme_style_of, returns the ButtonStyle of this button’s component theme.
Source

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

Returns the ButtonStyle that belongs to the button’s component theme.

The returned style can be overridden by the ButtonStyleButtonData::style parameter.

Concrete button subclasses should return the ButtonStyle for the nearest subclass-specific inherited theme, and if no such theme exists, then the same value from the overall Theme.

See also:

Provided Methods§

Source

fn enabled(&self) -> bool

Whether the button is enabled or disabled.

Buttons are disabled by default. To enable a button, set its on_pressed or on_long_press properties to a non-null value.

Implementations§

Source§

impl dyn ButtonStyleButton

Source

pub fn all_or_null<T: Clone + Debug + PartialEq + 'static>( value: Option<T>, ) -> Option<WidgetStatePropertyRef<Option<T>>>

Returns null if value is null, otherwise WidgetStatePropertyAll<T>(value).

A convenience method for subclasses.

Source

pub fn default_color( enabled: Option<Color>, disabled: Option<Color>, ) -> Option<WidgetStatePropertyRef<Option<Color>>>

Returns null if enabled and disabled are null. Otherwise, returns a WidgetStateProperty that resolves to disabled when WidgetState::Disabled is active, and enabled otherwise.

A convenience method for subclasses.

Source

pub fn scaled_padding( geometry1x: EdgeInsetsGeometry, geometry2x: EdgeInsetsGeometry, geometry3x: EdgeInsetsGeometry, font_size_multiplier: f64, ) -> EdgeInsetsGeometry

A convenience method used by subclasses in the framework, that returns an interpolated value based on the font_size_multiplier parameter:

  • 0 - 1 geometry1x
  • 1 - 2 lerp(geometry1x, geometry2x, font_size_multiplier - 1)
  • 2 - 3 lerp(geometry2x, geometry3x, font_size_multiplier - 2)
  • otherwise geometry3x

This method is used by the framework for estimating the default paddings to use on a button with a text label, when the system text scaling setting changes. It’s usually supplied with empirical geometry1x, geometry2x, geometry3x values adjusted for different system text scaling values, when the unscaled font size is set to 14.0 (the default TextTheme::label_large value).

The font_size_multiplier argument, for historical reasons, is the default font size specified in the ButtonStyle, scaled by the ambient font scaler, then divided by 14.0 (the default font size used in buttons).

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§