From 9aefd6a046e4665457c415386c2557224f947b13 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Sun, 17 Sep 2023 01:25:44 +0200 Subject: [PATCH] CConsole: reset the view to the top if the list was updated If you had a list of suggestions, and had an active element halfway through the list, and then update the suggestion list again by changing what's in the input buffer, the view would remain at the old position (displaying whatever is there). This makes sure the view gets reset all the way to the top if the list was updated. --- r5dev/gameui/IConsole.cpp | 43 +++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/r5dev/gameui/IConsole.cpp b/r5dev/gameui/IConsole.cpp index 8771c681..67830a2d 100644 --- a/r5dev/gameui/IConsole.cpp +++ b/r5dev/gameui/IConsole.cpp @@ -460,24 +460,45 @@ void CConsole::SuggestPanel(void) BuildSummary(svConVar); } + ImGui::PopID(); - // Make sure we bring the currently 'active' item into view. - if (m_bSuggestMoved && bIsIndexActive) + // Update the suggest position + if (m_bSuggestMoved) { - ImGuiWindow* pWindow = ImGui::GetCurrentWindow(); + ImGuiWindow* const pWindow = ImGui::GetCurrentWindow(); ImRect imRect = ImGui::GetCurrentContext()->LastItemData.Rect; - // Reset to keep flag in display. - imRect.Min.x = pWindow->InnerRect.Min.x; - imRect.Max.x = pWindow->InnerRect.Min.x; // Set to Min.x on purpose! + bool bChanged = false; - // Eliminate jiggle when going up/down in the menu. - imRect.Min.y += 1; - imRect.Max.y -= 1; + if (bIsIndexActive) // Bring the 'active' element into view + { + // Reset to keep flag in display. + imRect.Min.x = pWindow->InnerRect.Min.x; + imRect.Max.x = pWindow->InnerRect.Min.x; // Set to Min.x on purpose! - ImGui::ScrollToRect(pWindow, imRect); - m_bSuggestMoved = false; + // Eliminate jiggle when going up/down in the menu. + imRect.Min.y += 1; + imRect.Max.y -= 1; + + bChanged = true; + } + else if (m_nSuggestPos == -1) // Reset position; -1 = no active element. + { + imRect.Min.x = 0; + imRect.Max.x = 0; + imRect.Min.y = 0; + imRect.Max.y = 0; + + bChanged = true; + } + + if (bChanged) + { + ImGui::ScrollToRect(pWindow, imRect); + } + + m_bSuggestMoved = true; } }