fn redraw(&mut self) {
        for ch in self.choosers.iter() {
            self.win.remove(ch.get_win());
        }
        self.win.clear();
        let height = (3 + self.choosers.len() as i32) * GRADIENT_ROW_HEIGHT;
        self.win.set_size(COLOR_PANE_WIDTH, height);
        self.win.begin();

        let _ = Frame::default()
            .with_label("Color Map")
            .with_pos(0, 0)
            .with_size(COLOR_PANE_WIDTH, GRADIENT_ROW_HEIGHT);

        for (n, ch) in self.choosers.iter_mut().enumerate() {
            let ypos = (1 + n as i32) * GRADIENT_ROW_HEIGHT;
            let mut insert_butt = Button::default()
                .with_label("@+")
                .with_size(GRADIENT_BUTTON_WIDTH, GRADIENT_ROW_HEIGHT)
                .with_pos(0, ypos);
            insert_butt.set_tooltip("insert gradient before this one");
            self.win.add(ch.get_win());
            ch.set_pos(GRADIENT_BUTTON_WIDTH, ypos);
            //ch.show();
            let mut remove_butt = Button::default()
                .with_label("x")
                .with_size(GRADIENT_BUTTON_WIDTH, GRADIENT_ROW_HEIGHT)
                .with_pos(GRADIENT_BUTTON_WIDTH + GRADIENT_ROW_WIDTH, ypos);
            remove_butt.set_tooltip("remove this gradient");

            insert_butt.set_callback({
                let me = self.me.as_ref().unwrap().clone();
                move |_| {
                    me.borrow_mut().insert(n);
                }
            });

            remove_butt.set_callback({
                let me = self.me.as_ref().unwrap().clone();
                move |_| {
                    me.borrow_mut().remove(n);
                }
            });
        }

        let tail_w_ypos = (1 + self.choosers.len() as i32) * GRADIENT_ROW_HEIGHT;
        let tail_label_w = (2 * GRADIENT_BUTTON_WIDTH) + GRADIENT_STEPS_WIDTH;
        //~ let tail_w = DoubleWindow::default()
        //~ .with_size(COLOR_PANE_WIDTH, 2*GRADIENT_ROW_HEIGHT)
        //~ .with_pos(0, tail_w_ypos);
        let mut append_butt = Button::default()
            .with_label("@+")
            .with_pos(0, tail_w_ypos)
            .with_size(2 * GRADIENT_BUTTON_WIDTH, GRADIENT_ROW_HEIGHT);
        let _ = Frame::default()
            .with_label("append gradient")
            .with_pos(2 * GRADIENT_BUTTON_WIDTH, tail_w_ypos)
            .with_size(tail_label_w, GRADIENT_ROW_HEIGHT);
        let _ = Frame::default()
            .with_label("default color")
            .with_pos(0, tail_w_ypos + GRADIENT_ROW_HEIGHT)
            .with_size(tail_label_w, GRADIENT_ROW_HEIGHT);
        let mut default_select = Button::default()
            .with_pos(tail_label_w, tail_w_ypos + GRADIENT_ROW_HEIGHT)
            .with_size(2 * GRADIENT_BUTTON_WIDTH, GRADIENT_ROW_HEIGHT);
        default_select.set_color(rgb_to_fltk(self.default_color));
        default_select.set_tooltip("set default color");
        //~ tail_w.end();

        self.win.end();
        self.win.show();

        for ch in self.choosers.iter_mut() {
            ch.show();
        }

        append_butt.set_callback({
            let me = self.me.as_ref().unwrap().clone();
            move |_| {
                me.borrow_mut().append();
            }
        });

        default_select.set_callback({
            let me = self.me.as_ref().unwrap().clone();
            move |b| {
                let old_c = me.borrow().default_color;
                if let Some(c) = pick_color(old_c) {
                    me.borrow_mut().default_color = c;
                    b.set_color(rgb_to_fltk(c));
                    b.redraw();
                }
            }
        });
        default_select.handle({
            let drag_color = self.drag_color.clone();
            let me = self.me.as_ref().unwrap().clone();
            move |b, evt| match evt {
                Event::Enter => {
                    if let Some(c) = drag_color.get() {
                        b.set_color(rgb_to_fltk(c));
                        me.borrow_mut().default_color = c;
                        b.redraw();
                        true
                    } else {
                        false
                    }
                }
                Event::Released => {
                    drag_color.set(Some(me.borrow().default_color));
                    add_timeout3(0.0, {
                        let drag_color = drag_color.clone();
                        move |_| {
                            drag_color.set(None);
                        }
                    });
                    true
                }
                _ => false,
            }
        });
    }
