Edit box - key ENTER pressed

Started by Garwin, 18 April 2022, 12:09:13


I find out that if the Edit box is active (cursor blinks) and ENTER is pressed, it does not unfocus Editbox / does not end editing. The only possible way is to click by mouse somewhere else.
It is quite strange as I look into code of the widget and  there is:

    void EditBox::keyPressed(const Event::KeyEvent& event)
        if (event.code == Event::KeyboardKey::Enter)
            onReturnKeyPress.emit(this, m_text);
            onReturnOrUnfocus.emit(this, m_text);

However I cannot find "emit" anywhere (implementation).

OS: Windows 10
Codeblock 20.03
MinGW 7.3.0
SFML 2.5.1
TGUI 0.1 beta - MinGW 64 version
- both libraries linked dynamically


Quoteit does not unfocus Editbox / does not end editing
This is correct, the edit box doesn't actually do anything when you press enter.

The onReturnKeyPress and onReturnOrUnfocus are signals (like onPress in Button widgets) that you can connect to so that you can receive a callback when enter is pressed while the edit box is focused. So they just inform you about the key press, and don't change the state of the edit box.

The only reason why onReturnOrUnfocus exists is that there are many cases where you may want to execute the same code for onReturnKeyPress and onUnfocus, and the onReturnOrUnfocus signal simplifies this slightly (otherwise you would have to connect a callback to both onReturnKeyPress an onUnfocus, while now you only need to connect the callback to onReturnOrUnfocus).

You can connect to the onReturnKeyPress signal and then unfocus the edit box (or focus another widget) yourself from inside the callback if you really want that behavior.
I've never really though about how the focus is supposed to act when hitting the return key. I've only used if for cases where it triggered the same callback as a button beside the edit box or validate the input inside the edit box. I've never cared/thought about the focus before, so I never implemented any behavior for that.