pub fn text_editor(text: impl Binding<String>) -> impl ViewExpand description
A multi-line text editor.
This shows how a complex View with internal state can be created from more atomic Views.
Examples found in repository?
More examples
examples/todo_list.rs (line 6)
3fn add_button(todos: impl Binding<Vec<String>>) -> impl View {
4 state(String::new, move |name, _| {
5 hstack((
6 text_editor(name),
7 button(text("Add Item"), move |cx| {
8 let name_str = cx[name].clone();
9 todos.with_mut(cx, |todos| todos.push(name_str));
10 // Gotta fix a bug in text_editor!
11 // cx[name] = String::new();
12 }),
13 ))
14 })
15}examples/text_editor.rs (line 8)
3fn main() {
4 let lorem = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
5 rui(vstack((
6 state(
7 move || lorem.to_string(),
8 |state, _| text_editor(state).padding(Auto),
9 )
10 .background(
11 rectangle()
12 .color(BUTTON_BACKGROUND_COLOR)
13 .corner_radius(5.0),
14 )
15 .padding(Auto),
16 state(
17 move || lorem.to_string(),
18 |state, _| text_editor(state).padding(Auto),
19 )
20 .background(
21 rectangle()
22 .color(BUTTON_BACKGROUND_COLOR)
23 .corner_radius(5.0),
24 )
25 .padding(Auto),
26 )));
27}