2
0
Fork 0
mirror of https://github.com/DioxusLabs/dioxus synced 2024-12-18 08:33:07 +00:00
dioxus/examples/control_focus.rs

45 lines
1.1 KiB
Rust
Raw Normal View History

2023-03-24 16:32:42 +00:00
use std::rc::Rc;
use dioxus::prelude::*;
fn main() {
launch_desktop(app);
2023-03-24 16:32:42 +00:00
}
fn app() -> Element {
let mut elements = use_signal(Vec::<Rc<MountedData>>::new);
let mut running = use_signal(|| true);
2023-03-24 16:32:42 +00:00
2024-01-15 21:06:05 +00:00
use_future(move || async move {
2023-03-24 16:32:42 +00:00
let mut focused = 0;
if running() {
2023-03-24 16:32:42 +00:00
loop {
tokio::time::sleep(std::time::Duration::from_millis(10)).await;
2024-01-11 07:26:26 +00:00
if let Some(element) = elements.with(|f| f.get(focused).cloned()) {
_ = element.set_focus(true).await;
2023-03-24 16:32:42 +00:00
} else {
focused = 0;
}
focused += 1;
}
}
});
2024-01-16 19:18:46 +00:00
rsx! {
2023-03-24 16:32:42 +00:00
div {
h1 { "Input Roulette" }
for i in 0..100 {
input {
value: "{i}",
onmounted: move |cx| {
elements.write().push(cx.inner().clone());
},
oninput: move |_| {
running.set(false);
}
}
}
}
2024-01-14 05:12:21 +00:00
}
2023-03-24 16:32:42 +00:00
}