This commit is contained in:
2025-11-20 23:15:31 +01:00
parent 4d2f0d7b9d
commit b57fffe9b7
6 changed files with 111 additions and 261 deletions
+11 -30
View File
@@ -1,34 +1,15 @@
use osui::{state::use_state, Context, Event, Node};
use std::sync::Arc;
pub struct ClickEvent;
impl Event for ClickEvent {
fn as_any(&self) -> &dyn std::any::Any {
self
}
}
fn app(cx: &mut Context) -> Node {
// Hooks
let count = use_state(0);
cx.event({
let count = count.clone();
move |_: &ClickEvent| {
**count.get() += 1;
}
});
Box::new(move |renderer| {
renderer
.draw_text(&format!("Count: {count}"), 0, 0)
.unwrap();
})
}
use osui::prelude::*;
fn main() {
let mut osui = osui::Osui::new(Box::new(app));
loop {
osui.render().unwrap();
std::thread::sleep(std::time::Duration::from_millis(10));
}
let mut cx = Context::new(app);
cx.refresh();
// println!("{:?}", cx.get_nodes());
}
fn app(cx: &mut Context) -> Vec<Node> {
let count = use_state(0);
vec![Node::String(Arc::new(move || format!("{count}")))]
}