54 lines
1.1 KiB
Rust
54 lines
1.1 KiB
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>,
|
|
cur: WeakState<bool>,
|
|
}
|
|
|
|
impl Test {
|
|
pub fn new(rsc: &mut Rsc) -> Self {
|
|
let root = rect(Color::RED).add(rsc);
|
|
let cur = rsc.create_state(root, false);
|
|
Self { root, cur }
|
|
}
|
|
pub fn toggle(&self, rsc: &mut Rsc) {
|
|
let cur = &mut rsc[self.cur];
|
|
*cur = !*cur;
|
|
if *cur {
|
|
rsc[self.root].color = Color::BLUE;
|
|
} else {
|
|
rsc[self.root].color = Color::RED;
|
|
}
|
|
}
|
|
}
|
|
|
|
impl DefaultAppState for State {
|
|
fn new(
|
|
mut 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, &mut ui_state);
|
|
|
|
Self { ui_state }
|
|
}
|
|
}
|