callback(brwsr_cb);}
// more callback-related decls?
void brwsr_cb2();
static void brwsr_cb(Fl_Widget*,void *v) {
((Brwsr*)v)->brwsr_cb();
}
Subject: how can i declare & define Browser callback?
I haven't found any examples that use a subclassed Browser with .h & .cpp files.
#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(); }
On 6/18/21 10:18 AM, Dave Jordan wrote:
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 {
Brwsr(int x, int y, int w1, int w2, int h);void brwsr_cb(Fl_Widget*, void *v);
// set appearance properties
Brwsr *b = (Brwsr*) w;
if(b->value() > 0) {
Game *gm = (Game*) v;// unload app->cur.game// load Game* gm
// assign gm to app->cur.game
// etc...
}}
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkgeneral/38d85767-0516-f745-d4c2-ecd7077614e9%40seriss.com.
right, i did see examples in various places including your cheat page and the examples dir,
but again, no "MyBrowser.h" or the like was in evidence, so I wasn't sure about the decl.
struct Brwsr : Fl_Hold_Browser {
Brwsr(int x, int y, int w1, int w2, int h);void brwsr_cb(Fl_Widget*, void *v);};
Most of your example looks fine, but why are you using "struct" instead of "class" in the above?
Use class so you can use all the normal keywords to control method visibility such as
public: and protected: and private: and so it's clearly a class.
As soon as I wrap my head around all these other new C++ concepts I will go back and add appropriate access specifiers.For now there is little chance i will misapply my own functions/methods and i need to follow KISS.
--
You received this message because you are subscribed to the Google Groups "fltk.general" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkgeneral...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkgeneral/CAGFM6db4ZcTQkg3Q_2Och4sSJX0E6G_%2BQ492c6a4%3DncO89QFMw%40mail.gmail.com.
As soon as I wrap my head around all these other new C++ concepts I will go back and add appropriate access specifiers.For now there is little chance i will misapply my own functions/methods and i need to follow KISS.
--
You received this message because you are subscribed to the Google Groups "fltk.general" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkgeneral...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkgeneral/f9b4c020-1b0a-41ae-808f-d7146d871473n%40googlegroups.com.
I'm sure they will! Thank you for the refs!I never would have thought that Stroustrup's publications would discuss any libs except the C++ ones.