MCPcopy Create free account
hub / github.com/Wemino/MarkerPatch / DragBehaviorT

Method DragBehaviorT

include/imgui/imgui_widgets.cpp:2529–2657  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2527// This is called by DragBehavior() when the widget is active (held by mouse or being manipulated with Nav controls)
2528template<typename TYPE, typename SIGNEDTYPE, typename FLOATTYPE>
2529bool ImGui::DragBehaviorT(ImGuiDataType data_type, TYPE* v, float v_speed, const TYPE v_min, const TYPE v_max, const char* format, ImGuiSliderFlags flags)
2530{
2531 ImGuiContext& g = *GImGui;
2532 const ImGuiAxis axis = (flags & ImGuiSliderFlags_Vertical) ? ImGuiAxis_Y : ImGuiAxis_X;
2533 const bool is_bounded = (v_min < v_max) || ((v_min == v_max) && (v_min != 0.0f || (flags & ImGuiSliderFlags_ClampZeroRange)));
2534 const bool is_wrapped = is_bounded && (flags & ImGuiSliderFlags_WrapAround);
2535 const bool is_logarithmic = (flags & ImGuiSliderFlags_Logarithmic) != 0;
2536 const bool is_floating_point = (data_type == ImGuiDataType_Float) || (data_type == ImGuiDataType_Double);
2537
2538 // Default tweak speed
2539 if (v_speed == 0.0f && is_bounded && (v_max - v_min < FLT_MAX))
2540 v_speed = (float)((v_max - v_min) * g.DragSpeedDefaultRatio);
2541
2542 // Inputs accumulates into g.DragCurrentAccum, which is flushed into the current value as soon as it makes a difference with our precision settings
2543 float adjust_delta = 0.0f;
2544 if (g.ActiveIdSource == ImGuiInputSource_Mouse && IsMousePosValid() && IsMouseDragPastThreshold(0, g.IO.MouseDragThreshold * DRAG_MOUSE_THRESHOLD_FACTOR))
2545 {
2546 adjust_delta = g.IO.MouseDelta[axis];
2547 if (g.IO.KeyAlt && !(flags & ImGuiSliderFlags_NoSpeedTweaks))
2548 adjust_delta *= 1.0f / 100.0f;
2549 if (g.IO.KeyShift && !(flags & ImGuiSliderFlags_NoSpeedTweaks))
2550 adjust_delta *= 10.0f;
2551 }
2552 else if (g.ActiveIdSource == ImGuiInputSource_Keyboard || g.ActiveIdSource == ImGuiInputSource_Gamepad)
2553 {
2554 const int decimal_precision = is_floating_point ? ImParseFormatPrecision(format, 3) : 0;
2555 const bool tweak_slow = IsKeyDown((g.NavInputSource == ImGuiInputSource_Gamepad) ? ImGuiKey_NavGamepadTweakSlow : ImGuiKey_NavKeyboardTweakSlow);
2556 const bool tweak_fast = IsKeyDown((g.NavInputSource == ImGuiInputSource_Gamepad) ? ImGuiKey_NavGamepadTweakFast : ImGuiKey_NavKeyboardTweakFast);
2557 const float tweak_factor = (flags & ImGuiSliderFlags_NoSpeedTweaks) ? 1.0f : tweak_slow ? 1.0f / 10.0f : tweak_fast ? 10.0f : 1.0f;
2558 adjust_delta = GetNavTweakPressedAmount(axis) * tweak_factor;
2559 v_speed = ImMax(v_speed, GetMinimumStepAtDecimalPrecision(decimal_precision));
2560 }
2561 adjust_delta *= v_speed;
2562
2563 // For vertical drag we currently assume that Up=higher value (like we do with vertical sliders). This may become a parameter.
2564 if (axis == ImGuiAxis_Y)
2565 adjust_delta = -adjust_delta;
2566
2567 // For logarithmic use our range is effectively 0..1 so scale the delta into that range
2568 if (is_logarithmic && (v_max - v_min < FLT_MAX) && ((v_max - v_min) > 0.000001f)) // Epsilon to avoid /0
2569 adjust_delta /= (float)(v_max - v_min);
2570
2571 // Clear current value on activation
2572 // Avoid altering values and clamping when we are _already_ past the limits and heading in the same direction, so e.g. if range is 0..255, current value is 300 and we are pushing to the right side, keep the 300.
2573 const bool is_just_activated = g.ActiveIdIsJustActivated;
2574 const bool is_already_past_limits_and_pushing_outward = is_bounded && !is_wrapped && ((*v >= v_max && adjust_delta > 0.0f) || (*v <= v_min && adjust_delta < 0.0f));
2575 if (is_just_activated || is_already_past_limits_and_pushing_outward)
2576 {
2577 g.DragCurrentAccum = 0.0f;
2578 g.DragCurrentAccumDirty = false;
2579 }
2580 else if (adjust_delta != 0.0f)
2581 {
2582 g.DragCurrentAccum += adjust_delta;
2583 g.DragCurrentAccumDirty = true;
2584 }
2585
2586 if (!g.DragCurrentAccumDirty)

Callers

nothing calls this directly

Calls 4

ImParseFormatPrecisionFunction · 0.85
ImMaxFunction · 0.85
ImPowFunction · 0.85

Tested by

no test coverage detected