Function rui::map

source ·
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?
examples/slider.rs (lines 20-24)
18
19
20
21
22
23
24
25
26
fn main() {
    rui(state(MyState::default, |state_handle, cx| {
        map(
            cx[state_handle].value,
            move |v, cx| cx[state_handle].value = v,
            |s, _| my_slider(s),
        )
    }));
}
More examples
Hide additional 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),
            ),
        ))
    }));
}