IconButton

Struct IconButton 

Source
pub struct IconButton<'a, ICON: IconoirIcon> { /* private fields */ }
Expand description

A button widget that displays an icon with optional text label.

IconButton combines the visual display of an icon with interactive button behavior. It changes appearance based on user interaction (normal, hover, pressed) and can optionally display a text label underneath the icon.

Implementations§

Source§

impl<'a, ICON: IconoirIcon> IconButton<'a, ICON>

Source

pub fn new(_icon: ICON) -> Self

Creates a new IconButton from an IconoirIcon instance.

The icon color from the icon instance will be ignored, as the widget will use the icon color from the current UI style.

To see all icons you can use, look at embedded_iconoir::size12px. All other icon resolutions (from embedded_iconoir::size12px to embedded_iconoir::size144px) are available.

§Example
use embedded_iconoir::size24px;
ui.add(IconButton::new(size24px::actions::AddCircle));
Source

pub fn label(self, label: &'a str) -> Self

Adds a text label/subtitle below the icon.

The label text will be centered below the icon and sized according to the current UI style font settings.

§Example
use embedded_iconoir::size24px;
ui.add(IconButton::new(size24px::actions::AddCircle).label("Add"));
Source

pub fn new_from_type() -> Self

Creates a new IconButton using just the icon’s type.

This is a convenience method that allows creating an icon button without instantiating the icon object first.

§Example
use embedded_iconoir::size24px;
ui.add(IconButton::<size24px::actions::AddCircle>::new_from_type());
Source

pub fn smartstate(self, smartstate: &'a mut Smartstate) -> Self

Attaches a Smartstate to this widget for incremental redrawing.

When a smartstate is attached, the widget will only redraw when its state changes, improving performance for stationary UI elements.

§Example
let mut my_smartstate = Smartstate::empty();
ui.add(IconButton::new(size12px::actions::AddCircle).smartstate(&mut my_smartstate));

Returns self for method chaining.

Trait Implementations§

Source§

impl<ICON: IconoirIcon> Debug for IconButton<'_, ICON>

Source§

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

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

impl<ICON: IconoirIcon> Widget for IconButton<'_, ICON>

Source§

fn draw<DRAW: DrawTarget<Color = COL>, COL: PixelColor>( &mut self, ui: &mut Ui<'_, DRAW, COL>, ) -> GuiResult<Response>

Draws the icon button within the UI.

This method:

  1. Calculates the size based on icon and optional label
  2. Allocates space for the widget
  3. Positions the icon and optional label
  4. Detects interactions (hover, click, press)
  5. Manages visual appearance based on interaction state
  6. Updates the smartstate and draws when necessary
  7. Returns a response that includes click information

Auto Trait Implementations§

§

impl<'a, ICON> Freeze for IconButton<'a, ICON>

§

impl<'a, ICON> RefUnwindSafe for IconButton<'a, ICON>
where ICON: RefUnwindSafe,

§

impl<'a, ICON> Send for IconButton<'a, ICON>
where ICON: Send,

§

impl<'a, ICON> Sync for IconButton<'a, ICON>
where ICON: Sync,

§

impl<'a, ICON> Unpin for IconButton<'a, ICON>
where ICON: Unpin,

§

impl<'a, ICON> !UnwindSafe for IconButton<'a, ICON>

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

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
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<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
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> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
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> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.