cushy/examples/basic-button.rs
Jonathan Johnson df479e983e
Renaming crate to Cushy
Refs #117
2023-12-27 19:02:59 -08:00

20 lines
630 B
Rust

use cushy::value::Dynamic;
use cushy::widget::MakeWidget;
use cushy::Run;
// begin rustme snippet: readme
fn main() -> cushy::Result {
// Create a dynamic usize.
let count = Dynamic::new(0_isize);
// Create a dynamic that contains `count.to_string()`
let count_label = count.map_each(ToString::to_string);
// Create a new button whose text is our dynamic string.
count_label
.into_button()
// Set the `on_click` callback to a closure that increments the counter.
.on_click(move |_| count.set(count.get() + 1))
// Run the application
.run()
}
// end rustme snippet