cushy/examples/counter.rs
Jonathan Johnson 83e44912ee
ReadOnly<T>, Owned<T>, IntoSource<T>, more
Closes #98

This finishes my initial refactoring of the dynamic system to add
support for several dataflows including:

- Pure data sources that can be implemented using an `Owned<T>` at the
  root of a graph of `Dynamic<U>`/`DynamicReader<U>`s.
- Read-only data sinks. I thought this would be more useful across other
  widgets, but in general, Progress and Label seem like the only types
  that this applies to currently.
- The ability to mix/match Dynamic/DynamicReader in tuple-based
  for_each/map_each.
2024-01-02 14:36:53 -08:00

26 lines
643 B
Rust

use cushy::value::{Dynamic, IntoReader};
use cushy::widget::MakeWidget;
use cushy::Run;
use figures::units::Lp;
fn main() -> cushy::Result {
let counter = Dynamic::new(0i32);
counter
.clone()
.into_label()
.width(Lp::points(100))
.and("+".into_button().on_click(counter.with_clone(|counter| {
move |_| {
*counter.lock() += 1;
}
})))
.and("-".into_button().on_click(counter.with_clone(|counter| {
move |_| {
*counter.lock() -= 1;
}
})))
.into_columns()
.centered()
.run()
}