// This function only exists to save typing in the implementation of
// `pick_color()`. There are three nearly-identical rows of widgets in the
// color picker window; this abstracts creating them.
This function only exists to save typing in the implementation of
`pick_color()`. There are three nearly-identical rows of widgets in the
color picker window; this abstracts creating them.
This function only exists to save typing in the implementation of ` pick_color () ` . There are three nearly - identical rows of widgets in the color picker window ; this abstracts creating them .
fn make_picker_row(
    ypos: i32,
    label: &'static str,
    initial_value: f64,
    mut prev: DoubleWindow,
    rvalue: Rc<Cell<RGB>>,
) -> (Frame, HorNiceSlider, ValueInput) {
    let lab = Frame::default()
        .with_label(label)
        .with_pos(0, ypos)
        .with_size(PICKER_LABEL_WIDTH, PICKER_ROW_HEIGHT);
    let mut slider = HorNiceSlider::default()
        .with_pos(PICKER_LABEL_WIDTH, ypos)
        .with_size(PICKER_SLIDER_WIDTH, PICKER_ROW_HEIGHT);
    slider.set_value(initial_value);
    let mut vinput = ValueInput::new(
        PICKER_LABEL_WIDTH + PICKER_SLIDER_WIDTH,
        ypos,
        PICKER_INPUT_WIDTH,
        PICKER_ROW_HEIGHT,
        None,
    );
    vinput.set_value(initial_value);
    slider.set_range(0.0, 255.0);
    vinput.set_bounds(0.0, 255.0);
    slider.set_step(1.0, 1);
    slider.set_callback({
        let rvalue = rvalue.clone();
        let mut vinput = vinput.clone();
        let mut prev = prev.clone();
        move |s| {
            let x = s.value();
            vinput.set_value(x);
            let mut rv = rvalue.get();
            match label {
                "R" => {
                    rv.set_r(x as f32);
                }
                "G" => {
                    rv.set_g(x as f32);
                }
                "B" => {
                    rv.set_b(x as f32);
                }
                s => {
                    panic!("ui::make_picker_row(): bad picker row label: {}", s);
                }
            }
            rvalue.set(rv);
            let c = rgb_to_fltk(rv);
            prev.set_color(c);
            prev.redraw();
        }
    });
    vinput.set_callback({
        let mut slider = slider.clone();
        move |v| {
            let x = v.value();
            slider.set_value(x);
            let mut rv = rvalue.get();
            match label {
                "R" => {
                    rv.set_r(x as f32);
                }
                "G" => {
                    rv.set_g(x as f32);
                }
                "B" => {
                    rv.set_b(x as f32);
                }
                s => {
                    panic!("ui::make_picker_row(): bad picker row label: {}", s);
                }
            }
            rvalue.set(rv);
            let c = rgb_to_fltk(rv);
            prev.set_color(c);
            prev.redraw();
        }
    });
    (lab, slider, vinput)
}
fn make_picker_row ( ypos : i32 , label : & ' static str , initial_value : f64 , mut prev : DoubleWindow , rvalue : Rc < Cell < RGB > > , ) -> ( Frame , HorNiceSlider , ValueInput ) { let lab = Frame :: default ( ) . with_label ( label ) . with_pos ( 0 , ypos ) . with_size ( PICKER_LABEL_WIDTH , PICKER_ROW_HEIGHT ) ; let mut slider = HorNiceSlider :: default ( ) . with_pos ( PICKER_LABEL_WIDTH , ypos ) . with_size ( PICKER_SLIDER_WIDTH , PICKER_ROW_HEIGHT ) ; slider . set_value ( initial_value ) ; let mut vinput = ValueInput :: new ( PICKER_LABEL_WIDTH + PICKER_SLIDER_WIDTH , ypos , PICKER_INPUT_WIDTH , PICKER_ROW_HEIGHT , None , ) ; vinput . set_value ( initial_value ) ; slider . set_range ( 0.0 , 255.0 ) ; vinput . set_bounds ( 0.0 , 255.0 ) ; slider . set_step ( 1.0 , 1 ) ; slider . set_callback ( { let rvalue = rvalue . clone ( ) ; let mut vinput = vinput . clone ( ) ; let mut prev = prev . clone ( ) ; move | s | { let x = s . value ( ) ; vinput . set_value ( x ) ; let mut rv = rvalue . get ( ) ; match label { " " => { rv . set_r ( x as f32 ) ; } " " => { rv . set_g ( x as f32 ) ; } " " => { rv . set_b ( x as f32 ) ; } s => { panic ! ( " " s ) ; } } rvalue . set ( rv ) ; let c = rgb_to_fltk ( rv ) ; prev . set_color ( c ) ; prev . redraw ( ) ; } } ) ; vinput . set_callback ( { let mut slider = slider . clone ( ) ; move | v | { let x = v . value ( ) ; slider . set_value ( x ) ; let mut rv = rvalue . get ( ) ; match label { " " => { rv . set_r ( x as f32 ) ; } " " => { rv . set_g ( x as f32 ) ; } " " => { rv . set_b ( x as f32 ) ; } s => { panic ! ( " " s ) ; } } rvalue . set ( rv ) ; let c = rgb_to_fltk ( rv ) ; prev . set_color ( c ) ; prev . redraw ( ) ; } } ) ; ( lab , slider , vinput ) }
This function only exists to save typing in the implementation of
`pick_color()`.
This function only exists to save typing in the implementation of ` pick_color () ` .
ypos
i32
label
&'static str
initial_value
f64
prev
DoubleWindow
rvalue
Rc<Cell<RGB>>