From da035ced9752224050f88bec01ba3313972d30ab Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 3 Apr 2019 11:04:00 +0200 Subject: [PATCH] InputText, Examples/SDL: Emulate \t input if back-end doesn't provide it. (#1336, #2467) + Fix some output filename in SDL build batch files. --- docs/TODO.txt | 1 + examples/example_sdl_opengl2/build_win32.bat | 4 ++-- examples/example_sdl_opengl3/build_win32.bat | 2 +- imgui_widgets.cpp | 18 ++++++++++++++---- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/docs/TODO.txt b/docs/TODO.txt index 7e540b7b2..45d347489 100644 --- a/docs/TODO.txt +++ b/docs/TODO.txt @@ -80,6 +80,7 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - input text: force scroll to end or scroll to a given line/contents (so user can implement a log or a search feature) - input text: a side bar that could e.g. preview where errors are. probably left to the user to draw but we'd need to give them the info there. - input text: a way for the user to provide syntax coloring. + - input text: Shift+TAB with ImGuiInputTextFlags_AllowTabInput works inconsistently depending on whether back-end emits actual Tab Key + \t Char or not (SDL doesn't). - input text multi-line: don't directly call AddText() which does an unnecessary vertex reserve for character count prior to clipping. and/or more line-based clipping to AddText(). and/or reorganize TextUnformatted/RenderText for more efficiency for large text (e.g TextUnformatted could clip and log separately, etc). - input text multi-line: support for cut/paste without selection (cut/paste the current line) - input text multi-line: line numbers? status bar? (follow up on #200) diff --git a/examples/example_sdl_opengl2/build_win32.bat b/examples/example_sdl_opengl2/build_win32.bat index 97692d9e4..d209b2a2a 100644 --- a/examples/example_sdl_opengl2/build_win32.bat +++ b/examples/example_sdl_opengl2/build_win32.bat @@ -1,8 +1,8 @@ @REM Build for Visual Studio compiler. Run your copy of vcvars32.bat or vcvarsall.bat to setup command-line compiler. set OUT_DIR=Debug -set OUT_EXE=example_sdl_opengl2.exe +set OUT_EXE=example_sdl_opengl2 set INCLUDES=/I.. /I..\.. /I%SDL2_DIR%\include set SOURCES=main.cpp ..\imgui_impl_sdl.cpp ..\imgui_impl_opengl2.cpp ..\..\imgui*.cpp set LIBS=/libpath:%SDL2_DIR%\lib\x86 SDL2.lib SDL2main.lib opengl32.lib mkdir %OUT_DIR% -cl /nologo /Zi /MD %INCLUDES% %SOURCES% /Fe%OUT_DIR%/%OUT_DIR%.exe /Fo%OUT_DIR%/ /link %LIBS% /subsystem:console +cl /nologo /Zi /MD %INCLUDES% %SOURCES% /Fe%OUT_DIR%/%OUT_EXE%.exe /Fo%OUT_DIR%/ /link %LIBS% /subsystem:console diff --git a/examples/example_sdl_opengl3/build_win32.bat b/examples/example_sdl_opengl3/build_win32.bat index f263c4b34..ce105602f 100644 --- a/examples/example_sdl_opengl3/build_win32.bat +++ b/examples/example_sdl_opengl3/build_win32.bat @@ -1,6 +1,6 @@ @REM Build for Visual Studio compiler. Run your copy of vcvars32.bat or vcvarsall.bat to setup command-line compiler. set OUT_DIR=Debug -set OUT_EXE=example_sdl_opengl3.exe +set OUT_EXE=example_sdl_opengl3 set INCLUDES=/I.. /I..\.. /I%SDL2_DIR%\include /I..\libs\gl3w set SOURCES=main.cpp ..\imgui_impl_sdl.cpp ..\imgui_impl_opengl3.cpp ..\..\imgui*.cpp ..\libs\gl3w\GL\gl3w.c set LIBS=/libpath:%SDL2_DIR%\lib\x86 SDL2.lib SDL2main.lib opengl32.lib diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 04fe9d617..941b02ef2 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -3435,12 +3435,22 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ if (state->SelectedAllMouseLock && !io.MouseDown[0]) state->SelectedAllMouseLock = false; + // It is ill-defined whether the back-end needs to send a \t character when pressing the TAB keys. + // Win32 and GLFW naturally do it but not SDL. + const bool ignore_char_inputs = (io.KeyCtrl && !io.KeyAlt) || (is_osx && io.KeySuper); + if ((flags & ImGuiInputTextFlags_AllowTabInput) && IsKeyPressedMap(ImGuiKey_Tab) && !ignore_char_inputs && !io.KeyShift && !is_readonly) + if (!io.InputQueueCharacters.contains('\t')) + { + unsigned int c = '\t'; // Insert TAB + if (InputTextFilterCharacter(&c, flags, callback, callback_user_data)) + state->OnKeyPressed((int)c); + } + + // Process regular text input (before we check for Return because using some IME will effectively send a Return?) + // We ignore CTRL inputs, but need to allow ALT+CTRL as some keyboards (e.g. German) use AltGR (which _is_ Alt+Ctrl) to input certain characters. if (io.InputQueueCharacters.Size > 0) { - // Process text input (before we check for Return because using some IME will effectively send a Return?) - // We ignore CTRL inputs, but need to allow ALT+CTRL as some keyboards (e.g. German) use AltGR (which _is_ Alt+Ctrl) to input certain characters. - bool ignore_inputs = (io.KeyCtrl && !io.KeyAlt) || (is_osx && io.KeySuper); - if (!ignore_inputs && !is_readonly && !user_nav_input_start) + if (!ignore_char_inputs && !is_readonly && !user_nav_input_start) for (int n = 0; n < io.InputQueueCharacters.Size; n++) { // Insert character if they pass filtering