Function rui::text_editor

source ·
pub fn text_editor(text: impl Binding<String>) -> impl View
Expand 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?
examples/gallery.rs (line 37)
32
33
34
35
36
37
38
39
40
fn text_editor_example() -> impl View {
    hstack((
        caption("text_editor"),
        state(
            || "edit me".to_string(),
            |txt, _| text_editor(txt).padding(Auto),
        ),
    ))
}
More examples
Hide additional examples
examples/todo_list.rs (line 6)
3
4
5
6
7
8
9
10
11
12
13
14
15
fn add_button(todos: impl Binding<Vec<String>>) -> impl View {
    state(String::new, move |name, _| {
        hstack((
            text_editor(name),
            button(text("Add Item"), move |cx| {
                let name_str = cx[name].clone();
                todos.with_mut(cx, |todos| todos.push(name_str));
                // Gotta fix a bug in text_editor!
                // cx[name] = String::new();
            }),
        ))
    })
}
examples/text_editor.rs (line 8)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
fn main() {
    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.";
    rui(vstack((
        state(
            move || lorem.to_string(),
            |state, _| text_editor(state).padding(Auto),
        )
        .background(
            rectangle()
                .color(BUTTON_BACKGROUND_COLOR)
                .corner_radius(5.0),
        )
        .padding(Auto),
        state(
            move || lorem.to_string(),
            |state, _| text_editor(state).padding(Auto),
        )
        .background(
            rectangle()
                .color(BUTTON_BACKGROUND_COLOR)
                .corner_radius(5.0),
        )
        .padding(Auto),
    )));
}