From cac76b2754c9b7415679ee5acdd4424b9a78fd67 Mon Sep 17 00:00:00 2001 From: David Briscoe Date: Mon, 20 Mar 2023 13:51:53 -0700 Subject: [PATCH] Slider, Drags: skip %+ and %# format flags for scanning. (#6259) (There are two additional unhandled flags that only affect padding: '-' and ' '. Formatting flags don't make sense in a SliderInt's format string, so I've omitted them) --- docs/CHANGELOG.txt | 2 ++ imgui_widgets.cpp | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index d08205454..7f05abb23 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -44,6 +44,8 @@ Other changes: retaining underlying data. While we don't really want to encourage user not retaining underlying data, in the absence of a "late commit" behavior/flag we understand it may be desirable to take advantage of this trick. (#4714) +- Drag, Sliders: Fixed parsing of text input when '+' or '#' format flags are used + in the format string. (#6259) [@idbrii] - Backends: OpenGL3: Fixed GL loader crash when GL_VERSION returns NULL. (#6154, #4445, #3530) - Backends: GLFW: Fixed key modifiers handling on secondary viewports. (#6248, #6034) [@aiekick] - Examples: Windows: Added 'misc/debuggers/imgui.natstepfilter' file to all Visual Studio projects, diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 326bbe1e8..97cf4df89 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -3300,7 +3300,7 @@ void ImParseFormatSanitizeForPrinting(const char* fmt_in, char* fmt_out, size_t *fmt_out = 0; // Zero-terminate } -// - For scanning we need to remove all width and precision fields "%3.7f" -> "%f". BUT don't strip types like "%I64d" which includes digits. ! "%07I64d" -> "%I64d" +// - For scanning we need to remove all width and precision fields and flags "%+3.7f" -> "%f". BUT don't strip types like "%I64d" which includes digits. ! "%07I64d" -> "%I64d" const char* ImParseFormatSanitizeForScanning(const char* fmt_in, char* fmt_out, size_t fmt_out_size) { const char* fmt_end = ImParseFormatFindEnd(fmt_in); @@ -3311,7 +3311,7 @@ const char* ImParseFormatSanitizeForScanning(const char* fmt_in, char* fmt_out, while (fmt_in < fmt_end) { char c = *fmt_in++; - if (!has_type && ((c >= '0' && c <= '9') || c == '.')) + if (!has_type && ((c >= '0' && c <= '9') || c == '.' || c == '+' || c == '#')) continue; has_type |= ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')); // Stop skipping digits if (c != '\'' && c != '$' && c != '_') // Custom flags provided by stb_sprintf.h. POSIX 2008 also supports '.