// Create a new `GradientChooser` that initially displays parameters
// for the supplied `Gradient`.
Create a new `GradientChooser` that initially displays parameters
for the supplied `Gradient`.
Create a new ` GradientChooser ` that initially displays parameters for the supplied ` Gradient ` .
fn new(g: Gradient, drag_color: Rc<Cell<Option<RGB>>>) -> GradientChooser {
        let w = DoubleWindow::default().with_size(GRADIENT_ROW_WIDTH, GRADIENT_ROW_HEIGHT);
        let mut sbutt = Button::default()
            .with_size(GRADIENT_BUTTON_WIDTH, GRADIENT_ROW_HEIGHT)
            .with_pos(0, 0);
        sbutt.set_tooltip("set start color");
        sbutt.set_color(rgb_to_fltk(g.start));
        let mut ebutt = Button::default()
            .with_size(GRADIENT_BUTTON_WIDTH, GRADIENT_ROW_HEIGHT)
            .with_pos(GRADIENT_BUTTON_WIDTH + GRADIENT_STEPS_WIDTH, 0);
        ebutt.set_tooltip("set end color");
        ebutt.set_color(rgb_to_fltk(g.end));
        let mut stepsi = IntInput::default()
            .with_size(GRADIENT_STEPS_WIDTH, GRADIENT_ROW_HEIGHT)
            .with_pos(GRADIENT_BUTTON_WIDTH, 0);
        stepsi.set_tooltip("number of steps");
        stepsi.set_value(&format!("{}", g.steps));
        w.end();
        let sc_cell = Rc::new(Cell::new(g.start));
        let ec_cell = Rc::new(Cell::new(g.end));
        let sn_cell = Rc::new(Cell::new(g.steps));
        sbutt.set_callback({
            let sc_cell = sc_cell.clone();
            move |b| {
                if let Some(c) = pick_color(sc_cell.get()) {
                    b.set_color(rgb_to_fltk(c));
                    b.redraw();
                    sc_cell.set(c);
                }
            }
        });
        ebutt.set_callback({
            let ec_cell = ec_cell.clone();
            move |b| {
                if let Some(c) = pick_color(ec_cell.get()) {
                    b.set_color(rgb_to_fltk(c));
                    b.redraw();
                    ec_cell.set(c);
                }
            }
        });
        stepsi.set_callback({
            let sn_cell = sn_cell.clone();
            move |i| {
                if let Ok(n) = i.value().parse::<usize>() {
                    sn_cell.set(n);
                } else {
                    i.set_value(&format!("{}", sn_cell.get()));
                }
            }
        });
        sbutt.handle({
            let sc_cell = sc_cell.clone();
            let drag_color = drag_color.clone();
            move |b, evt| match evt {
                Event::Enter => {
                    if let Some(c) = drag_color.get() {
                        b.set_color(rgb_to_fltk(c));
                        b.redraw();
                        sc_cell.set(c);
                        true
                    } else {
                        false
                    }
                }
                Event::Released => {
                    drag_color.set(Some(sc_cell.get()));
                    add_timeout3(0.0, {
                        let drag_color = drag_color.clone();
                        move |_| {
                            drag_color.set(None);
                        }
                    });
                    true
                }
                _ => false,
            }
        });
        ebutt.handle({
            let ec_cell = ec_cell.clone();
            let drag_color = drag_color;
            move |b, evt| match evt {
                Event::Enter => {
                    if let Some(c) = drag_color.get() {
                        b.set_color(rgb_to_fltk(c));
                        b.redraw();
                        ec_cell.set(c);
                        true
                    } else {
                        false
                    }
                }
                Event::Released => {
                    drag_color.set(Some(ec_cell.get()));
                    add_timeout3(0.0, {
                        let drag_color = drag_color.clone();
                        move |_| {
                            drag_color.set(None);
                        }
                    });
                    true
                }
                _ => false,
            }
        });
        GradientChooser {
            win: w,
            start_color: sc_cell,
            end_color: ec_cell,
            steps_n: sn_cell,
        }
    }
