From 243400ee8ec460c40429b12a006d62a6a9bced04 Mon Sep 17 00:00:00 2001 From: griffi-gh Date: Thu, 21 Mar 2024 19:43:53 +0100 Subject: [PATCH] compute signal in the fn body --- hui-examples/examples/ui_test_6.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/hui-examples/examples/ui_test_6.rs b/hui-examples/examples/ui_test_6.rs index ad51855..5252fd9 100644 --- a/hui-examples/examples/ui_test_6.rs +++ b/hui-examples/examples/ui_test_6.rs @@ -15,7 +15,7 @@ use hui::{ }; enum CounterSignal { - ChangeValue(f32) + ChangeValue(u32) } impl UiSignal for CounterSignal {} @@ -47,7 +47,9 @@ ui_main!( Br.add_child(ui); Slider::new(*counter as f32 / 100.) .with_size(size!(66%, 20)) - .on_change(CounterSignal::ChangeValue) + .on_change(|x| { + CounterSignal::ChangeValue((x * 100.).round() as u32) + }) .add_child(ui); Br.add_child(ui); for _ in 0..*counter { @@ -59,9 +61,7 @@ ui_main!( .add_root(ui, size); ui.process_signals(|sig| match sig { - CounterSignal::ChangeValue(v) => { - *counter = (v * 100.).round() as usize; - } + CounterSignal::ChangeValue(v) => *counter = v, }); } );