From 8dab7ac0213088af8f2ce28ab0c2df65b2a6873d Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 3 Apr 2019 11:14:34 +0200 Subject: [PATCH] InputText: Made Shift+Tab consistently do nothing regardless of whether the back-end emits both char and keys or just keys. (#2467, #1336) --- docs/TODO.txt | 2 +- imgui_draw.cpp | 2 +- imgui_internal.h | 1 + imgui_widgets.cpp | 2 ++ 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/TODO.txt b/docs/TODO.txt index 45d347489..24525947c 100644 --- a/docs/TODO.txt +++ b/docs/TODO.txt @@ -80,7 +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: Shift+TAB with ImGuiInputTextFlags_AllowTabInput could eat preceding blanks, up to tab_count. - 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/imgui_draw.cpp b/imgui_draw.cpp index dcdf0e3f2..97f25bd45 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -2468,7 +2468,7 @@ void ImFont::BuildLookupTable() ImFontGlyph& tab_glyph = Glyphs.back(); tab_glyph = *FindGlyph((ImWchar)' '); tab_glyph.Codepoint = '\t'; - tab_glyph.AdvanceX *= 4; + tab_glyph.AdvanceX *= IM_TABSIZE; IndexAdvanceX[(int)tab_glyph.Codepoint] = (float)tab_glyph.AdvanceX; IndexLookup[(int)tab_glyph.Codepoint] = (ImWchar)(Glyphs.Size-1); } diff --git a/imgui_internal.h b/imgui_internal.h index 824c2824c..bcbaec6ad 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -129,6 +129,7 @@ extern IMGUI_API ImGuiContext* GImGui; // Current implicit ImGui context pointe #else #define IM_NEWLINE "\n" #endif +#define IM_TABSIZE (4) #define IMGUI_DEBUG_LOG(_FMT,...) printf("[%05d] " _FMT, GImGui->FrameCount, __VA_ARGS__) #define IM_STATIC_ASSERT(_COND) typedef char static_assertion_##__line__[(_COND)?1:-1] diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 941b02ef2..4ebbc1f56 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -3455,6 +3455,8 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ { // Insert character if they pass filtering unsigned int c = (unsigned int)io.InputQueueCharacters[n]; + if (c == '\t' && io.KeyShift) + continue; if (InputTextFilterCharacter(&c, flags, callback, callback_user_data)) state->OnKeyPressed((int)c); }