(This didn't get answered on  fltk-dev, perhaps this is a better place
to ask.)

I'd like  to know  if it's a  bug that  the attached program  needs to
explicitly  call  redraw() in  the  callback.   It's  just a  scrolled
vertical list of buttons that  delete themselves when clicked.  If the
button callback  does not  call redraw() on  the ScrollGroup  then the
image  of the bottom  button remains  even though  there is  no widget
there any more.  Bug or feature?

Regards, 

Jeremy Henty 
#include <stdio.h>

#include <fltk/run.h>

#include <fltk/Widget.h>
#include <fltk/Button.h>
#include <fltk/Window.h>
#include <fltk/ScrollGroup.h>
#include <fltk/PackedGroup.h>

static void button_callback(fltk::Widget *widget, void *vp);

class Callback_Data
{
private:
  friend void button_callback(fltk::Widget *widget, void *vp);
  fltk::ScrollGroup *scroll;
  fltk::PackedGroup *pack;
public:
  Callback_Data(fltk::ScrollGroup *scroll, fltk::PackedGroup *pack) :
    scroll(scroll), pack(pack) { }
};

static void button_callback(fltk::Widget *widget, void *vp)
{
  Callback_Data *data = (Callback_Data *)vp;
  data->pack->remove(widget);
  data->scroll->redraw();
  delete data;
  delete widget;
}

int main()
{
  fltk::Window *window = new fltk::Window(100,100,"Scroller");
  window->begin();
  fltk::ScrollGroup *scroll = new fltk::ScrollGroup(0,0,100,100);
  scroll->type(fltk::ScrollGroup::VERTICAL);
  scroll->begin();
  fltk::PackedGroup *pack = new fltk::PackedGroup(0,0,100,100);
  pack->begin();
  char label[20];
  for (int ii = 0; ii < 10; ii++) {
    sprintf(label, "Button: %2d", ii);
    fltk::Button *button = new fltk::Button(0,0,100,25);
    button->copy_label(label);
    button->callback(button_callback);
    button->user_data(new Callback_Data(scroll, pack));
  }
  pack->end();
  scroll->end();
  window->resizable(scroll);
  window->end();
  window->size_range(100,100);
  window->show();
  fltk::run();
}
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to