use iris::prelude::*; fn main() { DesktopApp::::run(); } #[derive(DesktopUiState)] struct State { ui_state: DesktopUiState, } type Rsc = DesktopRsc; #[derive(Clone, Copy, WidgetView)] struct Test { #[root] root: WeakWidget, cur: WeakState, } impl Test { pub fn new(rsc: &mut Rsc) -> Self { let root = rect(PaintId::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].set_paint(PaintId::BLUE); } else { rsc[self.root].set_paint(PaintId::RED); } } } impl DesktopAppState for State { fn new( mut ui_state: DesktopUiState, rsc: &mut DesktopRsc, _: Proxy, ) -> Self { let test = Test::new(rsc); test.on(CursorSense::click(), move |_, rsc| { test.toggle(rsc); }) .set_root(rsc, &mut ui_state); Self { ui_state } } }