mirror of
https://github.com/danbulant/cushy
synced 2026-06-15 04:21:06 +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.
32 lines
1.1 KiB
Rust
32 lines
1.1 KiB
Rust
use cushy::value::{Dynamic, Source};
|
|
use cushy::widget::MakeWidget;
|
|
use cushy::widgets::input::InputValue;
|
|
use cushy::widgets::slider::Slidable;
|
|
use cushy::widgets::Custom;
|
|
use cushy::Run;
|
|
use figures::units::Lp;
|
|
|
|
fn main() -> cushy::Result {
|
|
let allow_blur = Dynamic::new(true);
|
|
"Input Field"
|
|
.and(Dynamic::<String>::default().into_input())
|
|
.and("Range Slider")
|
|
.and(Dynamic::<u8>::default().slider_between(0_u8, 100_u8))
|
|
.and("Range Slider")
|
|
.and(Dynamic::new(10..=30).slider_between(0_u8, 100_u8))
|
|
.and("Allow Custom Widget to Lose Focus".into_checkbox(allow_blur.clone()))
|
|
.and(
|
|
Custom::empty()
|
|
.on_accept_focus(|context| context.enabled())
|
|
.on_redraw(|context| {
|
|
context.fill(context.theme().secondary.color);
|
|
if context.focused(true) {
|
|
context.draw_focus_ring();
|
|
}
|
|
})
|
|
.on_allow_blur(move |_| allow_blur.get())
|
|
.height(Lp::inches(1)),
|
|
)
|
|
.into_rows()
|
|
.run()
|
|
}
|