// Every time a gradient chooser is added or removed, the window
// needs to be resized/redrawn.
Every time a gradient chooser is added or removed, the window
needs to be resized/redrawn.
Every time a gradient chooser is added or removed the window needs to be resized / redrawn .
fn redraw(&mut self) {
        for ch in self.choosers.iter() {
            self.win.remove(ch.get_win());
        }
        self.win.clear();
        let height = (3 + self.choosers.len() as i32) * GRADIENT_ROW_HEIGHT;
        self.win.set_size(COLOR_PANE_WIDTH, height);
        self.win.begin();
        let _ = Frame::default()
            .with_label("Color Map")
            .with_pos(0, 0)
            .with_size(COLOR_PANE_WIDTH, GRADIENT_ROW_HEIGHT);
        for (n, ch) in self.choosers.iter_mut().enumerate() {
            let ypos = (1 + n as i32) * GRADIENT_ROW_HEIGHT;
            let mut insert_butt = Button::default()
                .with_label("@+")
                .with_size(GRADIENT_BUTTON_WIDTH, GRADIENT_ROW_HEIGHT)
                .with_pos(0, ypos);
            insert_butt.set_tooltip("insert gradient before this one");
            self.win.add(ch.get_win());
            ch.set_pos(GRADIENT_BUTTON_WIDTH, ypos);
            //ch.show();
            let mut remove_butt = Button::default()
                .with_label("x")
                .with_size(GRADIENT_BUTTON_WIDTH, GRADIENT_ROW_HEIGHT)
                .with_pos(GRADIENT_BUTTON_WIDTH + GRADIENT_ROW_WIDTH, ypos);
            remove_butt.set_tooltip("remove this gradient");
            insert_butt.set_callback({
                let me = self.me.as_ref().unwrap().clone();
                move |_| {
                    me.borrow_mut().insert(n);
                }
            });
            remove_butt.set_callback({
                let me = self.me.as_ref().unwrap().clone();
                move |_| {
                    me.borrow_mut().remove(n);
                }
            });
        }
        let tail_w_ypos = (1 + self.choosers.len() as i32) * GRADIENT_ROW_HEIGHT;
        let tail_label_w = (2 * GRADIENT_BUTTON_WIDTH) + GRADIENT_STEPS_WIDTH;
        //~ let tail_w = DoubleWindow::default()
        //~ .with_size(COLOR_PANE_WIDTH, 2*GRADIENT_ROW_HEIGHT)
        //~ .with_pos(0, tail_w_ypos);
        let mut append_butt = Button::default()
            .with_label("@+")
            .with_pos(0, tail_w_ypos)
            .with_size(2 * GRADIENT_BUTTON_WIDTH, GRADIENT_ROW_HEIGHT);
        let _ = Frame::default()
            .with_label("append gradient")
            .with_pos(2 * GRADIENT_BUTTON_WIDTH, tail_w_ypos)
            .with_size(tail_label_w, GRADIENT_ROW_HEIGHT);
        let _ = Frame::default()
            .with_label("default color")
            .with_pos(0, tail_w_ypos + GRADIENT_ROW_HEIGHT)
            .with_size(tail_label_w, GRADIENT_ROW_HEIGHT);
        let mut default_select = Button::default()
            .with_pos(tail_label_w, tail_w_ypos + GRADIENT_ROW_HEIGHT)
            .with_size(2 * GRADIENT_BUTTON_WIDTH, GRADIENT_ROW_HEIGHT);
        default_select.set_color(rgb_to_fltk(self.default_color));
        default_select.set_tooltip("set default color");
        //~ tail_w.end();
        self.win.end();
        self.win.show();
        for ch in self.choosers.iter_mut() {
            ch.show();
        }
        append_butt.set_callback({
            let me = self.me.as_ref().unwrap().clone();
            move |_| {
                me.borrow_mut().append();
            }
        });
        default_select.set_callback({
            let me = self.me.as_ref().unwrap().clone();
            move |b| {
                let old_c = me.borrow().default_color;
                if let Some(c) = pick_color(old_c) {
                    me.borrow_mut().default_color = c;
                    b.set_color(rgb_to_fltk(c));
                    b.redraw();
                }
            }
        });
        default_select.handle({
            let drag_color = self.drag_color.clone();
            let me = self.me.as_ref().unwrap().clone();
            move |b, evt| match evt {
                Event::Enter => {
                    if let Some(c) = drag_color.get() {
                        b.set_color(rgb_to_fltk(c));
                        me.borrow_mut().default_color = c;
                        b.redraw();
                        true
                    } else {
                        false
                    }
                }
                Event::Released => {
                    drag_color.set(Some(me.borrow().default_color));
                    add_timeout3(0.0, {
                        let drag_color = drag_color.clone();
                        move |_| {
                            drag_color.set(None);
                        }
                    });
                    true
                }
                _ => false,
            }
        });
    }
