pub struct Button { /* private fields */ }Expand description
Clickable button widget.
Implementations§
Source§impl Button
impl Button
Sourcepub fn new(text: impl Into<String>, bounds: Rect) -> Button
pub fn new(text: impl Into<String>, bounds: Rect) -> Button
Create a new button with the provided label text.
Examples found in repository?
examples/demo.rs (line 65)
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 set_on_click<F>(&mut self, handler: F)
pub fn set_on_click<F>(&mut self, handler: F)
Register a callback invoked when the button is released.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Button
impl !RefUnwindSafe for Button
impl !Send for Button
impl !Sync for Button
impl Unpin for Button
impl UnsafeUnpin for Button
impl !UnwindSafe for Button
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