From 0cc148e65c785b06f1012ef15821924e77ab2ab2 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Sun, 17 Sep 2023 12:06:38 +0200 Subject: [PATCH] Improve position reset logic Force scroll to 0 on xy when it should reset, setting rects to 0 isn't sufficient as it goes into minus. Made the code mode simple as well. --- r5dev/gameui/IConsole.cpp | 40 ++++++++++++++------------------------- 1 file changed, 14 insertions(+), 26 deletions(-) diff --git a/r5dev/gameui/IConsole.cpp b/r5dev/gameui/IConsole.cpp index 7aaf616e..bbfd3932 100644 --- a/r5dev/gameui/IConsole.cpp +++ b/r5dev/gameui/IConsole.cpp @@ -395,8 +395,6 @@ void CConsole::SuggestPanel(void) ImGui::Begin("##suggest", nullptr, m_nSuggestFlags); ImGui::PushAllowKeyboardFocus(false); - bool bViewChanged = false; - for (size_t i = 0, ns = m_vSuggest.size(); i < ns; i++) { const CSuggest& suggest = m_vSuggest[i]; @@ -466,45 +464,35 @@ void CConsole::SuggestPanel(void) ImGui::PopID(); // Update the suggest position - if (m_bSuggestMoved && !bViewChanged) + if (m_bSuggestMoved) { - ImGuiWindow* const pWindow = ImGui::GetCurrentWindow(); - ImRect imRect = ImGui::GetCurrentContext()->LastItemData.Rect; - if (bIsIndexActive) // Bring the 'active' element into view { + 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! + imRect.Max.x = pWindow->InnerRect.Max.x; // Eliminate jiggle when going up/down in the menu. imRect.Min.y += 1; imRect.Max.y -= 1; - bViewChanged = true; - } - else if (m_nSuggestPos == PositionMode_t::kPark) // Reset position; kPark = no active element. - { - imRect.Min.x = 0; - imRect.Max.x = 0; - imRect.Min.y = 0; - imRect.Max.y = 0; - - bViewChanged = true; - } - - if (bViewChanged) - { ImGui::ScrollToRect(pWindow, imRect); + m_bSuggestMoved = false; + } + else if (m_nSuggestPos == PositionMode_t::kPark) + { + // Reset position; kPark = no active element. + ImGui::SetScrollX(0.0f); + ImGui::SetScrollY(0.0f); + + m_bSuggestMoved = false; } } } - if (bViewChanged) - { - m_bSuggestMoved = false; - } - ImGui::PopAllowKeyboardFocus(); ImGui::End(); }