31 lines
822 B
Rust
31 lines
822 B
Rust
use iris::prelude::*;
|
|
use std::time::Duration;
|
|
|
|
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.task_on(CursorSense::click(), async move |mut ctx| {
|
|
tokio::time::sleep(Duration::from_secs(1)).await;
|
|
ctx.task.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 }
|
|
}
|
|
}
|