Skip to main content

MaterialIconButton

Struct MaterialIconButton 

Source
pub struct MaterialIconButton<'a> { /* private fields */ }
Expand description

Material Design icon button component.

Icon buttons help users take supplementary actions with a single tap. They’re used when a compact button is required.

§Example

// Standard icon button
if ui.add(MaterialIconButton::standard("favorite")).clicked() {
    println!("Favorite clicked!");
}

// Filled icon button with toggle state
let mut liked = false;
ui.add(MaterialIconButton::filled("favorite")
    .toggle(&mut liked)
    .size(48.0));

Implementations§

Source§

impl<'a> MaterialIconButton<'a>

Source

pub fn new(icon: impl Into<String>, variant: IconButtonVariant) -> Self

Create a new icon button with the specified variant.

§Arguments
  • icon - Icon identifier (e.g., “home”, “settings”, “delete”)
  • variant - Visual variant of the button
§Example
let button = MaterialIconButton::new("settings", IconButtonVariant::Outlined);
Source

pub fn standard(icon: impl Into<String>) -> Self

Create a standard icon button (minimal visual emphasis).

§Arguments
  • icon - Icon identifier
§Example
ui.add(MaterialIconButton::standard("menu"));
Source

pub fn filled(icon: impl Into<String>) -> Self

Create a filled icon button (high emphasis with filled background).

§Arguments
  • icon - Icon identifier
§Example
ui.add(MaterialIconButton::filled("add"));
Source

pub fn filled_tonal(icon: impl Into<String>) -> Self

Create a filled tonal icon button (medium emphasis with tonal background).

§Arguments
  • icon - Icon identifier
§Example
ui.add(MaterialIconButton::filled_tonal("edit"));
Source

pub fn outlined(icon: impl Into<String>) -> Self

Create an outlined icon button (medium emphasis with border).

§Arguments
  • icon - Icon identifier
§Example
ui.add(MaterialIconButton::outlined("delete"));
Source

pub fn toggle(icon: impl Into<String>, selected: &'a mut bool) -> Self

Create a toggleable icon button.

The button’s appearance will change based on the selected state.

§Arguments
  • icon - Icon identifier
  • selected - Mutable reference to the toggle state
§Example
let mut is_favorite = false;
ui.add(MaterialIconButton::toggle("favorite", &mut is_favorite));
Source

pub fn size(self, size: f32) -> Self

Set the size of the icon button.

§Arguments
  • size - Desired size (width and height) of the button
§Example
ui.add(MaterialIconButton::standard("settings").size(48.0));
Source

pub fn enabled(self, enabled: bool) -> Self

Enable or disable the icon button.

§Arguments
  • enabled - true to enable the button, false to disable
§Example
ui.add(MaterialIconButton::standard("download").enabled(false));
Source

pub fn container(self, container: bool) -> Self

Set the container style of the icon button.

§Arguments
  • container - true for rectangular container, false for circular
§Example
ui.add(MaterialIconButton::standard("share").container(true));
Source

pub fn svg(self, path: impl Into<String>) -> Self

Use an SVG file as the icon. The path will be loaded and rasterized.

Source

pub fn svg_data(self, svg_content: impl Into<String>) -> Self

Use inline SVG content as the icon. The content will be rasterized directly.

Source

pub fn icon_color(self, color: Color32) -> Self

Override the icon color.

Source

pub fn on_click<F>(self, f: F) -> Self
where F: Fn() + 'a,

Set the click action for the icon button.

§Arguments
  • f - Function to execute when the button is clicked
§Example
ui.add(MaterialIconButton::standard("info").on_click(|| {
    println!("Info button clicked!");
}));

Trait Implementations§

Source§

impl<'a> Widget for MaterialIconButton<'a>

Source§

fn ui(self, ui: &mut Ui) -> Response

Allocate space, interact, paint, and return a Response. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for MaterialIconButton<'a>

§

impl<'a> !RefUnwindSafe for MaterialIconButton<'a>

§

impl<'a> !Send for MaterialIconButton<'a>

§

impl<'a> !Sync for MaterialIconButton<'a>

§

impl<'a> Unpin for MaterialIconButton<'a>

§

impl<'a> UnsafeUnpin for MaterialIconButton<'a>

§

impl<'a> !UnwindSafe for MaterialIconButton<'a>

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<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more