From 36af39805605828b1a75e781abb3b1bdc72a49f5 Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 7 Sep 2020 19:52:11 +0200 Subject: [PATCH] Sliders: Fixed using ImGuiSliderFlags_ClampOnInput with reverse sliders. (#3432, #3449) --- docs/CHANGELOG.txt | 2 ++ imgui_widgets.cpp | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 515b0ff11..b401c0ee1 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -51,6 +51,8 @@ Other Changes: - InputText: Fixed callback's helper DeleteChars() function when cursor is inside the deleted block. (#3454). - DragFloat, DragScalar: Fixed ImGuiSliderFlags_ClampOnInput not being honored in the special case where v_min == v_max. (#3361) +- SliderInt, SliderScalar: Fixed reaching of maximum value with inverted integer min/max ranges, both + with signed and unsigned types. Added reverse Sliders to Demo. (#3432, #3449) [@rokups] - BeginMenuBar: Fixed minor bug where CursorPosMax gets pushed to CursorPos prior to calling BeginMenuBar(), so e.g. calling the function at the end of a window would often add +ItemSpacing.y to scrolling range. - TreeNode, CollapsingHeader: Made clicking on arrow toggle toggle the open state on the Mouse Down event diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index b0cf70bc9..628d4cfd5 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -1942,7 +1942,7 @@ static bool DataTypeClampT(T* v, const T* v_min, const T* v_max) { // Clamp, both sides are optional, return true if modified if (v_min && *v < *v_min) { *v = *v_min; return true; } - if (v_max && *v > * v_max) { *v = *v_max; return true; } + if (v_max && *v > *v_max) { *v = *v_max; return true; } return false; } @@ -3191,7 +3191,11 @@ bool ImGui::TempInputScalar(const ImRect& bb, ImGuiID id, const char* label, ImG // Apply new value (or operations) then clamp DataTypeApplyOpFromText(data_buf, g.InputTextState.InitialTextA.Data, data_type, p_data, NULL); if (p_clamp_min || p_clamp_max) + { + if (DataTypeCompare(data_type, p_clamp_min, p_clamp_max) > 0) + ImSwap(p_clamp_min, p_clamp_max); DataTypeClamp(data_type, p_data, p_clamp_min, p_clamp_max); + } // Only mark as edited if new value is different value_changed = memcmp(&data_backup, p_data, data_type_size) != 0;