From 6d3bd818e1de6aaa368bec32c9288c3c032aa96b Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Sat, 2 Mar 2024 01:54:04 +0100 Subject: [PATCH] ImGui: move summary text above input text The pass filter has some features (including, or excluding with the '-' prefix), but this isn't very clear. Added the original 'usage' text back, which caused the following issue: the summary text (showing how many history items, or the currently selected convar's current value/default value) would clip outside the console window on ConVar's that had larger string values, like URL's. The summary text has been moved to just above the input text field to fix this issue. This patch also contains some slight improvement to styling of the console. --- r5dev/gameui/IConsole.cpp | 47 +++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/r5dev/gameui/IConsole.cpp b/r5dev/gameui/IConsole.cpp index 723cdd61..d7c342b7 100644 --- a/r5dev/gameui/IConsole.cpp +++ b/r5dev/gameui/IConsole.cpp @@ -218,12 +218,8 @@ bool CConsole::DrawSurface(void) } const ImGuiStyle& style = ImGui::GetStyle(); - - // Reserve enough left-over height and width for 1 separator + 1 input text - const float footerHeightReserve = style.ItemSpacing.y + ImGui::GetFrameHeightWithSpacing(); - const float footerWidthReserve = style.ItemSpacing.y + ImGui::GetWindowWidth(); - const ImVec2 fontSize = ImGui::GetFont()->CalcTextSizeA(ImGui::GetFontSize(), FLT_MAX, -1.0f, "#", nullptr, nullptr); + /////////////////////////////////////////////////////////////////////// ImGui::Separator(); if (ImGui::BeginPopup("Options")) @@ -236,10 +232,10 @@ bool CConsole::DrawSurface(void) } ImGui::SameLine(); - m_colorTextLogger.GetFilter().Draw("Filter | ", footerWidthReserve - 500); - ImGui::SameLine(); - ImGui::Text("%s", m_summaryTextBuf); + // Reserve enough left-over height and width for 1 separator + 1 input text + const float footerWidthReserve = style.ItemSpacing.y + ImGui::GetWindowWidth(); + m_colorTextLogger.GetFilter().Draw("Filter (inc,-exc)", footerWidthReserve - 350); ImGui::Separator(); @@ -256,10 +252,27 @@ bool CConsole::DrawSurface(void) } m_scrollBackAmount = 0; - /////////////////////////////////////////////////////////////////////// - int numStyleVars = 0; // Eliminate borders around log window. - ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2{ 1.f, 1.f }); numStyleVars++; - ImGui::BeginChild(m_loggerLabel, ImVec2(0, -footerHeightReserve), true, m_colorLoggerWindowFlags); + // Reserve enough left-over height for 2 text elements. + float footerHeightReserve = ImGui::GetFrameHeight() * 2; + ImGuiChildFlags loggerFlags = ImGuiChildFlags_None; + + const bool isLegacyStyle = m_surfaceStyle == ImGuiStyle_t::LEGACY; + int numLoggerStyleVars = 0; + + if (isLegacyStyle) + { + loggerFlags |= ImGuiChildFlags_Border; + + // Eliminate padding around logger child. This padding gets added when + // ImGuiChildFlags_Border flag gets set. + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2{ 1.f, 1.f }); numLoggerStyleVars++; + + // if we use the legacy theme, also account for one extra space as the + // legacy theme has an extra separator at the bottom of the logger. + footerHeightReserve += style.ItemSpacing.y; + } + + ImGui::BeginChild(m_loggerLabel, ImVec2(0, -footerHeightReserve), loggerFlags, m_colorLoggerWindowFlags); // NOTE: scoped so the mutex releases after we have rendered. // this is currently the only place the color logger is used @@ -272,9 +285,15 @@ bool CConsole::DrawSurface(void) m_lastFrameScrollPos = ImVec2(ImGui::GetScrollX(), ImGui::GetScrollY()); ImGui::EndChild(); - ImGui::PopStyleVar(numStyleVars); - ImGui::Separator(); + if (numLoggerStyleVars) + ImGui::PopStyleVar(numLoggerStyleVars); + + // The legacy theme also has a spacer here. + if (isLegacyStyle) + ImGui::Separator(); + + ImGui::Text("%s", m_summaryTextBuf); const std::function fnHandleInput = [&](void) {