I wrote a toy FLTK2 app  (source attached) with a scrolled packed list
of buttons that delete themselves when clicked.  I found I had to call
redraw() on  the scrollgroup after removing the  button, otherwise the
bottom button wasn't erased even  though the list had shrunk and there
wasn't anything  there any more.   Is this a  bug or am I  expected to
explicitly redraw() the scrollgroup?

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-dev mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-dev

Reply via email to