text

Function text 

Source
pub fn text(name: &str) -> Text
Expand description

Shows a string as a label (not editable).

Examples found in repository?
examples/clip.rs (line 5)
3fn main() {
4    rui(hstack((
5        text("This text is clipped.")
6            // .offset([0.0, 0.0])
7            .clip(),
8        text("This text isn't clipped."),
9    )))
10}
More examples
Hide additional examples
examples/action.rs (line 13)
5fn main() {
6    rui(vstack((
7        rectangle()
8            .tap(|_| {
9                println!("rect tapped");
10                MyAction {}
11            })
12            .padding(Auto),
13        text("tap the rectangle to send an action"),
14    ))
15    .handle(|_, _: &MyAction| println!("action received")));
16}
examples/calc.rs (line 12)
5fn digit_button(title: &str, state: StateHandle<String>) -> impl View {
6    let t = String::from(title);
7    zstack((
8        rectangle()
9            .corner_radius(10.0)
10            .color(RED_HIGHLIGHT)
11            .tap(move |cx| cx[state].push_str(&t)),
12        text(title).color(BLACK).offset([10.0, 10.0]),
13    ))
14    .padding(Auto)
15}
16
17fn calc_button(title: &str, callback: impl Fn(&mut Context) + 'static) -> impl View {
18    zstack((
19        rectangle()
20            .corner_radius(10.0)
21            .color(GREEN_HIGHLIGHT)
22            .tap(callback),
23        text(title).color(BLACK).offset([10.0, 10.0]),
24    ))
25    .padding(Auto)
26}
27
28fn main() {
29    rui(state(
30        || String::from("0"),
31        |s, cx| {
32            vstack((
33                text(&cx[s].to_string()),
34                hstack((
35                    calc_button("AC", move |cx| cx[s] = "0".into()),
36                    calc_button("+/-", |_| ()),
37                    calc_button("%", |_| ()),
38                    calc_button("/", |_| ()),
39                )),
40                hstack((
41                    digit_button("7", s),
42                    digit_button("8", s),
43                    digit_button("9", s),
44                    calc_button("*", |_| ()),
45                )),
46                hstack((
47                    digit_button("4", s),
48                    digit_button("5", s),
49                    digit_button("6", s),
50                    calc_button("-", |_| ()),
51                )),
52                hstack((
53                    digit_button("1", s),
54                    digit_button("2", s),
55                    digit_button("3", s),
56                    calc_button("+", |_| ()),
57                )),
58                hstack((
59                    digit_button("0", s),
60                    calc_button(".", move |cx| cx[s].push_str(".")),
61                    calc_button("=", |_| ()),
62                )),
63            ))
64        },
65    ))
66}
examples/todo_list.rs (line 7)
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/async.rs (line 19)
7fn main() {
8    rui(state(
9        || "task not started".to_string(),
10        |s, cx| {
11            hstack((
12                button("press to begin", move |_| {
13                    spawn(move || {
14                        on_main(move |cx| cx[s] = "task started".into());
15                        sleep(Duration::from_secs(2));
16                        on_main(move |cx| cx[s] = "task complete".into());
17                    });
18                }),
19                text(&cx[s]),
20            ))
21        },
22    ));
23}