Skip to main content

IconButton

Struct IconButton 

Source
pub struct IconButton { /* private fields */ }
Expand description

Icon-only button wrapper.

Implementations§

Source§

impl IconButton

Source

pub fn new(icon: &str, bounds: Rect) -> Self

Create a new icon button using the named glyph.

Examples found in repository?
examples/demo.rs (line 70)
13fn main() {
14    let theme = Theme::material_light();
15    let style = StyleBuilder::new()
16        .bg(theme.tokens.colors.primary)
17        .radius(theme.tokens.radii.md)
18        .build();
19
20    let layout = {
21        #[cfg(feature = "view")]
22        {
23            view! { VStack::new(90)
24            .child(20, |rect| Heading::new("Demo", rect))
25            .child(20, |rect| Text::new("Hello", rect))
26            .child(30, |rect| {
27                Button::new("Tap", rect)
28                    .icon("save")
29                    .on_click(|_| println!("clicked"))
30            })
31            .child(30, |rect| {
32                IconButton::new("edit", rect)
33                    .on_click(|_| println!("edit"))
34            })
35            .child(20, |rect| {
36                Checkbox::new("Accept", rect).on_change(|v| println!("checkbox: {v}"))
37            })
38            .child(20, |rect| {
39                Switch::new(rect).on_change(|v| println!("switch: {v}"))
40            })
41            .child(20, |rect| {
42                Radio::new("Option", rect).on_change(|v| println!("radio: {v}"))
43            })
44            .child(20, |rect| { Badge::new("NEW", rect) })
45            .child(20, |rect| {
46                Tag::new("rust", rect).on_remove(|| println!("tag removed"))
47            })
48            .child(30, |rect| { Alert::new("Saved", rect) })
49            .child(20, |rect| {
50                Input::new("Name", rect).on_change(|v| println!("input: {v}"))
51            })
52            .child(40, |rect| {
53                Textarea::new("Multiline", rect).on_change(|v| println!("textarea: {v}"))
54            })
55            .child(30, |rect| Modal::new("Modal", rect))
56            .child(30, |rect| Drawer::new("Menu", rect))
57            .child(30, |rect| Toast::new("Saved", rect)) }
58        }
59        #[cfg(not(feature = "view"))]
60        {
61            VStack::new(90)
62                .child(20, |rect| Heading::new("Demo", rect))
63                .child(20, |rect| Text::new("Hello", rect))
64                .child(30, |rect| {
65                    Button::new("Tap", rect)
66                        .icon("save")
67                        .on_click(|_| println!("clicked"))
68                })
69                .child(30, |rect| {
70                    IconButton::new("edit", rect).on_click(|_| println!("edit"))
71                })
72                .child(20, |rect| {
73                    Checkbox::new("Accept", rect).on_change(|v| println!("checkbox: {v}"))
74                })
75                .child(20, |rect| {
76                    Switch::new(rect).on_change(|v| println!("switch: {v}"))
77                })
78                .child(20, |rect| {
79                    Radio::new("Option", rect).on_change(|v| println!("radio: {v}"))
80                })
81                .child(20, |rect| Badge::new("NEW", rect))
82                .child(20, |rect| {
83                    Tag::new("rust", rect).on_remove(|| println!("tag removed"))
84                })
85                .child(30, |rect| Alert::new("Saved", rect))
86                .child(20, |rect| {
87                    Input::new("Name", rect).on_change(|v| println!("input: {v}"))
88                })
89                .child(40, |rect| {
90                    Textarea::new("Multiline", rect).on_change(|v| println!("textarea: {v}"))
91                })
92                .child(30, |rect| Modal::new("Modal", rect))
93                .child(30, |rect| Drawer::new("Menu", rect))
94                .child(30, |rect| Toast::new("Saved", rect))
95        }
96    };
97
98    let _ = (style, layout);
99}
Source

pub fn on_click<F: FnMut(&mut BaseButton) + 'static>(self, handler: F) -> Self

Register a click handler executed when the button is released.

