Skip to content

Commit 02de9bd

Browse files
committed
DragFloat, DragInt: if step/speed is zero defaults to 1% of range #180
1 parent 6408ac4 commit 02de9bd

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

imgui.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -1148,6 +1148,7 @@ struct ImGuiState
11481148
ImGuiID ActiveComboID;
11491149
float DragCurrentValue; // current dragged value, always float, not rounded by end-user precision settings
11501150
ImVec2 DragLastMouseDelta;
1151+
float DragSpeedDefaultRatio; // if speed == 0.0f, uses (max-min) * DragSpeedDefaultRatio
11511152
float DragSpeedScaleSlow;
11521153
float DragSpeedScaleFast;
11531154
float ScrollbarClickDeltaToGrabCenter; // distance between mouse and center of grab box, normalized in parent space
@@ -1205,6 +1206,7 @@ struct ImGuiState
12051206
ActiveComboID = 0;
12061207
DragCurrentValue = 0.0f;
12071208
DragLastMouseDelta = ImVec2(0.0f, 0.0f);
1209+
DragSpeedDefaultRatio = 0.01f;
12081210
DragSpeedScaleSlow = 0.01f;
12091211
DragSpeedScaleFast = 10.0f;
12101212
ScrollbarClickDeltaToGrabCenter = 0.0f;
@@ -5536,10 +5538,12 @@ static bool DragScalarBehavior(const ImRect& frame_bb, ImGuiID id, float* v, flo
55365538
if (fabsf(mouse_drag_delta.x - g.DragLastMouseDelta.x) > 0.0f)
55375539
{
55385540
float speed = v_speed;
5541+
if (speed == 0.0f && (v_max - v_min) != 0.0f && (v_max - v_min) < FLT_MAX)
5542+
speed = (v_max - v_min) * g.DragSpeedDefaultRatio;
55395543
if (g.IO.KeyShift && g.DragSpeedScaleFast >= 0.0f)
5540-
speed = v_speed * g.DragSpeedScaleFast;
5544+
speed = speed * g.DragSpeedScaleFast;
55415545
if (g.IO.KeyAlt && g.DragSpeedScaleSlow >= 0.0f)
5542-
speed = v_speed * g.DragSpeedScaleSlow;
5546+
speed = speed * g.DragSpeedScaleSlow;
55435547

55445548
float v_cur = g.DragCurrentValue;
55455549
float delta = (mouse_drag_delta.x - g.DragLastMouseDelta.x) * speed;

0 commit comments

Comments
 (0)