fn redraw ( & mut self ) { for ch in self . choosers . iter ( ) { self . win . remove ( ch . get_win ( ) ) ; } self . win . clear ( ) ; let height = ( 3 + self . choosers . len ( ) as i32 ) * GRADIENT_ROW_HEIGHT ; self . win . set_size ( COLOR_PANE_WIDTH , height ) ; self . win . begin ( ) ; let _ = Frame :: default ( ) . with_label ( " " ) . with_pos ( 0 , 0 ) . with_size ( COLOR_PANE_WIDTH , GRADIENT_ROW_HEIGHT ) ; for ( n , ch ) in self . choosers . iter_mut ( ) . enumerate ( ) { let ypos = ( 1 + n as i32 ) * GRADIENT_ROW_HEIGHT ; let mut insert_butt = Button :: default ( ) . with_label ( " " ) . with_size ( GRADIENT_BUTTON_WIDTH , GRADIENT_ROW_HEIGHT ) . with_pos ( 0 , ypos ) ; insert_butt . set_tooltip ( " " ) ; self . win . add ( ch . get_win ( ) ) ; ch . set_pos ( GRADIENT_BUTTON_WIDTH , ypos ) ; //ch.show(); let mut remove_butt = Button :: default ( ) . with_label ( " " ) . with_size ( GRADIENT_BUTTON_WIDTH , GRADIENT_ROW_HEIGHT ) . with_pos ( GRADIENT_BUTTON_WIDTH + GRADIENT_ROW_WIDTH , ypos ) ; remove_butt . set_tooltip ( " " ) ; insert_butt . set_callback ( { let me = self . me . as_ref ( ) . unwrap ( ) . clone ( ) ; move | _ | { me . borrow_mut ( ) . insert ( n ) ; } } ) ; remove_butt . set_callback ( { let me = self . me . as_ref ( ) . unwrap ( ) . clone ( ) ; move | _ | { me . borrow_mut ( ) . remove ( n ) ; } } ) ; } let tail_w_ypos = ( 1 + self . choosers . len ( ) as i32 ) * GRADIENT_ROW_HEIGHT ; let tail_label_w = ( 2 * GRADIENT_BUTTON_WIDTH ) + GRADIENT_STEPS_WIDTH ; //~ let tail_w = DoubleWindow::default() //~ .with_size(COLOR_PANE_WIDTH, 2*GRADIENT_ROW_HEIGHT) //~ .with_pos(0, tail_w_ypos); let mut append_butt = Button :: default ( ) . with_label ( " " ) . with_pos ( 0 , tail_w_ypos ) . with_size ( 2 * GRADIENT_BUTTON_WIDTH , GRADIENT_ROW_HEIGHT ) ; let _ = Frame :: default ( ) . with_label ( " " ) . with_pos ( 2 * GRADIENT_BUTTON_WIDTH , tail_w_ypos ) . with_size ( tail_label_w , GRADIENT_ROW_HEIGHT ) ; let _ = Frame :: default ( ) . with_label ( " " ) . with_pos ( 0 , tail_w_ypos + GRADIENT_ROW_HEIGHT ) . with_size ( tail_label_w , GRADIENT_ROW_HEIGHT ) ; let mut default_select = Button :: default ( ) . with_pos ( tail_label_w , tail_w_ypos + GRADIENT_ROW_HEIGHT ) . with_size ( 2 * GRADIENT_BUTTON_WIDTH , GRADIENT_ROW_HEIGHT ) ; default_select . set_color ( rgb_to_fltk ( self . default_color ) ) ; default_select . set_tooltip ( " " ) ; //~ tail_w.end(); self . win . end ( ) ; self . win . show ( ) ; for ch in self . choosers . iter_mut ( ) { ch . show ( ) ; } append_butt . set_callback ( { let me = self . me . as_ref ( ) . unwrap ( ) . clone ( ) ; move | _ | { me . borrow_mut ( ) . append ( ) ; } } ) ; default_select . set_callback ( { let me = self . me . as_ref ( ) . unwrap ( ) . clone ( ) ; move | b | { let old_c = me . borrow ( ) . default_color ; if let Some ( c ) = pick_color ( old_c ) { me . borrow_mut ( ) . default_color = c ; b . set_color ( rgb_to_fltk ( c ) ) ; b . redraw ( ) ; } } } ) ; default_select . handle ( { let drag_color = self . drag_color . clone ( ) ; let me = self . me . as_ref ( ) . unwrap ( ) . clone ( ) ; move | b , evt | match evt { Event :: Enter => { if let Some ( c ) = drag_color . get ( ) { b . set_color ( rgb_to_fltk ( c ) ) ; me . borrow_mut ( ) . default_color = c ; b . redraw ( ) ; true } else { false } } Event :: Released => { drag_color . set ( Some ( me . borrow ( ) . default_color ) ) ; add_timeout3 ( 0.0 , { let drag_color = drag_color . clone ( ) ; move | _ | { drag_color . set ( None ) ; } } ) ; true } _ => false , } } ) ; }
Every time a gradient chooser is added or removed, the window
needs to be resized/redrawn.
Every time a gradient chooser is added or removed the window needs to be resized / redrawn .
&mut self
&mut self