tasks initial impl (still working on task_on trait method)
This commit is contained in:
33
examples/task.rs
Normal file
33
examples/task.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
use std::time::Duration;
|
||||
|
||||
iris::state_prelude!(DefaultRsc<State>);
|
||||
|
||||
fn main() {
|
||||
DefaultApp::<State>::run();
|
||||
}
|
||||
|
||||
#[derive(DefaultUiState)]
|
||||
struct State {
|
||||
ui_state: DefaultUiState,
|
||||
}
|
||||
|
||||
impl DefaultAppState for State {
|
||||
fn new(ui_state: DefaultUiState, rsc: &mut DefaultRsc<Self>, _: Proxy<Self::Event>) -> Self {
|
||||
let rect = rect(Color::RED).add(rsc);
|
||||
rect.on(CursorSense::click(), move |_, rsc| {
|
||||
rsc.tasks.spawn(async move |ctx| {
|
||||
tokio::time::sleep(Duration::from_secs(1)).await;
|
||||
ctx.update(move |_, rsc| {
|
||||
let rect = rect(rsc);
|
||||
if rect.color == Color::RED {
|
||||
rect.color = Color::GREEN;
|
||||
} else {
|
||||
rect.color = Color::RED;
|
||||
}
|
||||
});
|
||||
});
|
||||
})
|
||||
.set_root(rsc);
|
||||
Self { ui_state }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user