Function rui::on_main

source ·
pub fn on_main(f: impl FnOnce(&mut Context) + Send + 'static)
Examples found in repository?
examples/async.rs (line 14)
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]),
            ))
        },
    ));
}