cushy/examples/counter.rs
Jonathan Johnson c9c4c9aeed
Documentation
2023-10-30 21:12:04 -07:00

25 lines
675 B
Rust

use std::string::ToString;
use gooey::value::Dynamic;
use gooey::widgets::array::Array;
use gooey::widgets::{Button, Label};
use gooey::{widgets, Run};
fn main() -> gooey::Result {
let counter = Dynamic::new(0i32);
let label = counter.map_each(ToString::to_string);
Array::rows(widgets![
Label::new(label),
Button::new("+").on_click(counter.with_clone(|counter| {
move |_| {
counter.set(counter.get() + 1);
}
})),
Button::new("-").on_click(counter.with_clone(|counter| {
move |_| {
counter.set(counter.get() - 1);
}
})),
])
.run()
}