From 02de9bd859f84742cd555eeb90cee53c6b58ad35 Mon Sep 17 00:00:00 2001 From: ocornut Date: Fri, 17 Apr 2015 10:01:39 +0100 Subject: [PATCH] DragFloat, DragInt: if step/speed is zero defaults to 1% of range #180 --- imgui.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index fdbf12fa..9ba6b707 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1148,6 +1148,7 @@ struct ImGuiState ImGuiID ActiveComboID; float DragCurrentValue; // current dragged value, always float, not rounded by end-user precision settings ImVec2 DragLastMouseDelta; + float DragSpeedDefaultRatio; // if speed == 0.0f, uses (max-min) * DragSpeedDefaultRatio float DragSpeedScaleSlow; float DragSpeedScaleFast; float ScrollbarClickDeltaToGrabCenter; // distance between mouse and center of grab box, normalized in parent space @@ -1205,6 +1206,7 @@ struct ImGuiState ActiveComboID = 0; DragCurrentValue = 0.0f; DragLastMouseDelta = ImVec2(0.0f, 0.0f); + DragSpeedDefaultRatio = 0.01f; DragSpeedScaleSlow = 0.01f; DragSpeedScaleFast = 10.0f; ScrollbarClickDeltaToGrabCenter = 0.0f; @@ -5536,10 +5538,12 @@ static bool DragScalarBehavior(const ImRect& frame_bb, ImGuiID id, float* v, flo if (fabsf(mouse_drag_delta.x - g.DragLastMouseDelta.x) > 0.0f) { float speed = v_speed; + if (speed == 0.0f && (v_max - v_min) != 0.0f && (v_max - v_min) < FLT_MAX) + speed = (v_max - v_min) * g.DragSpeedDefaultRatio; if (g.IO.KeyShift && g.DragSpeedScaleFast >= 0.0f) - speed = v_speed * g.DragSpeedScaleFast; + speed = speed * g.DragSpeedScaleFast; if (g.IO.KeyAlt && g.DragSpeedScaleSlow >= 0.0f) - speed = v_speed * g.DragSpeedScaleSlow; + speed = speed * g.DragSpeedScaleSlow; float v_cur = g.DragCurrentValue; float delta = (mouse_drag_delta.x - g.DragLastMouseDelta.x) * speed;