mirror of
https://github.com/danbulant/cushy
synced 2026-05-19 20:28:42 +00:00
Refs #98 This refactor overhauls the reactive system to move all the reactive methods to traits. The side effect of this change is that now DynamicReader's API is the same as Dynamic's API, but because it only implements Source<T>, DynamicReader does not offer any mutation functions. While it's unfortunate to have more traits to include to use Cushy, this seems like the best option, and it offers a path to try to integrate this into the tuple ForEach/MapEach traits. Unfortunately, my attempt at doing those in this set of changes led to issues specifying generic associated lifetimes for the DynamicGuard. But, I was also in the middle of this larger refactoring, so it might be that a fresh attempt will succeed.
58 lines
2 KiB
Rust
58 lines
2 KiB
Rust
use cushy::value::{Destination, Dynamic, Source};
|
|
use cushy::widget::MakeWidget;
|
|
use cushy::widgets::button::ButtonKind;
|
|
use cushy::Run;
|
|
|
|
fn main() -> cushy::Result {
|
|
let clicked_label = Dynamic::new(String::from("Click a Button"));
|
|
let default_is_outline = Dynamic::new(false);
|
|
let default_button_style = default_is_outline.map_each(|is_outline| {
|
|
if *is_outline {
|
|
ButtonKind::Outline
|
|
} else {
|
|
ButtonKind::Solid
|
|
}
|
|
});
|
|
|
|
clicked_label
|
|
.clone()
|
|
.and(
|
|
"Normal Button"
|
|
.into_button()
|
|
.on_click(
|
|
clicked_label.with_clone(|label| {
|
|
move |_| label.set(String::from("Clicked Normal Button"))
|
|
}),
|
|
)
|
|
.and(
|
|
"Outline Button"
|
|
.into_button()
|
|
.on_click(clicked_label.with_clone(|label| {
|
|
move |_| label.set(String::from("Clicked Outline Button"))
|
|
}))
|
|
.kind(ButtonKind::Outline),
|
|
)
|
|
.and(
|
|
"Transparent Button"
|
|
.into_button()
|
|
.on_click(clicked_label.with_clone(|label| {
|
|
move |_| label.set(String::from("Clicked Transparent Button"))
|
|
}))
|
|
.kind(ButtonKind::Transparent),
|
|
)
|
|
.and(
|
|
"Default Button"
|
|
.into_button()
|
|
.on_click(clicked_label.with_clone(|label| {
|
|
move |_| label.set(String::from("Clicked Default Button"))
|
|
}))
|
|
.kind(default_button_style)
|
|
.into_default(),
|
|
)
|
|
.and("Set Default to Outline".into_checkbox(default_is_outline))
|
|
.into_columns(),
|
|
)
|
|
.into_rows()
|
|
.centered()
|
|
.run()
|
|
}
|