2023-01-02 00:57:33 +00:00
|
|
|
use dioxus::prelude::*;
|
|
|
|
use dioxus_signals::{use_init_signal_rt, use_signal};
|
|
|
|
use std::time::Duration;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
dioxus_desktop::launch(app);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn app(cx: Scope) -> Element {
|
|
|
|
use_init_signal_rt(cx);
|
|
|
|
|
|
|
|
let mut count = use_signal(cx, || 0);
|
|
|
|
|
2023-01-02 03:09:08 +00:00
|
|
|
use_future!(cx, || async move {
|
2023-01-02 00:57:33 +00:00
|
|
|
loop {
|
2023-01-02 03:02:49 +00:00
|
|
|
count += 1;
|
2023-01-02 03:57:16 +00:00
|
|
|
tokio::time::sleep(Duration::from_millis(400)).await;
|
2023-01-02 00:57:33 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
cx.render(rsx! {
|
|
|
|
h1 { "High-Five counter: {count}" }
|
|
|
|
button { onclick: move |_| count += 1, "Up high!" }
|
|
|
|
button { onclick: move |_| count -= 1, "Down low!" }
|
2023-01-02 03:57:16 +00:00
|
|
|
|
|
|
|
if count() > 5 {
|
|
|
|
rsx!{ h2 { "High five!" } }
|
|
|
|
}
|
2023-01-02 00:57:33 +00:00
|
|
|
})
|
|
|
|
}
|