State management

This commit is contained in:
2025-11-20 17:17:18 +01:00
parent ff351caee0
commit 4d2f0d7b9d
3 changed files with 113 additions and 4 deletions
+12 -4
View File
@@ -1,4 +1,4 @@
use osui::{Context, Event, Node};
use osui::{state::use_state, Context, Event, Node};
pub struct ClickEvent;
@@ -10,10 +10,18 @@ impl Event for ClickEvent {
fn app(cx: &mut Context) -> Node {
// Hooks
cx.event(|_: &ClickEvent| {});
let count = use_state(0);
cx.event({
let count = count.clone();
move |_: &ClickEvent| {
**count.get() += 1;
}
});
Box::new(|renderer| {
renderer.draw_text("Hello, World!", 0, 0).unwrap();
Box::new(move |renderer| {
renderer
.draw_text(&format!("Count: {count}"), 0, 0)
.unwrap();
})
}