From b2db7d11ec8dfd9d8a8fa164a2479a83d8418ddc Mon Sep 17 00:00:00 2001 From: jaswantp <40538987+jaswantp@users.noreply.github.com> Date: Mon, 24 Aug 2020 15:18:29 +0200 Subject: [PATCH] Recover from almost equal axis limits. When state.Axis->Range.Size() == DBL_EPSILON, the 'speed' to DragFloat is about 1.0e-14 which makes it virtually impossible to recover from that state! The fix proposes to detect and adjust the drag_speed accordingly. --- implot.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/implot.cpp b/implot.cpp index 85e34e5..7beb903 100644 --- a/implot.cpp +++ b/implot.cpp @@ -1140,7 +1140,8 @@ inline void ShowAxisContextMenu(ImPlotAxisState& state) { bool grid = ImHasFlag(state.Axis->Flags, ImPlotAxisFlags_GridLines); bool ticks = ImHasFlag(state.Axis->Flags, ImPlotAxisFlags_TickMarks); bool labels = ImHasFlag(state.Axis->Flags, ImPlotAxisFlags_TickLabels); - + double drag_speed = (state.Axis->Range.Size() <= DBL_EPSILON) ? DBL_EPSILON * 1.0e+13 : 0.01 * state.Axis->Range.Size(); // recover from almost equal axis limits. + BeginDisabledControls(total_lock); if (ImGui::Checkbox("##LockMin", &state.LockMin)) ImFlipFlag(state.Axis->Flags, ImPlotAxisFlags_LockMin); @@ -1148,7 +1149,8 @@ inline void ShowAxisContextMenu(ImPlotAxisState& state) { ImGui::SameLine(); BeginDisabledControls(state.LockMin); - DragFloat("Min", &state.Axis->Range.Min, 0.01f * (float)state.Axis->Range.Size(), -HUGE_VAL, state.Axis->Range.Max - DBL_EPSILON); + //DragFloat("Min", &state.Axis->Range.Min, 0.01f * (float)state.Axis->Range.Size(), -HUGE_VAL, state.Axis->Range.Max - DBL_EPSILON); + DragFloat("Min", &state.Axis->Range.Min, (float)drag_speed, -HUGE_VAL, state.Axis->Range.Max - DBL_EPSILON); EndDisabledControls(state.LockMin); BeginDisabledControls(total_lock); @@ -1158,7 +1160,8 @@ inline void ShowAxisContextMenu(ImPlotAxisState& state) { ImGui::SameLine(); BeginDisabledControls(state.LockMax); - DragFloat("Max", &state.Axis->Range.Max, 0.01f * (float)state.Axis->Range.Size(), state.Axis->Range.Min + DBL_EPSILON, HUGE_VAL); + //DragFloat("Max", &state.Axis->Range.Max, 0.01f * (float)state.Axis->Range.Size(), state.Axis->Range.Min + DBL_EPSILON, HUGE_VAL); + DragFloat("Max", &state.Axis->Range.Max, (float)drag_speed, state.Axis->Range.Min + DBL_EPSILON, HUGE_VAL); EndDisabledControls(state.LockMax); ImGui::Separator();