Auto-scroll message list to bottom.

This commit is contained in:
Bartosz Taudul 2019-07-13 01:25:37 +02:00
parent bcecd6e3a6
commit 387674a40a
2 changed files with 22 additions and 1 deletions

View File

@ -105,6 +105,7 @@ View::View( const char* addr, ImFont* fixedWidth, ImFont* bigFont, SetTitleCallb
, m_staticView( false ) , m_staticView( false )
, m_pause( false ) , m_pause( false )
, m_frames( nullptr ) , m_frames( nullptr )
, m_messagesScrollBottom( true )
, m_textEditorFont( fixedWidth ) , m_textEditorFont( fixedWidth )
, m_bigFont( bigFont ) , m_bigFont( bigFont )
, m_stcb( stcb ) , m_stcb( stcb )
@ -120,6 +121,7 @@ View::View( FileRead& f, ImFont* fixedWidth, ImFont* bigFont, SetTitleCallback s
, m_staticView( true ) , m_staticView( true )
, m_pause( true ) , m_pause( true )
, m_frames( m_worker.GetFramesBase() ) , m_frames( m_worker.GetFramesBase() )
, m_messagesScrollBottom( false )
, m_textEditorFont( fixedWidth ) , m_textEditorFont( fixedWidth )
, m_bigFont( bigFont ) , m_bigFont( bigFont )
, m_stcb( stcb ) , m_stcb( stcb )
@ -5756,7 +5758,8 @@ void View::DrawMessages()
ImGui::NextColumn(); ImGui::NextColumn();
ImGui::Separator(); ImGui::Separator();
for( const auto& v : m_worker.GetMessages() ) const auto& msgs = m_worker.GetMessages();
for( const auto& v : msgs )
{ {
if( VisibleMsgThread( v->thread ) ) if( VisibleMsgThread( v->thread ) )
{ {
@ -5786,6 +5789,22 @@ void View::DrawMessages()
ImGui::NextColumn(); ImGui::NextColumn();
} }
} }
const auto maxScroll = ImGui::GetScrollMaxY();
if( maxScroll != 0 )
{
const auto msgssize = msgs.size();
if( m_prevMessages == msgssize )
{
m_messagesScrollBottom = ImGui::GetScrollY() == maxScroll;
}
else
{
m_prevMessages = msgssize;
if( m_messagesScrollBottom ) ImGui::SetScrollHereY();
}
}
ImGui::EndColumns(); ImGui::EndColumns();
ImGui::EndChild(); ImGui::EndChild();
ImGui::End(); ImGui::End();

View File

@ -265,6 +265,8 @@ private:
uint32_t m_lockInfoWindow = InvalidId; uint32_t m_lockInfoWindow = InvalidId;
ZoneEvent* m_zoneHover = nullptr; ZoneEvent* m_zoneHover = nullptr;
int m_frameHover = -1; int m_frameHover = -1;
bool m_messagesScrollBottom;
size_t m_prevMessages = 0;
Region m_highlight; Region m_highlight;
Region m_highlightZoom; Region m_highlightZoom;