Examples found in repository?
examples/demo.rs (line 70)
13fn main() {
14    let theme = Theme::material_light();
15    let style = StyleBuilder::new()
16        .bg(theme.tokens.colors.primary)
17        .radius(theme.tokens.radii.md)
18        .build();
19
20    let layout = {
21        #[cfg(feature = "view")]
22        {
23            view! { VStack::new(90)
24            .child(20, |rect| Heading::new("Demo", rect))
25            .child(20, |rect| Text::new("Hello", rect))
26            .child(30, |rect| {
27                Button::new("Tap", rect)
28                    .icon("save")
29                    .on_click(|_| println!("clicked"))
30            })
31            .child(30, |rect| {
32                IconButton::new("edit", rect)
33                    .on_click(|_| println!("edit"))
34            })
35            .child(20, |rect| {
36                Checkbox::new("Accept", rect).on_change(|v| println!("checkbox: {v}"))
37            })
38            .child(20, |rect| {
39                Switch::new(rect).on_change(|v| println!("switch: {v}"))
40            })
41            .child(20, |rect| {
42                Radio::new("Option", rect).on_change(|v| println!("radio: {v}"))
43            })
44            .child(20, |rect| { Badge::new("NEW", rect) })
45            .child(20, |rect| {
46                Tag::new("rust", rect).on_remove(|| println!("tag removed"))
47            })
48            .child(30, |rect| { Alert::new("Saved", rect) })
49            .child(20, |rect| {
50                Input::new("Name", rect).on_change(|v| println!("input: {v}"))
51            })
52            .child(40, |rect| {
53                Textarea::new("Multiline", rect).on_change(|v| println!("textarea: {v}"))
54            })
55            .child(30, |rect| Modal::new("Modal", rect))
56            .child(30, |rect| Drawer::new("Menu", rect))
57            .child(30, |rect| Toast::new("Saved", rect)) }
58        }
59        #[cfg(not(feature = "view"))]
60        {
61            VStack::new(90)
62                .child(20, |rect| Heading::new("Demo", rect))
63                .child(20, |rect| Text::new("Hello", rect))
64                .child(30, |rect| {
65                    Button::new("Tap", rect)
66                        .icon("save")
67                        .on_click(|_| println!("clicked"))
68                })
69                .child(30, |rect| {
70                    IconButton::new("edit", rect).on_click(|_| println!("edit"))
71                })
72                .child(20, |rect| {
73                    Checkbox::new("Accept", rect).on_change(|v| println!("checkbox: {v}"))
74                })
75                .child(20, |rect| {
76                    Switch::new(rect).on_change(|v| println!("switch: {v}"))
77                })
78                .child(20, |rect| {
79                    Radio::new("Option", rect).on_change(|v| println!("radio: {v}"))
80                })
81                .child(20, |rect| Badge::new("NEW", rect))
82                .child(20, |rect| {
83                    Tag::new("rust", rect).on_remove(|| println!("tag removed"))
84                })
85                .child(30, |rect| Alert::new("Saved", rect))
86                .child(20, |rect| {
87                    Input::new("Name", rect).on_change(|v| println!("input: {v}"))
88                })
89                .child(40, |rect| {
90                    Textarea::new("Multiline", rect).on_change(|v| println!("textarea: {v}"))
91                })
92                .child(30, |rect| Modal::new("Modal", rect))
93                .child(30, |rect| Drawer::new("Menu", rect))
94                .child(30, |rect| Toast::new("Saved", rect))
95        }
96    };
97
98    let _ = (style, layout);
99}
Source

pub fn style(&self) -> &Style

Immutable access to the button style.

Source

pub fn style_mut(&mut self) -> &mut Style

Mutable access to the button style.

Trait Implementations§

Source§

impl Widget for IconButton

Source§

fn bounds(&self) -> Rect

Return the area this widget occupies relative to its parent.
Source§

fn draw(&self, renderer: &mut dyn Renderer)

Render the widget using the provided Renderer.
Source§

fn handle_event(&mut self, event: &Event) -> bool

Handle an event and return true if it was consumed. Read more
Source§

fn clear_region(&mut self) -> Option<Rect>

Return a region (in draw/landscape coordinates) that should be restored from the pristine background copy, or None. Read more

Auto Trait Implementations§

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> 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, 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.