Receiving ESCAPE and ENTER from an Edit box

245 views
Skip to first unread message

Joe Eaves

unread,
Feb 1, 2016, 2:54:40 PM2/1/16
to flatuilib
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!

Wouter van Oortmerssen

unread,
Feb 1, 2016, 4:06:01 PM2/1/16
to Joe Eaves, Hak Matsuda, flatuilib
You're right, the current Edit widget is a black box. CheckEvent doesn't work because that applies to the current group, and Edit has its own group (and event handling).

A solution would be to replace the bool return value into something that is more informative on what happened, like one of Selected, Deselected, Deselected_Confirmed, and Deselected_Cancelled or so.

Alternatively, we could have allowed users to create their own group for an Edit widget, so additional events can be added.





--
You received this message because you are subscribed to the Google Groups "flatuilib" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flatuilib+...@googlegroups.com.
To post to this group, send email to flat...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flatuilib/727e207e-b99b-42c9-8db3-5ec227fea3d6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Joe Eaves

unread,
Feb 1, 2016, 5:04:50 PM2/1/16
to flatuilib
On Monday, 1 February 2016 21:06:01 UTC, Wouter van Oortmerssen wrote:
You're right, the current Edit widget is a black box. CheckEvent doesn't work because that applies to the current group, and Edit has its own group (and event handling).

Ok, it's not just me then!
 
A solution would be to replace the bool return value into something that is more informative on what happened, like one of Selected, Deselected, Deselected_Confirmed, and Deselected_Cancelled or so.

Alternatively, we could have allowed users to create their own group for an Edit widget, so additional events can be added.

I think I'm much more likely to get somewhere with the first idea. Things get stranger with this library though:

If I do this around ~530 in flatui.cpp, I get no output when I press ESCAPE:
// Handle text input events only after the rendering for the pass is
// finished.
auto x = input_.GetTextInputEvents();
if (x->size() > 0)
    // This never happens for ESCAPE, because it never gets put in the event array.
    std::cout << x->size() << std::endl;

// How can we expect HandleInputEvents to deal with a non-existent ESCAPE?
auto finished_input = persistent_.text_edit_.HandleInputEvents(x); //input_.GetTextInputEvents());
input_.ClearTextInputEvents();

 

Wouter van Oortmerssen

unread,
Feb 1, 2016, 8:31:50 PM2/1/16
to Joe Eaves, flatuilib
That's definitely strange. ESC should get recorded at line 242 of input.cpp (of FPLbase).

--
You received this message because you are subscribed to the Google Groups "flatuilib" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flatuilib+...@googlegroups.com.
To post to this group, send email to flat...@googlegroups.com.

Joe Eaves

unread,
Feb 2, 2016, 11:35:59 AM2/2/16
to flatuilib
Ok so I changed input.cpp to read like this at line 242:
        if (record_text_input_) {
          std::cout << "GOT KEY " << event.key.keysym.sym << std::endl;

Sure enough, the ESC registers and I see "GOT KEY 27" in my terminal!

So somewhere between the Input and the Edit, we lose the keypress.

Hak Matsuda

unread,
Feb 2, 2016, 3:32:03 PM2/2/16
to Joe Eaves, flatuilib
It looks like the escape is flushed as a part of CheckGamePadNavigation.
Anyway, I think it's a good idea for Event() to return an input status. Will update it.

void CheckGamePadNavigation() {
    // Update state.
    int dir = GetNavigationDirection();

    // If "back" is pressed, clear the current focus.
    if (BackPressed()) {
      CaptureInput(kNullHash, true); // Here, flushing the text input when the escape key is pressed.
    }
...
}

Thanks for your try out!!
hak


Joe Eaves

unread,
Feb 2, 2016, 3:33:49 PM2/2/16
to flatuilib
On Tuesday, 2 February 2016 16:35:59 UTC, Joe Eaves wrote: 
So somewhere between the Input and the Edit, we lose the keypress.

Alright I think I found the issue, but I'm not sure what to do about it. It seems like ESC is only caught by GetTextInputEvents in the layout pass (the render pass?), but we do all of our key catching inside the render pass. On line 444 of flatui.cpp, there is this if:
if (!layout_pass_) {

 Everything we need is inside this if, but the following code will only work outside (above) of it:
auto y = input_.GetTextInputEvents();
    if (y->size() > 0)
        // This never happens for ESCAPE unless we are in layout pass!
        std::cout << y->size() << std::endl;

What do you think?

Joe Eaves

unread,
Feb 2, 2016, 3:35:35 PM2/2/16
to flatuilib
On Tuesday, 2 February 2016 20:32:03 UTC, Hak Matsuda wrote:
It looks like the escape is flushed as a part of CheckGamePadNavigation.
Anyway, I think it's a good idea for Event() to return an input status. Will update it.

Thanks for your try out!!

Ah wicked! Cheers! No worries :D 
Reply all
Reply to author
Forward
0 new messages