Skip to content

Commit

Permalink
dep/imgui: Fix smooth scrolling on scrollbar drag
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek committed Nov 2, 2024
1 parent b4e509d commit 09a8257
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
2 changes: 2 additions & 0 deletions dep/imgui/include/imgui_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -2255,6 +2255,7 @@ struct ImGuiContext
ImGuiComboPreviewData ComboPreviewData;
ImRect WindowResizeBorderExpectedRect; // Expected border rect, switch to relative edit if moving
bool WindowResizeRelativeMode;
unsigned char ScrollbarHeld; // Is the scrollbar scrolling the window?
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 SliderGrabClickOffset;
Expand Down Expand Up @@ -2478,6 +2479,7 @@ struct ImGuiContext
ColorEditSavedHue = ColorEditSavedSat = 0.0f;
ColorEditSavedColor = 0;
WindowResizeRelativeMode = false;
ScrollbarHeld = false;
ScrollbarSeekMode = 0;
ScrollbarClickDeltaToGrabCenter = 0.0f;
SliderGrabClickOffset = 0.0f;
Expand Down
3 changes: 2 additions & 1 deletion dep/imgui/src/imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4792,6 +4792,7 @@ void ImGui::NewFrame()
g.HoveredId = 0;
g.HoveredIdAllowOverlap = false;
g.HoveredIdIsDisabled = false;
g.ScrollbarHeld >>= 1;

// Clear ActiveID if the item is not alive anymore.
// In 1.87, the common most call to KeepAliveID() was moved from GetID() to ItemAdd().
Expand Down Expand Up @@ -10802,7 +10803,7 @@ static ImVec2 CalcNextScrollFromScrollTargetAndClamp(ImGuiWindow* window)
else
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;
Expand Down
3 changes: 2 additions & 1 deletion dep/imgui/src/imgui_widgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
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)
Expand All @@ -1025,6 +1025,7 @@ bool ImGui::ScrollbarEx(const ImRect& bb_frame, ImGuiID id, ImGuiAxis axis, ImS6
// Update values for rendering
scroll_ratio = ImSaturate((float)*p_scroll_v / (float)scroll_max);
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
//if (seek_absolute)
Expand Down

0 comments on commit 09a8257

Please sign in to comment.