pub struct Input { /* private fields */ }Expand description
Single-line text input component.
Implementations§
Source§impl Input
impl Input
Sourcepub fn new(text: &str, bounds: Rect) -> Self
pub fn new(text: &str, bounds: Rect) -> Self
Create a new input with the provided initial value and bounds.
Examples found in repository?
examples/demo.rs (line 87)
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_change<F: FnMut(&str) + 'static>(self, handler: F) -> Self
pub fn on_change<F: FnMut(&str) + 'static>(self, handler: F) -> Self
Register a change handler invoked when Self::set_text is called.
Examples found in repository?
examples/demo.rs (line 87)
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§
Auto Trait Implementations§
impl Freeze for Input
impl !RefUnwindSafe for Input
impl !Send for Input
impl !Sync for Input
impl Unpin for Input
impl UnsafeUnpin for Input
impl !UnwindSafe for Input
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