From 8a370f64912b1cdb56d0dfcd9bd535adc9075040 Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 2 May 2018 19:46:57 +0200 Subject: [PATCH] SliderFloat: Fixed grab size and steps with %g format. (#642, #1301) --- imgui.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/imgui.cpp b/imgui.cpp index 467cda768..d9e2b4651 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -8689,6 +8689,8 @@ int ImGui::ParseFormatPrecision(const char* fmt, int default_precision) static float GetMinimumStepAtDecimalPrecision(int decimal_precision) { static const float min_steps[10] = { 1.0f, 0.1f, 0.01f, 0.001f, 0.0001f, 0.00001f, 0.000001f, 0.0000001f, 0.00000001f, 0.000000001f }; + if (decimal_precision < 0) + return FLT_MIN; return (decimal_precision >= 0 && decimal_precision < 10) ? min_steps[decimal_precision] : powf(10.0f, (float)-decimal_precision); } @@ -8737,7 +8739,7 @@ bool ImGui::SliderBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v const bool is_non_linear = (power < 1.0f-0.00001f) || (power > 1.0f+0.00001f); const bool is_horizontal = (flags & ImGuiSliderFlags_Vertical) == 0; - const bool is_decimal = ParseFormatPrecision(format, 3) > 0; + const bool is_decimal = ParseFormatPrecision(format, 3) != 0; const float grab_padding = 2.0f; const float slider_sz = is_horizontal ? (frame_bb.GetWidth() - grab_padding * 2.0f) : (frame_bb.GetHeight() - grab_padding * 2.0f);