Extract shared section lane tooltip and interaction handlers.

This commit is contained in:
Bartosz Taudul
2026-10-11 21:34:55 +02:00
parent da10087fe9
commit 1af7bef86f

View File

@@ -441,6 +441,30 @@ void View::DrawTimelineSections()
const auto nspx = 1.0 / pxns;
const auto MinVisNs = int64_t( round( GetScale() * MinVisSize * nspx ) );
auto Interact = [this]( int64_t s, int64_t e )
{
if( IsMouseClickReleased( ImGuiMouseButton_Right ) ) m_setRangePopup = RangeSlim { s, e, true };
if( IsMouseClicked( ImGuiMouseButton_Middle ) )
{
ZoomToRange( s, e );
}
};
auto SectionTooltip = [this, &Interact]( const char* name, int64_t s, int64_t e, uint16_t category )
{
ImGui::BeginTooltip();
TextFocused( "Section:", name );
if( m_worker.GetSectionDescriptions().size() > 1 )
{
TextFocused( "Category:", m_worker.GetSectionCategoryDescription( category ) );
}
ImGui::Separator();
TextFocused( "Execution time:", TimeToString( e - s ) );
TextFocused( "Time from start of program:", TimeToStringExact( s ) );
ImGui::EndTooltip();
Interact( s, e );
};
int rowidx = 0;
for( auto& row : rows )
{
@@ -495,32 +519,18 @@ void View::DrawTimelineSections()
if( hover && ImGui::IsMouseHoveringRect( wpos + ImVec2( std::max( px0, -10.0 ), offset ), wpos + ImVec2( std::min( std::max( pr1, px0 + MinVisSize ), double( w + 10 ) ), offset + ty + 1 ) ) )
{
ImGui::BeginTooltip();
if( count > 1 )
{
ImGui::BeginTooltip();
TextFocused( "Sections too small to display:", RealToString( count ) );
ImGui::Separator();
TextFocused( "Execution time:", TimeToString( groupEnd - start ) );
ImGui::EndTooltip();
if( IsMouseClickReleased( ImGuiMouseButton_Right ) ) m_setRangePopup = RangeSlim { start, groupEnd, true };
if( IsMouseClicked( ImGuiMouseButton_Middle ) ) ZoomToRange( start, groupEnd );
Interact( start, groupEnd );
}
else
{
const char* name = m_worker.GetString( v.text );
TextFocused( "Section:", name );
if( m_worker.GetSectionDescriptions().size() > 1 )
{
TextFocused( "Category:", m_worker.GetSectionCategoryDescription( entry.category ) );
}
ImGui::Separator();
TextFocused( "Execution time:", TimeToString( end - start ) );
TextFocused( "Time from start of program:", TimeToStringExact( start ) );
ImGui::EndTooltip();
if( IsMouseClickReleased( ImGuiMouseButton_Right ) ) m_setRangePopup = RangeSlim { start, end, true };
if( IsMouseClicked( ImGuiMouseButton_Middle ) ) ZoomToRange( start, end );
SectionTooltip( m_worker.GetString( v.text ), start, end, entry.category );
}
}
@@ -566,19 +576,7 @@ void View::DrawTimelineSections()
if( hover && ImGui::IsMouseHoveringRect( wpos + ImVec2( px0, offset ), wpos + ImVec2( px1, offset + ty + 1 ) ) )
{
ImGui::BeginTooltip();
TextFocused( "Section:", name );
if( m_worker.GetSectionDescriptions().size() > 1 )
{
TextFocused( "Category:", m_worker.GetSectionCategoryDescription( entry.category ) );
}
ImGui::Separator();
TextFocused( "Execution time:", TimeToString( end - start ) );
TextFocused( "Time from start of program:", TimeToStringExact( start ) );
ImGui::EndTooltip();
if( IsMouseClickReleased( ImGuiMouseButton_Right ) ) m_setRangePopup = RangeSlim { start, end, true };
if( IsMouseClicked( ImGuiMouseButton_Middle ) ) ZoomToRange( start, end );
SectionTooltip( name, start, end, entry.category );
}
++i;