semi working state management

This commit is contained in:
2025-07-27 02:35:36 +02:00
parent 0878cad01c
commit 327f14d9ed
4 changed files with 135 additions and 44 deletions
+13 -7
View File
@@ -1,17 +1,23 @@
use osui::{elements::state::use_state, Screen};
use osui::{dependency::Dependency, elements::state::use_state, style::Transform, Screen};
fn main() -> std::io::Result<()> {
let screen = Screen::new();
let count = use_state(0);
screen.draw(count.draw({
let count = count.clone();
move || Box::new(format!("Count: {count}"))
}));
screen
.draw(
Dependency::new({
let count = count.clone();
move || format!("{count}")
})
.add(count.clone()),
)
.component(Transform::center());
std::thread::spawn(move || loop {
std::thread::sleep(std::time::Duration::from_millis(500));
count.set(unsafe { *count.value } + 1);
std::thread::sleep(std::time::Duration::from_millis(900));
let c = (*count).clone();
count.set(c + 1);
});
screen.run()