> I'm trying to process multiple buttons with one callback, so I I want to
> use user_data() to store the button's name / identifier
This is one way to handle this, but there is another possibility:
> Here is my example code:
> |
> #include<FL/Fl.H>
> #include<FL/Fl_Window.H>
> #include<FL/Fl_Double_Window.H>
> #include<FL/Fl_Button.H>
>
> #include<stdio.h>
> #include<iostream>
< snipped >
Fl_Button*btn1; // Make button definitions visible for callback
Fl_Button*btn2;
> /* callback for button clicks */
> voidbuttonCallback (Fl_Widget*widget,void*data)
> {
> Fl_Button*btn =static_cast<Fl_Button*>(widget);
if (btn==btn1) cout << "Button 1" << endl;
else if (btn==btn2) cout << "Button 2" << endl;
// Identify Button by comparison with defined buttons
> }
> /* main program */
> intmain (intargc,char**argv)
> {
> sStruct*s =newsStruct;
>
> strcpy(s->s1,"Struct string 1");
> strcpy(s->s2,"Struct string 2");
>
> Fl_Window*win =newFl_Window(100,100,150,100);
> win->label("FLTK user_data test");
>
> Fl_Button*btn1 =newFl_Button(25,25,100,28,"Button1");
btn1 =newFl_Button(25,25,100,28,"Button1");
// Be aware not to lokal redefine name of button