On 4/30/26 23:36 Jackk Sonn wrote:
> 'm trying to create a simple GUI where typing text into an Fl_Input
> and clicking an Fl_Button updates an Fl_Output field.I am struggling
> to pass the input widget pointer to the button's callback function to
> retrieve the value. I know callback(callback_func, data) allows
> passing void*, but I am not sure of the cleanest way to pass multiple
> widgets (the input to read from, and the output to write to) into one
> callback without using global variables.What is the recommended way to
> handle this in modern FLTK 1.3/1.4?
This is not exactly what you're asking for, but here's what you would
usually do: you don't need to use a button. Instead you attach the
callback directly to the input widget. Depending on the when() condition
you use each character or the full input (after losing the focus) could
be mirrored to the output widget. Possible code (untested):
void my_callback(Fl_Widget *w, void *v) {
Fl_Input *in = (Fl_Input *)w;
Fl_Output *o = (Fl_Output *)v;
o->value(in->value());
}
auto input = new Fl_Input( ... );
auto output = new Fl_Output( ... );
input->callback(my_callback, (void *)output);
As you can see in the code of the callback, you can use both arguments.
The first is the widget that caused the callback, the second is the
argument of the callback assignment.
> Should I use a struct to pack the widgets, or is there a better
> design pattern?
If you really want to use a button, then a struct with both pointers
would be a good choice (the "classic C++" decision).
Otherwise you may want to explore the more modern way of a lambda
expression, but if you need help with that, someone else may chime in...
> Thanks!
Welcome. And welcome to the world of FLTK!