Scrolling: SetScrollFromPosY() tweak to match change in a0d53fee81084a547bf21f46e736ea89f79fffb5 with similar desirable jump/discontinuity at each limit to skip the (ItemSpacing>WindowPadding) difference (followup to 0e5b64ecd2, #150)

This commit is contained in:
omar 2017-11-29 23:47:15 +01:00
parent c36e586cce
commit b513fdce48

View File

@ -5709,9 +5709,13 @@ void ImGui::SetScrollFromPosY(float pos_y, float center_y_ratio)
ImGuiWindow* window = GetCurrentWindow();
IM_ASSERT(center_y_ratio >= 0.0f && center_y_ratio <= 1.0f);
window->ScrollTarget.y = (float)(int)(pos_y + window->Scroll.y);
if (center_y_ratio <= 0.0f && window->ScrollTarget.y <= window->WindowPadding.y) // Minor hack to make "scroll to top" take account of WindowPadding, else it would scroll to (WindowPadding.y - ItemSpacing.y)
window->ScrollTarget.y = 0.0f;
window->ScrollTargetCenterRatio.y = center_y_ratio;
// Minor hack to to make scrolling to top/bottom of window take account of WindowPadding, it looks more right to the user this way
if (center_y_ratio <= 0.0f && window->ScrollTarget.y <= window->WindowPadding.y)
window->ScrollTarget.y = 0.0f;
else if (center_y_ratio >= 1.0f && window->ScrollTarget.y >= window->SizeContents.y - window->WindowPadding.y + GImGui->Style.ItemSpacing.y)
window->ScrollTarget.y = window->SizeContents.y;
}
// center_y_ratio: 0.0f top of last item, 0.5f vertical center of last item, 1.0f bottom of last item.