cushy/examples/counter.rs
Jonathan Johnson 0f6d3838b1
LayoutContext
measure() now is layout(). LayoutContext can either persist layout
information or be used temporarily for measurement. While this caching
is constantly thrown out currently, this is a step towards being able to
only re-layout widgets if they've been invalidated.
2023-11-05 11:50:59 -08:00

25 lines
772 B
Rust

use std::string::ToString;
use gooey::value::Dynamic;
use gooey::widgets::{Align, Button, Expand, Label, Resize, Stack};
use gooey::{children, Run};
use kludgine::figures::units::Lp;
fn main() -> gooey::Result {
let counter = Dynamic::new(0i32);
let label = counter.map_each(ToString::to_string);
Expand::new(Align::centered(Stack::columns(children![
Resize::width(Lp::points(100), 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()
}