Subject: how can i declare &
define Browser callback?
I haven't found any examples that use a subclassed
Browser with .h & .cpp files.
It sounds like you're looking for an example that
subclasses Fl_Hold_Browser
and uses callbacks, so an example of that might be:
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Hold_Browser.H>
// Demonstrate subclassing Fl_Hold_Browser and using callback -erco 6/18/21
class MyBrowser : public Fl_Hold_Browser {
void MyCallback2(Fl_Widget *w) {
void *i = selection();
if ( i ) printf("item selected is '%s'..\n", item_text(i));
}
static void MyCallback(Fl_Widget *w, void *data) {
MyBrowser *brow = static_cast<MyBrowser*>(data);
brow->MyCallback2(w);
}
public:
MyBrowser(int X,int Y,int W,int H) : Fl_Hold_Browser(X,Y,W,H) {
when(FL_WHEN_CHANGED);
callback(MyCallback, (void*)this);
}
};
int main() {
Fl_Window win(300,500);
MyBrowser brow(10,10,300-20,500-20);
brow.add("aaa"); brow.add("bbb"); brow.add("ccc");
win.show();
return Fl::run();
}
Also, my FLTK cheat page
has a few examples that subclass Fl_Browser, so to see those
you can search that page for 'public Fl_Browser' and find
those examples too.
Comments are owned by the poster. All other content is copyright 1998-2025 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.