On 02/28/13 23:58, edgar wrote:
> Is it possible to send text typed into an Fl_Input box to another box without
> using
> a callback via an enter button?
Going to assume you meant not to have the word "without" in the above.
> I would like to have the user type an answer into an Input box and then hit
> the enter key on the
> keyboard.
Sure, just use set the callback() for the input widget to send whatever
the user typed to the other box. eg:
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Input.H>
#include <FL/Fl_Box.H>
//
// Demonstrate Fl_Input to use Enter key to trigger callback to change window's
title - erco 3/1/13
//
void ChangeTitle(Fl_Widget *w, void *data) {
Fl_Input *in = (Fl_Input*)w;
Fl_Window *win = (Fl_Window*)data;
win->label(in->value()); // send value of Fl_Input to
window's title
}
int main(int argc,char **argv) {
Fl_Window *win = new Fl_Window(300,100);
Fl_Input *in = new Fl_Input(140,10,150,25,"Type something:");
in->callback(ChangeTitle, (void*)win);
in->when(FL_WHEN_ENTER_KEY);
win->show();
return(Fl::run());
}
> Also, if I am wanting to loop this series of events, how would I go about this
> if the Input box and the other text box are dynamically allocated? Should they
> be destroyed and recreated with each iteration to avoid memory leaks?
No, just hide() and show() them as needed.
If these widgets are in a dialog, then just hide() and show() the dialog
window, and leave the widgets within allocated.
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk