1
0
Fork 0
mirror of https://github.com/gwm17/implot.git synced 2024-11-13 22:48:50 -05:00

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.
This commit is contained in:
jaswantp 2020-08-24 15:18:29 +02:00 committed by GitHub
parent ac07bea9ac
commit b2db7d11ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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();