diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 7846eaced..c2850811c 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -40,6 +40,8 @@ Other Changes: - Nav: Fixed clicking on void (behind any windows) from not clearing the focused window. This would be problematic e.g. in situation where the application relies on io.WantCaptureKeyboard flag being cleared accordingly. (bug introduced in 1.77 WIP on 2020/06/16) (#3344, #2880) +- DragFloatRange2, DragIntRange2: Fixed an issue allowing to drag out of bounds when both + min and max value are on the same value. (#1441) - InputText, ImDrawList: Fixed assert triggering when drawing single line of text with more than ~16 KB characters. (Note that current code is going to show corrupted display if after clipping, more than 16 KB characters are visible in the same low-level ImDrawList::RenderText diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 49ac4180e..647e4298a 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -1491,7 +1491,8 @@ static void ShowDemoWindowWidgets() { static float begin = 10, end = 90; static int begin_i = 100, end_i = 1000; - ImGui::DragFloatRange2("range", &begin, &end, 0.25f, 0.0f, 100.0f, "Min: %.1f %%", "Max: %.1f %%"); + ImGui::DragFloatRange2("range float", &begin, &end, 0.25f, 0.0f, 100.0f, "Min: %.1f %%", "Max: %.1f %%"); + ImGui::DragIntRange2("range int", &begin_i, &end_i, 5, 0, 1000, "Min: %d units", "Max: %d units"); ImGui::DragIntRange2("range int (no bounds)", &begin_i, &end_i, 5, 0, 0, "Min: %d units", "Max: %d units"); ImGui::TreePop(); } diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 9b3ec52dd..c0de761a0 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -2278,10 +2278,17 @@ bool ImGui::DragFloatRange2(const char* label, float* v_current_min, float* v_cu BeginGroup(); PushMultiItemsWidths(2, CalcItemWidth()); - bool value_changed = DragFloat("##min", v_current_min, v_speed, (v_min >= v_max) ? -FLT_MAX : v_min, (v_min >= v_max) ? *v_current_max : ImMin(v_max, *v_current_max), format, power); + float min = (v_min >= v_max) ? -FLT_MAX : v_min; + float max = (v_min >= v_max) ? *v_current_max : ImMin(v_max, *v_current_max); + if (min == max) { min = FLT_MAX; max = -FLT_MAX; } // Lock edit + bool value_changed = DragScalar("##min", ImGuiDataType_Float, v_current_min, v_speed, &min, &max, format, power); PopItemWidth(); SameLine(0, g.Style.ItemInnerSpacing.x); - value_changed |= DragFloat("##max", v_current_max, v_speed, (v_min >= v_max) ? *v_current_min : ImMax(v_min, *v_current_min), (v_min >= v_max) ? FLT_MAX : v_max, format_max ? format_max : format, power); + + min = (v_min >= v_max) ? *v_current_min : ImMax(v_min, *v_current_min); + max = (v_min >= v_max) ? FLT_MAX : v_max; + if (min == max) { min = FLT_MAX; max = -FLT_MAX; } // Lock edit + value_changed |= DragScalar("##max", ImGuiDataType_Float, v_current_max, v_speed, &min, &max, format_max ? format_max : format, power); PopItemWidth(); SameLine(0, g.Style.ItemInnerSpacing.x); @@ -2323,10 +2330,17 @@ bool ImGui::DragIntRange2(const char* label, int* v_current_min, int* v_current_ BeginGroup(); PushMultiItemsWidths(2, CalcItemWidth()); - bool value_changed = DragInt("##min", v_current_min, v_speed, (v_min >= v_max) ? INT_MIN : v_min, (v_min >= v_max) ? *v_current_max : ImMin(v_max, *v_current_max), format); + int min = (v_min >= v_max) ? INT_MIN : v_min; + int max = (v_min >= v_max) ? *v_current_max : ImMin(v_max, *v_current_max); + if (min == max) { min = INT_MAX; max = INT_MIN; } // Lock edit + bool value_changed = DragInt("##min", v_current_min, v_speed, min, max, format); PopItemWidth(); SameLine(0, g.Style.ItemInnerSpacing.x); - value_changed |= DragInt("##max", v_current_max, v_speed, (v_min >= v_max) ? *v_current_min : ImMax(v_min, *v_current_min), (v_min >= v_max) ? INT_MAX : v_max, format_max ? format_max : format); + + min = (v_min >= v_max) ? *v_current_min : ImMax(v_min, *v_current_min); + max = (v_min >= v_max) ? INT_MAX : v_max; + if (min == max) { min = INT_MAX; max = INT_MIN; } // Lock edit + value_changed |= DragInt("##max", v_current_max, v_speed, min, max, format_max ? format_max : format); PopItemWidth(); SameLine(0, g.Style.ItemInnerSpacing.x);