47 lines
942 B
Rust
47 lines
942 B
Rust
use iris::prelude::*;
|
|
|
|
fn main() {
|
|
DefaultApp::<State>::run();
|
|
}
|
|
|
|
#[derive(DefaultUiState)]
|
|
struct State {
|
|
ui_state: DefaultUiState,
|
|
}
|
|
|
|
type Rsc = DefaultRsc<State>;
|
|
|
|
#[derive(Clone, Copy, WidgetView)]
|
|
struct Test {
|
|
#[root]
|
|
root: WeakWidget<Rect>,
|
|
}
|
|
|
|
impl Test {
|
|
pub fn new(rsc: &mut Rsc) -> Self {
|
|
let root = rect(Color::RED).add(rsc);
|
|
Self { root }
|
|
}
|
|
pub fn toggle(&self, rsc: &mut Rsc) {
|
|
let rect = (self.root)(rsc);
|
|
if rect.color == Color::RED {
|
|
rect.color = Color::BLUE;
|
|
} else {
|
|
rect.color = Color::RED;
|
|
}
|
|
}
|
|
}
|
|
|
|
impl DefaultAppState for State {
|
|
fn new(ui_state: DefaultUiState, rsc: &mut DefaultRsc<Self>, _: Proxy<Self::Event>) -> Self {
|
|
let test = Test::new(rsc);
|
|
|
|
test.on(CursorSense::click(), move |_, rsc| {
|
|
test.toggle(rsc);
|
|
})
|
|
.set_root(rsc);
|
|
|
|
Self { ui_state }
|
|
}
|
|
}
|