From 91c878c7192154aba85a06ebd377f3a97a3b76eb Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Thu, 7 Mar 2024 22:35:13 +0100 Subject: [PATCH] ImGui: properly attach autocomplete suggest window to console Make sure the autocomplete suggest window is always behind the console window with nothing in between. Previously, the server browser or modal panel ended up between the autocomplete suggest window and console window if the console was focused after the browser was invoked and moved partially on top of the console. --- r5dev/gameui/IConsole.cpp | 21 +++++++++++++++------ r5dev/gameui/IConsole.h | 1 + 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/r5dev/gameui/IConsole.cpp b/r5dev/gameui/IConsole.cpp index dae1c7f8..ffc6efdc 100644 --- a/r5dev/gameui/IConsole.cpp +++ b/r5dev/gameui/IConsole.cpp @@ -193,6 +193,8 @@ bool CConsole::DrawSurface(void) return false; } + m_mainWindow = ImGui::GetCurrentWindow(); + const ImGuiStyle& style = ImGui::GetStyle(); const ImVec2 fontSize = ImGui::GetFont()->CalcTextSizeA(ImGui::GetFontSize(), FLT_MAX, -1.0f, "#", nullptr, nullptr); @@ -218,8 +220,7 @@ bool CConsole::DrawSurface(void) /////////////////////////////////////////////////////////////////////// if (!m_colorTextLogger.IsScrolledToBottom() && m_scrollBackAmount > 0) { - ImGuiWindow* const window = ImGui::GetCurrentWindow(); - const ImGuiID windowId = window->GetID(m_loggerLabel); + const ImGuiID windowId = m_mainWindow->GetID(m_loggerLabel); char windowName[128]; snprintf(windowName, sizeof(windowName), "%s/%s_%08X", m_surfaceLabel, m_loggerLabel, windowId); @@ -403,6 +404,15 @@ void CConsole::DrawAutoCompletePanel(void) ImGui::Begin("##suggest", nullptr, autoCompleteWindowFlags); ImGui::PushAllowKeyboardFocus(false); + ImGuiWindow* const autocompleteWindow = ImGui::GetCurrentWindow(); + + // NOTE: this makes sure we always draw this window behind the main console + // window, this is necessary as otherwise if you were to drag another + // window above the console, and then focus on the console again, that + // window will now be in between the console window and the autocomplete + // suggest window. + ImGui::BringWindowToDisplayBehind(autocompleteWindow, m_mainWindow); + for (size_t i = 0, ns = m_vecSuggest.size(); i < ns; i++) { const ConAutoCompleteSuggest_s& suggest = m_vecSuggest[i]; @@ -477,18 +487,17 @@ void CConsole::DrawAutoCompletePanel(void) { if (isIndexActive) // Bring the 'active' element into view { - ImGuiWindow* const pWindow = ImGui::GetCurrentWindow(); ImRect imRect = ImGui::GetCurrentContext()->LastItemData.Rect; // Reset to keep flag icon in display. - imRect.Min.x = pWindow->InnerRect.Min.x; - imRect.Max.x = pWindow->InnerRect.Max.x; + imRect.Min.x = autocompleteWindow->InnerRect.Min.x; + imRect.Max.x = autocompleteWindow->InnerRect.Max.x; // Eliminate jiggle when going up/down in the menu. imRect.Min.y += 1; imRect.Max.y -= 1; - ImGui::ScrollToRect(pWindow, imRect); + ImGui::ScrollToRect(autocompleteWindow, imRect); m_autoCompletePosMoved = false; } else if (m_suggestPos == ConAutoCompletePos_e::kPark) diff --git a/r5dev/gameui/IConsole.h b/r5dev/gameui/IConsole.h index 2674cd74..7066098f 100644 --- a/r5dev/gameui/IConsole.h +++ b/r5dev/gameui/IConsole.h @@ -95,6 +95,7 @@ private: private: /////////////////////////////////////////////////////////////////////////// + ImGuiWindow* m_mainWindow; const char* m_loggerLabel; char m_inputTextBuf[512]; char m_summaryTextBuf[256];