From 865a6dfa59052188979797117e0ded2f01f96c42 Mon Sep 17 00:00:00 2001 From: "Alexander \"FireFox\" Ong" Date: Tue, 28 Apr 2026 20:44:20 +1000 Subject: [PATCH] InputScalar: fixed not parsing user input when the display format is configured not to show the scalar value. (#9385) Useful e.g. for displaying "mixed" inputs, where a single field might represent multiple different values. --- docs/CHANGELOG.txt | 2 ++ imgui_widgets.cpp | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 5b12ba40e..dce8025f2 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -97,6 +97,8 @@ Other Changes: with 1.91.4 behavior. - In a majority of cases you should use IsItemDeactivatedAfterEdit() instead, but it still has a few edge cases flaws (to be addressed soon). +- InputInt, InputFloat, InputScalar: allow passing a format string that does not display + the scalar value. Parsing input with default format for the type. (#9385) [@FireFox2000000] - Multi-Select: - Fixed an issue using Multi-Select within a Table causing column width measurement to be invalid when trailing column contents is not submitted in the last row. (#9341, #8250) diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index ecad830a7..d05857d3c 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -2375,12 +2375,17 @@ bool ImGui::DataTypeApplyFromText(const char* buf, ImGuiDataType data_type, void // Sanitize format // - For float/double we have to ignore format with precision (e.g. "%.2f") because sscanf doesn't take them in, so force them into %f and %lf - // - In theory could treat empty format as using default, but this would only cover rare/bizarre case of using InputScalar() + integer + format string without %. char format_sanitized[32]; if (data_type == ImGuiDataType_Float || data_type == ImGuiDataType_Double) + { format = type_info->ScanFmt; + } else + { format = ImParseFormatSanitizeForScanning(format, format_sanitized, IM_COUNTOF(format_sanitized)); + if (format[0] == '\0') + format = type_info->ScanFmt; // Format doesn't want us to show the number currently, but we still need to parse the resulting input + } // Small types need a 32-bit buffer to receive the result from scanf() int v32 = 0;