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