From 4a57507f75e1e0da7d3bd72345ab3ae86f4df81e Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 3 Apr 2019 10:40:14 +0200 Subject: [PATCH] InputText: Work-around for buggy standard libraries where isprint('\t') returns true. (#2467, #1336) Not using isprint. + todo items. --- docs/CHANGELOG.txt | 1 + docs/TODO.txt | 3 ++- imgui.cpp | 2 +- imgui_demo.cpp | 3 ++- imgui_widgets.cpp | 10 +++++++--- 5 files changed, 13 insertions(+), 6 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 4834cb3f..f2b0b447 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -38,6 +38,7 @@ Breaking Changes: Other Changes: - InputText: Fixed selection background starts rendering one frame after the cursor movement when first transitioning from no-selection to has-selection. (Bug in 1.69) (#2436) [@Nazg-Gul] +- InputText: Work-around for buggy standard libraries where isprint('\t') returns true. (#2467, #1336) - GetMouseDragDelta(): also returns the delta on the mouse button released frame. (#2419) - GetMouseDragDelta(): verify that mouse positions are valid otherwise returns zero. - Inputs: Also add support for horizontal scroll with Shift+Mouse Wheel. (#2424, #1463) [@LucaRood] diff --git a/docs/TODO.txt b/docs/TODO.txt index f1774f8c..7e540b7b 100644 --- a/docs/TODO.txt +++ b/docs/TODO.txt @@ -138,7 +138,7 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - button: provide a button that looks framed. (?) - image/image button: misalignment on padded/bordered button? - image/image button: parameters are confusing, image() has tint_col,border_col whereas imagebutton() has bg_col/tint_col. Even thou they are different parameters ordering could be more consistent. can we fix that? - - image button: not taking an explicit id is odd. + - image button: not taking an explicit id can be problematic. (#2464, #1390) - slider/drag: ctrl+click when format doesn't include a % character.. disable? display underlying value in default format? (see InputScalarAsWidgetReplacement) - slider: allow using the [-]/[+] buttons used by InputFloat()/InputInt() - slider: initial absolute click is imprecise. change to relative movement slider (same as scrollbar). (#1946) @@ -329,6 +329,7 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - examples: glfw: could go idle when minimized? if (glfwGetWindowAttrib(window, GLFW_ICONIFIED)) { glfwWaitEvents(); continue; } // issue: DeltaTime will be super high on resume, perhaps provide a way to let impl know (#440) - examples: opengl: rename imgui_impl_opengl2 to impl_opengl_legacy and imgui_impl_opengl3 to imgui_impl_opengl? (#1900) - examples: opengl: could use a single vertex buffer and glBufferSubData for uploads? + - examples: vulkan: viewport: support for synchronized swapping of multiple swap chains. - optimization: replace vsnprintf with stb_printf? or enable the defines/infrastructure to allow it (#1038) - optimization: add clipping for multi-component widgets (SliderFloatX, ColorEditX, etc.). one problem is that nav branch can't easily clip parent group when there is a move request. - optimization: add a flag to disable most of rendering, for the case where the user expect to skip it (#335) diff --git a/imgui.cpp b/imgui.cpp index b129cb18..506a22aa 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -933,7 +933,7 @@ CODE #endif #include "imgui_internal.h" -#include // toupper, isprint +#include // toupper #include // vsnprintf, sscanf, printf #if defined(_MSC_VER) && _MSC_VER <= 1500 // MSVC 2008 or earlier #include // intptr_t diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 7496cd23..423022c1 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -49,7 +49,7 @@ Index of this file: #endif #include "imgui.h" -#include // toupper, isprint +#include // toupper #include // INT_MIN, INT_MAX #include // sqrtf, powf, cosf, sinf, floorf, ceilf #include // vsnprintf, sscanf, printf @@ -2571,6 +2571,7 @@ static void ShowDemoWindowMisc() ImGui::Text("Keys pressed:"); for (int i = 0; i < IM_ARRAYSIZE(io.KeysDown); i++) if (ImGui::IsKeyPressed(i)) { ImGui::SameLine(); ImGui::Text("%d (0x%X)", i, i); } ImGui::Text("Keys release:"); for (int i = 0; i < IM_ARRAYSIZE(io.KeysDown); i++) if (ImGui::IsKeyReleased(i)) { ImGui::SameLine(); ImGui::Text("%d (0x%X)", i, i); } ImGui::Text("Keys mods: %s%s%s%s", io.KeyCtrl ? "CTRL " : "", io.KeyShift ? "SHIFT " : "", io.KeyAlt ? "ALT " : "", io.KeySuper ? "SUPER " : ""); + ImGui::Text("Chars queue:"); for (int i = 0; i < io.InputQueueCharacters.Size; i++) { ImWchar c = io.InputQueueCharacters[i]; ImGui::SameLine(); ImGui::Text("\'%c\' (0x%04X)", (c > ' ' && c <= 255) ? (char)c : '?', c); } // FIXME: We should convert 'c' to UTF-8 here but the functions are not public. ImGui::Text("NavInputs down:"); for (int i = 0; i < IM_ARRAYSIZE(io.NavInputs); i++) if (io.NavInputs[i] > 0.0f) { ImGui::SameLine(); ImGui::Text("[%d] %.2f", i, io.NavInputs[i]); } ImGui::Text("NavInputs pressed:"); for (int i = 0; i < IM_ARRAYSIZE(io.NavInputs); i++) if (io.NavInputsDownDuration[i] == 0.0f) { ImGui::SameLine(); ImGui::Text("[%d]", i); } diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index f151e119..88e90cbc 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -37,7 +37,7 @@ Index of this file: #endif #include "imgui_internal.h" -#include // toupper, isprint +#include // toupper #if defined(_MSC_VER) && _MSC_VER <= 1500 // MSVC 2008 or earlier #include // intptr_t #else @@ -3139,7 +3139,8 @@ static bool InputTextFilterCharacter(unsigned int* p_char, ImGuiInputTextFlags f { unsigned int c = *p_char; - if (c < 128 && c != ' ' && !isprint((int)(c & 0xFF))) + // Filter non-printable (NB: isprint is unreliable! see #2467) + if (c < 0x20) { bool pass = false; pass |= (c == '\n' && (flags & ImGuiInputTextFlags_Multiline)); @@ -3148,9 +3149,11 @@ static bool InputTextFilterCharacter(unsigned int* p_char, ImGuiInputTextFlags f return false; } - if (c >= 0xE000 && c <= 0xF8FF) // Filter private Unicode range. I don't imagine anybody would want to input them. GLFW on OSX seems to send private characters for special keys like arrow keys. + // Filter private Unicode range. GLFW on OSX seems to send private characters for special keys like arrow keys (FIXME) + if (c >= 0xE000 && c <= 0xF8FF) return false; + // Generic named filters if (flags & (ImGuiInputTextFlags_CharsDecimal | ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsUppercase | ImGuiInputTextFlags_CharsNoBlank | ImGuiInputTextFlags_CharsScientific)) { if (flags & ImGuiInputTextFlags_CharsDecimal) @@ -3174,6 +3177,7 @@ static bool InputTextFilterCharacter(unsigned int* p_char, ImGuiInputTextFlags f return false; } + // Custom callback filter if (flags & ImGuiInputTextFlags_CallbackCharFilter) { ImGuiInputTextCallbackData callback_data;