Skip to content

Commit

Permalink
DragFloatRange2, DragIntRange2: Fixed an issue allowing to drag out o…
Browse files Browse the repository at this point in the history
…f bounds when both min and max value are on the same value. (#1441)
  • Loading branch information
ocornut committed Jul 23, 2020
1 parent fdc526e commit b8c22bd
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
2 changes: 2 additions & 0 deletions docs/CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion imgui_demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
22 changes: 18 additions & 4 deletions imgui_widgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit b8c22bd

Please sign in to comment.