Use clipper to render source view.

This commit is contained in:
Bartosz Taudul 2020-03-24 18:10:56 +01:00
parent 1c23d7e67a
commit a7cedddcef

View File

@ -74,6 +74,8 @@ void SourceView::Render()
ImGui::BeginChild( "##sourceView", ImVec2( 0, 0 ), true ); ImGui::BeginChild( "##sourceView", ImVec2( 0, 0 ), true );
if( m_font ) ImGui::PushFont( m_font ); if( m_font ) ImGui::PushFont( m_font );
const auto nw = ImGui::CalcTextSize( "123,345" ).x; const auto nw = ImGui::CalcTextSize( "123,345" ).x;
if( m_targetLine != 0 )
{
int lineNum = 1; int lineNum = 1;
for( auto& line : m_lines ) for( auto& line : m_lines )
{ {
@ -84,6 +86,18 @@ void SourceView::Render()
} }
RenderLine( line, lineNum++ ); RenderLine( line, lineNum++ );
} }
}
else
{
ImGuiListClipper clipper( m_lines.size() );
while( clipper.Step() )
{
for( auto i=clipper.DisplayStart; i<clipper.DisplayEnd; i++ )
{
RenderLine( m_lines[i], i+1 );
}
}
}
if( m_font ) ImGui::PopFont(); if( m_font ) ImGui::PopFont();
ImGui::EndChild(); ImGui::EndChild();
} }