On 14.08.2016 10:08 Svets wrote:
> Is there any possible way to get the name of a widget.
>
> For example.
>
> |
> Fl_Choice*ch =newFl_Choice(10,10,100,40); //no label.
>
>
> cout <<"The name of the Fl_Choice widget is: "<< ch->name()<<endl;
> |
>
>
> //clearly the above will not work. Is there any way of doing this or am
> I restricted to identifying the widget via it's x() and y() coordinates?
[Please read Ian's post as well]
If you want to use the label of your widgets to identify the widgets,
then you can just use the label. I think that's what your example code
implies. However, if you don't want your widget to have a visible label
you can still use one with
widget->label(FL_NO_LABEL, "my_choice");
<
http://www.fltk.org/doc-1.3/classFl__Widget.html#aa3afb86e13e921c17934cf2b1f6951b4>
See also:
<
http://www.fltk.org/doc-1.3/classFl__Widget.html#aa3afb86e13e921c17934cf2b1f6951b4>
<
http://www.fltk.org/doc-1.3/Enumerations_8H.html#ad5774781d33328b82990ff9e25dfd61b>
Hence you can set an invisible label to identify your widget. Does this
help?
Otherwise you might use the user_data() method to set a pointer to an
own structure so that it can be used for callbacks and/or to identify
your widget. Something like:
struct my_widget_data {
void *userdata_ptr;
int userdata_int;
const char *name; // used to identify a particular widget
}
Set the user_data() widget member to point to your struct and use one or
the other struct member in callbacks or to identify the widget, resp.