mirror of
https://github.com/danbulant/cushy
synced 2026-05-24 12:28:23 +00:00
29 lines
1.1 KiB
Rust
29 lines
1.1 KiB
Rust
use gooey::value::Dynamic;
|
|
use gooey::widget::MakeWidget;
|
|
use gooey::widgets::button::ButtonOutline;
|
|
use gooey::widgets::Button;
|
|
use gooey::Run;
|
|
use kludgine::Color;
|
|
|
|
// begin rustme snippet: readme
|
|
fn main() -> gooey::Result {
|
|
// Create a dynamic usize.
|
|
let count = Dynamic::new(0_isize);
|
|
|
|
// Create a new button with a label that is produced by mapping the contents
|
|
// of `count`.
|
|
Button::new(count.map_each(ToString::to_string))
|
|
// Set the `on_click` callback to a closure that increments the counter.
|
|
.on_click(count.with_clone(|count| move |_| count.set(count.get() + 1)))
|
|
.and(
|
|
// Creates a second, outlined button
|
|
Button::new(count.map_each(ToString::to_string))
|
|
// Set the `on_click` callback to a closure that decrements the counter.
|
|
.on_click(count.with_clone(|count| move |_| count.set(count.get() - 1)))
|
|
.with(&ButtonOutline, Color::DARKRED),
|
|
)
|
|
.into_columns()
|
|
// Run the button as an an application.
|
|
.run()
|
|
}
|
|
// end rustme snippet
|