Kaynağa Gözat

InputText: Made Shift+Tab consistently do nothing regardless of whether the back-end emits both char and keys or just keys. (#2467, #1336)

omar 6 yıl önce
ebeveyn
işleme
8dab7ac021
4 değiştirilmiş dosya ile 5 ekleme ve 2 silme
  1. 1 1
      docs/TODO.txt
  2. 1 1
      imgui_draw.cpp
  3. 1 0
      imgui_internal.h
  4. 2 0
      imgui_widgets.cpp

+ 1 - 1
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)

+ 1 - 1
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);
     }

+ 1 - 0
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]

+ 2 - 0
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);
                 }