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>
impl<'a, ICON: IconoirIcon> IconButton<'a, ICON>
Sourcepub fn new(_icon: ICON) -> Self
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));Sourcepub fn label(self, label: &'a str) -> Self
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"));Sourcepub fn new_from_type() -> Self
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());Sourcepub fn smartstate(self, smartstate: &'a mut Smartstate) -> Self
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>
impl<ICON: IconoirIcon> Debug for IconButton<'_, ICON>
Source§impl<ICON: IconoirIcon> Widget for IconButton<'_, ICON>
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>
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:
- Calculates the size based on icon and optional label
- Allocates space for the widget
- Positions the icon and optional label
- Detects interactions (hover, click, press)
- Manages visual appearance based on interaction state
- Updates the smartstate and draws when necessary
- Returns a response that includes click information