pub fn map<S, SF, F>(value: S, set_value: SF, func: F) -> impl Viewwhere
MapView<S, SF, F>: View,
Expand description
Maps state into local state.
For example:
#[derive(Debug, Default)]
struct MyState {
x: f32,
}
fn main() {
rui(state(MyState::default, |state, cx| {
vstack((
format!("value: {:?}", cx[state]).padding(Auto),
map(
cx[state].x * 0.01,
move |v, cx| cx[state].x = v * 100.0,
|s, _| knob(s).padding(Auto),
),
))
}));
}
Examples found in repository?
More examples
examples/knob.rs (lines 12-16)
8 9 10 11 12 13 14 15 16 17 18 19
fn main() {
rui(state(MyState::default, |state, cx| {
vstack((
format!("value: {:?}", cx[state]).padding(Auto),
map(
cx[state].x * 0.01,
move |v, cx| cx[state].x = v * 100.0,
|s, _| knob(s).padding(Auto),
),
))
}));
}