Hi,
I'm really struggling to understand how to use the Edit widget for more than a very simple input box. What I'd like to do is catch extra key events from the widget so I can tell what a user may have tried to do with the input.
I thought I might be able to get this information directly from the return data of the widget, but it turns out it only tells me if it's 'in_edit' or not. This means I can tell that the widget received *some* input, but not what it was! The two keys I am particularly interested in are ESCAPE and ENTER/RETURN, for the following purposes:
ESCAPE: The user probably wanted to cancel (delete) the current line of input.
ENTER: The user probably wanted us to do something with the text, like submit it to the network or whatnot.
Examples ----
The following code is what I have achieved so far. Can we make it better?
if (Edit(20, vec2(0, 20), "IOEdit", &input)) {
cout << "Yes the box had input" << endl;
} else {
cout << "We lost focus...somehow..or no text was input?" << endl;
}
I thought that maybe I had to go and catch the keypresses myself aside the Edit box, like below, but the call to CheckEvent() always seemed to cancel out any input checking the Edit was doing. I concluded that this meant I'd have to update the input string myself anyway, leading to a superfluous Edit box to begin with?
if (Edit(20, vec2(0, 20), "IOEdit", &input)) {
cout << "Yes the box had input" << endl;
} else {
cout << "We lost focus...somehow" << endl;
}
auto event = CheckEvent();
// use event here? Why did the Edit stop updating?
So at this point I'm a little stuck. Can anyone point me in the right direction? Do I have to write my own Edit widget? Do I have to resort to submission via
button?
Here's an example of the kind of thing I'm looking for:
auto edit = Edit(20, vec2(0, 20), "IOEdit", &input);
if(edit.changed) {
if (edit.key == KESCAPE) {
input.clear();
} else if (edit.key == KRETURN) {
cout << "Sending to network... [" << input << "]" << endl;
} else {
cout << "Something else changed (probably some text was input)" << endl;
}
} else {
// We could check something like edit.focus_lost, etc
cout << "There was no change" << endl;
}
Any ideas?
Thanks in advance,
Joe
--
:wq!