Fixed bug where auto-scrolling occasionally gets disabled

Issue happened when scrolling back, most of the time it will work, but there is always jitter in the first frame after the change which could result in ImGui::GetScrollY() <= ImGui::GetScrollMaxY() resulting in auto-scroll disable.
Only scroll back if ImGui::GetScrollY() <= ImGui::GetScrollMaxY() and always reset value of CConsole::m_nScrollBack.
This commit is contained in:
Kawe Mazidjatari 2022-06-24 18:28:26 +02:00
parent cdc32531eb
commit d7a004a0eb
3 changed files with 6 additions and 2 deletions

View File

@ -214,11 +214,12 @@ void CConsole::BasePanel(void)
m_bCopyToClipBoard = false;
}
if (m_nScrollBack > 0)
if (!m_Logger.m_bScrolledToMax && m_nScrollBack > 0)
{
ImGui::SetScrollY(ImGui::GetScrollY() - m_nScrollBack * fontSize.y);
m_nScrollBack = 0;
}
m_nScrollBack = 0;
///////////////////////////////////////////////////////////////////////
ImGui::EndChild();

View File

@ -205,6 +205,7 @@ private:
public:
bool m_bAutoScroll;
bool m_bScrollToBottom;
bool m_bScrolledToMax;
private:
bool m_bHandleKeyboardInputs;
bool m_bHandleMouseInputs;

View File

@ -28,6 +28,7 @@ CTextLogger::CTextLogger()
, m_bAutoScroll(true)
, m_bScrollToBottom(true)
, m_bScrollToCursor(false)
, m_bScrolledToMax(false)
, m_flTextStart(0.0f)
, m_nLeftMargin(0)
, m_bCursorPositionChanged(false)
@ -860,8 +861,9 @@ void CTextLogger::Render()
ImGui::Dummy(ImVec2((longest + 2), m_Lines.size() * m_CharAdvance.y));
m_bScrolledToMax = ImGui::GetScrollY() >= ImGui::GetScrollMaxY();
if (m_bScrollToBottom || (!m_bScrollToCursor && m_bAutoScroll && ImGui::GetScrollY() >= ImGui::GetScrollMaxY()))
if (m_bScrollToBottom || (!m_bScrollToCursor && m_bAutoScroll && m_bScrolledToMax))
{
ImGui::SetScrollHereY(1.0f);
m_bScrollToBottom = false;