fn new ( g : Gradient , drag_color : Rc < Cell < Option < RGB > > > ) -> GradientChooser { let w = DoubleWindow :: default ( ) . with_size ( GRADIENT_ROW_WIDTH , GRADIENT_ROW_HEIGHT ) ; let mut sbutt = Button :: default ( ) . with_size ( GRADIENT_BUTTON_WIDTH , GRADIENT_ROW_HEIGHT ) . with_pos ( 0 , 0 ) ; sbutt . set_tooltip ( " " ) ; sbutt . set_color ( rgb_to_fltk ( g . start ) ) ; let mut ebutt = Button :: default ( ) . with_size ( GRADIENT_BUTTON_WIDTH , GRADIENT_ROW_HEIGHT ) . with_pos ( GRADIENT_BUTTON_WIDTH + GRADIENT_STEPS_WIDTH , 0 ) ; ebutt . set_tooltip ( " " ) ; ebutt . set_color ( rgb_to_fltk ( g . end ) ) ; let mut stepsi = IntInput :: default ( ) . with_size ( GRADIENT_STEPS_WIDTH , GRADIENT_ROW_HEIGHT ) . with_pos ( GRADIENT_BUTTON_WIDTH , 0 ) ; stepsi . set_tooltip ( " " ) ; stepsi . set_value ( & format ! ( " " g steps ) ) ; w . end ( ) ; let sc_cell = Rc :: new ( Cell :: new ( g . start ) ) ; let ec_cell = Rc :: new ( Cell :: new ( g . end ) ) ; let sn_cell = Rc :: new ( Cell :: new ( g . steps ) ) ; sbutt . set_callback ( { let sc_cell = sc_cell . clone ( ) ; move | b | { if let Some ( c ) = pick_color ( sc_cell . get ( ) ) { b . set_color ( rgb_to_fltk ( c ) ) ; b . redraw ( ) ; sc_cell . set ( c ) ; } } } ) ; ebutt . set_callback ( { let ec_cell = ec_cell . clone ( ) ; move | b | { if let Some ( c ) = pick_color ( ec_cell . get ( ) ) { b . set_color ( rgb_to_fltk ( c ) ) ; b . redraw ( ) ; ec_cell . set ( c ) ; } } } ) ; stepsi . set_callback ( { let sn_cell = sn_cell . clone ( ) ; move | i | { if let Ok ( n ) = i . value ( ) . parse :: < usize > ( ) { sn_cell . set ( n ) ; } else { i . set_value ( & format ! ( " " sn_cell get ( ) ) ) ; } } } ) ; sbutt . handle ( { let sc_cell = sc_cell . clone ( ) ; let drag_color = drag_color . clone ( ) ; move | b , evt | match evt { Event :: Enter => { if let Some ( c ) = drag_color . get ( ) { b . set_color ( rgb_to_fltk ( c ) ) ; b . redraw ( ) ; sc_cell . set ( c ) ; true } else { false } } Event :: Released => { drag_color . set ( Some ( sc_cell . get ( ) ) ) ; add_timeout3 ( 0.0 , { let drag_color = drag_color . clone ( ) ; move | _ | { drag_color . set ( None ) ; } } ) ; true } _ => false , } } ) ; ebutt . handle ( { let ec_cell = ec_cell . clone ( ) ; let drag_color = drag_color ; move | b , evt | match evt { Event :: Enter => { if let Some ( c ) = drag_color . get ( ) { b . set_color ( rgb_to_fltk ( c ) ) ; b . redraw ( ) ; ec_cell . set ( c ) ; true } else { false } } Event :: Released => { drag_color . set ( Some ( ec_cell . get ( ) ) ) ; add_timeout3 ( 0.0 , { let drag_color = drag_color . clone ( ) ; move | _ | { drag_color . set ( None ) ; } } ) ; true } _ => false , } } ) ; GradientChooser { win : w , start_color : sc_cell , end_color : ec_cell , steps_n : sn_cell , } }
Create a new `GradientChooser` that initially displays parameters
for the supplied `Gradient`.
Create a new ` GradientChooser ` that initially displays parameters for the supplied ` Gradient ` .
g
Gradient
drag_color
Rc<Cell<Option<RGB>>>