widget view

This commit is contained in:
2026-01-05 17:01:09 -05:00
parent 07de7c8722
commit d11107f965
7 changed files with 130 additions and 15 deletions

View File

@@ -18,7 +18,7 @@ impl DefaultAppState for State {
ctx.task.update(move |_, rsc| {
let rect = rect(rsc);
if rect.color == Color::RED {
rect.color = Color::GREEN;
rect.color = Color::BLUE;
} else {
rect.color = Color::RED;
}

46
examples/view.rs Normal file
View File

@@ -0,0 +1,46 @@
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: WidgetRef<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 }
}
}