From 3ca54ad3699da66414b7026a87db3c910ac13651 Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 9 Jun 2015 12:57:27 -0600 Subject: [PATCH] SetScrollPosHere() takes account of item height + more accurate centering --- imgui.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 5459bc94..91ce2e1e 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3717,7 +3717,7 @@ bool ImGui::Begin(const char* name, bool* p_opened, const ImVec2& size_on_first_ // Apply scrolling if (window->ScrollTargetCenterY >= 0.0f) { - window->ScrollY = window->ScrollTargetCenterY - (window->Pos.y + window->SizeFull.y * 0.5f) - (window->TitleBarHeight() + window->WindowPadding().y); + window->ScrollY = window->ScrollTargetCenterY - (window->Pos.y + (window->SizeFull.y + window->TitleBarHeight() + window->WindowPadding().y) * 0.5f); window->ScrollTargetCenterY = -1.0f; } window->ScrollY = ImMax(window->ScrollY, 0.0f); @@ -4646,7 +4646,7 @@ float ImGui::GetScrollMaxY() void ImGui::SetScrollPosHere() { ImGuiWindow* window = GetCurrentWindow(); - window->ScrollTargetCenterY = (window->DC.CursorPos.y + window->ScrollY); + window->ScrollTargetCenterY = (window->DC.CursorPos.y + window->ScrollY) - window->DC.PrevLineHeight * 0.5f; } void ImGui::SetKeyboardFocusHere(int offset)