pub struct IconButton { /* private fields */ }Expand description
Icon-only button wrapper.
Implementations§
Source§impl IconButton
impl IconButton
Sourcepub fn new(icon: &str, bounds: Rect) -> Self
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}Sourcepub fn on_click<F: FnMut(&mut BaseButton) + 'static>(self, handler: F) -> Self
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}Trait Implementations§
Source§impl Widget for IconButton
impl Widget for IconButton
Auto Trait Implementations§
impl Freeze for IconButton
impl !RefUnwindSafe for IconButton
impl !Send for IconButton
impl !Sync for IconButton
impl Unpin for IconButton
impl UnsafeUnpin for IconButton
impl !UnwindSafe for IconButton
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more