FLTK is a callback based GUI system but there are times that I need a user to input an acceptable answer into a Fl_Input widget before a function can return.
This seems to require updating the widget, collecting the answer then returning the answer if it is valid.
So, in essence let's say I have a function called int get_int(Fl_Input i). This function needs to continually update the Fl_Input, validate the contents by attempting to cast the value() to an int, clear Fl_Input if the validation fails, and finally return the cast int from the function. This validation should happen on the press of enter key. (I plan to also have functions to return cast strings and floats but they'll work the same way)
This is actually part of a scripting system and FLTK is the GUI. The embedded language is waiting to get a proper int from my Fl_Input but FLTK can't update and process events because it has not completed the main loop. I can't easily do this via normal FLTK callbacks it seems because they must return void and I'll have many types of casting and validation on my single input depending on the context of the object reading from it.
Thanks to anyone who can help me!
EDIT here is some rough example code of what I need.
Embeddable Common Lisp needs to wrap the get_int function but I'm not sure how to update all widgets with an interrupt and also break the loop with a callback which can't affect the loop directly. (boolean flag maybe?)
#include <iostream>
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <Fl/Fl_Input.H>
#include <Fl/Fl_Button.H>
#include <stdexcept>
int get_int(Fl_Input* i)
{
int temp = 0;
while(True)
{
// not sure how to update here
// at this point, button and field need to update
// also somehow validate needs to be done on Enter button press
// but callbacks can't interact with this part of the code directly
// to validate and end the loop here
try
{
temp = std::stoi(i->value());
}
catch(...)
{
std::cout << "Invalid conversion to int" << i->value() << std::endl;
i->value("");
}
}
return temp;
}
void field_callback(Fl_Widget * w, void *d)
{
// This callback simulates Embeddable Common Lisp calling wrapped get_int
// Once a number is valid, it is converted and passed to back to Lisp
int something = get_int((Fl_Input*)w);
std::cout << something << std::endl;
}
int main()
{
Fl_Window *w = new Fl_Window(200, 32);
Fl_Input *i = new Fl_Input(0, 0, 128, 24, "");
Fl_Button *b = new Fl_Button(128, 0, 32, 24, "Simulate Request");
b->callback(field_callback);
w->show();
return(Fl::run());
}