mirror of
https://github.com/stenzek/duckstation.git
synced 2025-06-06 19:45:33 +00:00
dep/imgui: Fix smooth scrolling on scrollbar drag
This commit is contained in:
parent
b4e509d090
commit
09a825720d
@ -2255,6 +2255,7 @@ struct ImGuiContext
|
|||||||
ImGuiComboPreviewData ComboPreviewData;
|
ImGuiComboPreviewData ComboPreviewData;
|
||||||
ImRect WindowResizeBorderExpectedRect; // Expected border rect, switch to relative edit if moving
|
ImRect WindowResizeBorderExpectedRect; // Expected border rect, switch to relative edit if moving
|
||||||
bool WindowResizeRelativeMode;
|
bool WindowResizeRelativeMode;
|
||||||
|
unsigned char ScrollbarHeld; // Is the scrollbar scrolling the window?
|
||||||
short ScrollbarSeekMode; // 0: relative, -1/+1: prev/next page.
|
short ScrollbarSeekMode; // 0: relative, -1/+1: prev/next page.
|
||||||
float ScrollbarClickDeltaToGrabCenter; // Distance between mouse and center of grab box, normalized in parent space. Use storage?
|
float ScrollbarClickDeltaToGrabCenter; // Distance between mouse and center of grab box, normalized in parent space. Use storage?
|
||||||
float SliderGrabClickOffset;
|
float SliderGrabClickOffset;
|
||||||
@ -2478,6 +2479,7 @@ struct ImGuiContext
|
|||||||
ColorEditSavedHue = ColorEditSavedSat = 0.0f;
|
ColorEditSavedHue = ColorEditSavedSat = 0.0f;
|
||||||
ColorEditSavedColor = 0;
|
ColorEditSavedColor = 0;
|
||||||
WindowResizeRelativeMode = false;
|
WindowResizeRelativeMode = false;
|
||||||
|
ScrollbarHeld = false;
|
||||||
ScrollbarSeekMode = 0;
|
ScrollbarSeekMode = 0;
|
||||||
ScrollbarClickDeltaToGrabCenter = 0.0f;
|
ScrollbarClickDeltaToGrabCenter = 0.0f;
|
||||||
SliderGrabClickOffset = 0.0f;
|
SliderGrabClickOffset = 0.0f;
|
||||||
|
@ -4792,6 +4792,7 @@ void ImGui::NewFrame()
|
|||||||
g.HoveredId = 0;
|
g.HoveredId = 0;
|
||||||
g.HoveredIdAllowOverlap = false;
|
g.HoveredIdAllowOverlap = false;
|
||||||
g.HoveredIdIsDisabled = false;
|
g.HoveredIdIsDisabled = false;
|
||||||
|
g.ScrollbarHeld >>= 1;
|
||||||
|
|
||||||
// Clear ActiveID if the item is not alive anymore.
|
// Clear ActiveID if the item is not alive anymore.
|
||||||
// In 1.87, the common most call to KeepAliveID() was moved from GetID() to ItemAdd().
|
// In 1.87, the common most call to KeepAliveID() was moved from GetID() to ItemAdd().
|
||||||
@ -10802,7 +10803,7 @@ static ImVec2 CalcNextScrollFromScrollTargetAndClamp(ImGuiWindow* window)
|
|||||||
else
|
else
|
||||||
scroll[axis] -= ImMin(-diff, (-diff / (style.ScrollSmooth * multiplier)));
|
scroll[axis] -= ImMin(-diff, (-diff / (style.ScrollSmooth * multiplier)));
|
||||||
|
|
||||||
scroll[axis] = window->Appearing ? window->ScrollExpected[axis] : scroll[axis];
|
scroll[axis] = (window->Appearing || g.ScrollbarHeld & 1) ? window->ScrollExpected[axis] : scroll[axis];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return scroll;
|
return scroll;
|
||||||
|
@ -1001,7 +1001,7 @@ bool ImGui::ScrollbarEx(const ImRect& bb_frame, ImGuiID id, ImGuiAxis axis, ImS6
|
|||||||
{
|
{
|
||||||
// On initial click calculate the distance between mouse and the center of the grab
|
// On initial click calculate the distance between mouse and the center of the grab
|
||||||
g.ScrollbarSeekMode = (short)held_dir;
|
g.ScrollbarSeekMode = (short)held_dir;
|
||||||
g.ScrollbarClickDeltaToGrabCenter = (g.ScrollbarSeekMode == 0.0f) ? clicked_v_norm - grab_v_norm - grab_h_norm * 0.5f : 0.0f;
|
g.ScrollbarClickDeltaToGrabCenter = (g.ScrollbarSeekMode == 0) ? clicked_v_norm - grab_v_norm - grab_h_norm * 0.5f : 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply scroll (p_scroll_v will generally point on one member of window->Scroll)
|
// Apply scroll (p_scroll_v will generally point on one member of window->Scroll)
|
||||||
@ -1025,6 +1025,7 @@ bool ImGui::ScrollbarEx(const ImRect& bb_frame, ImGuiID id, ImGuiAxis axis, ImS6
|
|||||||
// Update values for rendering
|
// Update values for rendering
|
||||||
scroll_ratio = ImSaturate((float)*p_scroll_v / (float)scroll_max);
|
scroll_ratio = ImSaturate((float)*p_scroll_v / (float)scroll_max);
|
||||||
grab_v_norm = scroll_ratio * (scrollbar_size_v - grab_h_pixels) / scrollbar_size_v;
|
grab_v_norm = scroll_ratio * (scrollbar_size_v - grab_h_pixels) / scrollbar_size_v;
|
||||||
|
g.ScrollbarHeld |= 2;
|
||||||
|
|
||||||
// Update distance to grab now that we have seek'ed and saturated
|
// Update distance to grab now that we have seek'ed and saturated
|
||||||
//if (seek_absolute)
|
//if (seek_absolute)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user