From 4cabf599c4f9c15a175c2347e1aa052ec69de8c8 Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 8 May 2018 23:35:26 +0200 Subject: [PATCH] Data types: Fix format srtings with leading blanks. Fix ColorEdit4() to not use obsolete formats (when using IMGUI_DISABLE_OBSOLETE_FUNCTIONS) (#643) --- imgui.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 3097e7c6..530c04bf 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -8750,10 +8750,13 @@ static inline TYPE RoundScalarWithFormat(const char* format, ImGuiDataType data_ return v; char v_str[64]; ImFormatString(v_str, IM_ARRAYSIZE(v_str), fmt_start, v); + const char* p = v_str; + while (*p == ' ') + p++; if (data_type == ImGuiDataType_Float || data_type == ImGuiDataType_Double) - v = (TYPE)atof(v_str); + v = (TYPE)atof(p); else - ImAtoi(v_str, (SIGNEDTYPE*)&v); + ImAtoi(p, (SIGNEDTYPE*)&v); return v; } @@ -11910,9 +11913,9 @@ bool ImGui::ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flag const char* ids[4] = { "##X", "##Y", "##Z", "##W" }; const char* fmt_table_int[3][4] = { - { "%3.0f", "%3.0f", "%3.0f", "%3.0f" }, // Short display - { "R:%3.0f", "G:%3.0f", "B:%3.0f", "A:%3.0f" }, // Long display for RGBA - { "H:%3.0f", "S:%3.0f", "V:%3.0f", "A:%3.0f" } // Long display for HSVA + { "%3d", "%3d", "%3d", "%3d" }, // Short display + { "R:%3d", "G:%3d", "B:%3d", "A:%3d" }, // Long display for RGBA + { "H:%3d", "S:%3d", "V:%3d", "A:%3d" } // Long display for HSVA }; const char* fmt_table_float[3][4] = {