cushy/examples/counter.rs
Jonathan Johnson 58b98a9a16
LinearInterpolation now requires PartialEq
This also means that if an animation is animating over discrete values
and the actual value has not changed, the Dynamic will no longer detect
a change because it's now using update instead of set.
2023-11-09 07:46:02 -08:00

28 lines
795 B
Rust

use std::string::ToString;
use gooey::value::Dynamic;
use gooey::widget::MakeWidget;
use gooey::widgets::{Button, Label, Resize, Stack};
use gooey::Run;
use kludgine::figures::units::Lp;
fn main() -> gooey::Result {
let counter = Dynamic::new(0i32);
let label = counter.map_each(ToString::to_string);
Stack::columns(
Resize::width(Lp::points(100), Label::new(label))
.and(Button::new("+").on_click(counter.with_clone(|counter| {
move |_| {
*counter.lock() += 1;
}
})))
.and(Button::new("-").on_click(counter.with_clone(|counter| {
move |_| {
*counter.lock() -= 1;
}
}))),
)
.centered()
.expand()
.run()
}