raysan5 / raygui

A simple and easy-to-use immediate-mode gui library
zlib License
3.36k stars 289 forks source link

Escape key doesn't abort textfield editing #342

Closed danielchasehooper closed 8 months ago

danielchasehooper commented 11 months ago

ESC doesn't abort textfield editing. Yes I know esc by default closes raylib, but if you called SetExitKey(0);, you kinda expect to be able to press escape to cancel editing a GuiValueBox.

raysan5 commented 11 months ago

I didn't add it because it could be problematic for some users. In my tools I just manage it on user-side, that's a benefit of the functions that register the edition mode.

danielchasehooper commented 11 months ago

Problematic? How so? That's how OS controls work.

What is the edition mode? I don't see anything named like that in the code.

raysan5 commented 11 months ago

This is how I use the GuiTextBox():

// User side GuiTexBox variables
char textBoxText[64] = "My text";
bool textBoxEditMode = false;

// Control drawing (ENTER accepts input text)
if (GuiTextBox((Rectangle){ 25, 215, 125, 30 }, textBoxText, 64, textBoxEditMode)) textBoxEditMode = !textBoxEditMode;

// But... what should happen if ESCAPE is pressed? Accept current input or cancel current edition?
if (textBoxEditMode && IsKeyPressed(KEY_ESCAPE)) 
{
    // In some of my tools ESCAPE is used to undo current edit and return to previous value (rGuiLayout tool)
    // So users are free to manage that kind of scenarios themselfs
    textBoxEditMode = false;
}
raysan5 commented 8 months ago

Escape key should be managed at user level due to the implications it could imply on main program.