Skip to content

Commit eb405ab

Browse files
committed
DragBehavior: Moving code around, in what should be a no-op, to simplify upcoming Nav diff (#323, #180)
1 parent c816e6c commit eb405ab

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

imgui.cpp

+13-12
Original file line numberDiff line numberDiff line change
@@ -6769,32 +6769,33 @@ bool ImGui::DragBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v_s
67696769
g.DragLastMouseDelta = ImVec2(0.f, 0.f);
67706770
}
67716771

6772+
if (v_speed == 0.0f && (v_max - v_min) != 0.0f && (v_max - v_min) < FLT_MAX)
6773+
v_speed = (v_max - v_min) * g.DragSpeedDefaultRatio;
6774+
67726775
float v_cur = g.DragCurrentValue;
67736776
const ImVec2 mouse_drag_delta = GetMouseDragDelta(0, 1.0f);
6774-
if (fabsf(mouse_drag_delta.x - g.DragLastMouseDelta.x) > 0.0f)
6777+
float adjust_delta = mouse_drag_delta.x - g.DragLastMouseDelta.x;
6778+
if (g.IO.KeyShift && g.DragSpeedScaleFast >= 0.0f)
6779+
adjust_delta *= g.DragSpeedScaleFast;
6780+
if (g.IO.KeyAlt && g.DragSpeedScaleSlow >= 0.0f)
6781+
adjust_delta *= g.DragSpeedScaleSlow;
6782+
adjust_delta *= v_speed;
6783+
6784+
if (fabsf(adjust_delta) > 0.0f)
67756785
{
6776-
float speed = v_speed;
6777-
if (speed == 0.0f && (v_max - v_min) != 0.0f && (v_max - v_min) < FLT_MAX)
6778-
speed = (v_max - v_min) * g.DragSpeedDefaultRatio;
6779-
if (g.IO.KeyShift && g.DragSpeedScaleFast >= 0.0f)
6780-
speed = speed * g.DragSpeedScaleFast;
6781-
if (g.IO.KeyAlt && g.DragSpeedScaleSlow >= 0.0f)
6782-
speed = speed * g.DragSpeedScaleSlow;
6783-
6784-
float delta = (mouse_drag_delta.x - g.DragLastMouseDelta.x) * speed;
67856786
if (fabsf(power - 1.0f) > 0.001f)
67866787
{
67876788
// Logarithmic curve on both side of 0.0
67886789
float v0_abs = v_cur >= 0.0f ? v_cur : -v_cur;
67896790
float v0_sign = v_cur >= 0.0f ? 1.0f : -1.0f;
6790-
float v1 = powf(v0_abs, 1.0f / power) + (delta * v0_sign);
6791+
float v1 = powf(v0_abs, 1.0f / power) + (adjust_delta * v0_sign);
67916792
float v1_abs = v1 >= 0.0f ? v1 : -v1;
67926793
float v1_sign = v1 >= 0.0f ? 1.0f : -1.0f; // Crossed sign line
67936794
v_cur = powf(v1_abs, power) * v0_sign * v1_sign; // Reapply sign
67946795
}
67956796
else
67966797
{
6797-
v_cur += delta;
6798+
v_cur += adjust_delta;
67986799
}
67996800
g.DragLastMouseDelta.x = mouse_drag_delta.x;
68006801

0 commit comments

Comments
 (0)