mirror of
https://github.com/ocornut/imgui.git
synced 2025-02-07 14:51:22 +01:00
MultiSelect: Box-Select: Fixed scrolling on high framerates.
This commit is contained in:
parent
5d9de14493
commit
907268a430
@ -1721,6 +1721,7 @@ struct ImGuiBoxSelectState
|
|||||||
ImGuiKeyChord KeyMods : 16; // Latched key-mods for box-select logic.
|
ImGuiKeyChord KeyMods : 16; // Latched key-mods for box-select logic.
|
||||||
ImVec2 StartPosRel; // Start position in window-contents relative space (to support scrolling)
|
ImVec2 StartPosRel; // Start position in window-contents relative space (to support scrolling)
|
||||||
ImVec2 EndPosRel; // End position in window-contents relative space
|
ImVec2 EndPosRel; // End position in window-contents relative space
|
||||||
|
ImVec2 ScrollAccum; // Scrolling accumulator (to behave at high-frame spaces)
|
||||||
ImGuiWindow* Window;
|
ImGuiWindow* Window;
|
||||||
|
|
||||||
// Temporary/Transient data
|
// Temporary/Transient data
|
||||||
|
@ -7127,11 +7127,14 @@ static void BoxSelectStart(ImGuiID id, ImGuiSelectionUserData clicked_item)
|
|||||||
bs->IsStartedFromVoid = (clicked_item == ImGuiSelectionUserData_Invalid);
|
bs->IsStartedFromVoid = (clicked_item == ImGuiSelectionUserData_Invalid);
|
||||||
bs->KeyMods = g.IO.KeyMods;
|
bs->KeyMods = g.IO.KeyMods;
|
||||||
bs->StartPosRel = bs->EndPosRel = ImGui::WindowPosAbsToRel(g.CurrentWindow, g.IO.MousePos);
|
bs->StartPosRel = bs->EndPosRel = ImGui::WindowPosAbsToRel(g.CurrentWindow, g.IO.MousePos);
|
||||||
|
bs->ScrollAccum = ImVec2(0.0f, 0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void BoxSelectScrollWithMouseDrag(ImGuiWindow* window, const ImRect& inner_r)
|
static void BoxSelectScrollWithMouseDrag(ImGuiWindow* window, const ImRect& inner_r)
|
||||||
{
|
{
|
||||||
ImGuiContext& g = *GImGui;
|
ImGuiContext& g = *GImGui;
|
||||||
|
ImGuiBoxSelectState* bs = &g.BoxSelectState;
|
||||||
|
IM_ASSERT(bs->Window == window);
|
||||||
for (int n = 0; n < 2; n++) // each axis
|
for (int n = 0; n < 2; n++) // each axis
|
||||||
{
|
{
|
||||||
const float mouse_pos = g.IO.MousePos[n];
|
const float mouse_pos = g.IO.MousePos[n];
|
||||||
@ -7139,12 +7142,20 @@ static void BoxSelectScrollWithMouseDrag(ImGuiWindow* window, const ImRect& inne
|
|||||||
const float scroll_curr = window->Scroll[n];
|
const float scroll_curr = window->Scroll[n];
|
||||||
if (dist == 0.0f || (dist < 0.0f && scroll_curr < 0.0f) || (dist > 0.0f && scroll_curr >= window->ScrollMax[n]))
|
if (dist == 0.0f || (dist < 0.0f && scroll_curr < 0.0f) || (dist > 0.0f && scroll_curr >= window->ScrollMax[n]))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const float speed_multiplier = ImLinearRemapClamp(g.FontSize, g.FontSize * 5.0f, 1.0f, 4.0f, ImAbs(dist)); // x1 to x4 depending on distance
|
const float speed_multiplier = ImLinearRemapClamp(g.FontSize, g.FontSize * 5.0f, 1.0f, 4.0f, ImAbs(dist)); // x1 to x4 depending on distance
|
||||||
const float scroll_step = IM_ROUND(g.FontSize * 35.0f * speed_multiplier * ImSign(dist) * g.IO.DeltaTime);
|
const float scroll_step = g.FontSize * 35.0f * speed_multiplier * ImSign(dist) * g.IO.DeltaTime;
|
||||||
|
bs->ScrollAccum[n] += scroll_step;
|
||||||
|
|
||||||
|
// Accumulate into a stored value so we can handle high-framerate
|
||||||
|
const float scroll_step_i = ImFloor(bs->ScrollAccum[n]);
|
||||||
|
if (scroll_step_i == 0.0f)
|
||||||
|
continue;
|
||||||
if (n == 0)
|
if (n == 0)
|
||||||
ImGui::SetScrollX(window, scroll_curr + scroll_step);
|
ImGui::SetScrollX(window, scroll_curr + scroll_step_i);
|
||||||
else
|
else
|
||||||
ImGui::SetScrollY(window, scroll_curr + scroll_step);
|
ImGui::SetScrollY(window, scroll_curr + scroll_step_i);
|
||||||
|
bs->ScrollAccum[n] -= scroll_step_i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user