Fix console autocomplete window not padding elements correctly when size is between the clamped values

This commit is contained in:
Kawe Mazidjatari 2022-08-31 13:00:02 +02:00
parent 1f41f3c9d0
commit eca922d3df
2 changed files with 24 additions and 9 deletions

View File

@ -263,15 +263,7 @@ void CConsole::DrawSurface(void)
m_bReclaimFocus = false;
}
float nPad = 0.f;
if (m_vSuggest.size() > 1)
{
// Pad with 18 to keep all items in view.
nPad = ImGui::GetItemRectSize().y - 3;
}
m_ivSuggestWindowPos = ImGui::GetItemRectMin();
m_ivSuggestWindowPos.y += ImGui::GetItemRectSize().y;
m_ivSuggestWindowSize = ImVec2(600, nPad + std::clamp(static_cast<float>(m_vSuggest.size()) * fontSize.y, 37.0f, 127.5f));
BuildSuggestPanelRect();
ImGui::SameLine();
if (ImGui::Button("Submit"))
@ -611,6 +603,27 @@ void CConsole::BuildSummary(string svConVar)
}
}
//-----------------------------------------------------------------------------
// Purpose: builds the suggestion panel rect
//-----------------------------------------------------------------------------
void CConsole::BuildSuggestPanelRect(void)
{
float flSinglePadding = 0.f;
float flItemHeight = ImGui::GetTextLineHeightWithSpacing() + 1.0f;
if (m_vSuggest.size() > 1)
{
// Pad with 18 to keep all items in view.
flSinglePadding = flItemHeight;
}
m_ivSuggestWindowPos = ImGui::GetItemRectMin();
m_ivSuggestWindowPos.y += ImGui::GetItemRectSize().y;
float flWindowHeight = flSinglePadding + std::clamp(static_cast<float>(m_vSuggest.size()) * (flItemHeight), 37.0f, 127.5f);
m_ivSuggestWindowSize = ImVec2(600, flWindowHeight);
}
//-----------------------------------------------------------------------------
// Purpose: clamps the size of the log vector
//-----------------------------------------------------------------------------

View File

@ -31,7 +31,9 @@ private:
void FindFromPartial(void);
void ProcessCommand(const char* pszCommand);
void BuildSummary(string svConVar = "");
void BuildSuggestPanelRect(void);
void ClampLogSize(void);
void ClampHistorySize(void);