From 1af7bef86fb66089fac6d6adb8f6002ca9a14c3c Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sun, 11 Oct 2026 21:34:55 +0200 Subject: [PATCH] Extract shared section lane tooltip and interaction handlers. --- .../src/profiler/TracyView_FrameTimeline.cpp | 58 +++++++++---------- 1 file changed, 28 insertions(+), 30 deletions(-) diff --git a/profiler/src/profiler/TracyView_FrameTimeline.cpp b/profiler/src/profiler/TracyView_FrameTimeline.cpp index 56a9bf7e..2fa7fce8 100644 --- a/profiler/src/profiler/TracyView_FrameTimeline.cpp +++ b/profiler/src/profiler/TracyView_FrameTimeline.cpp @@ -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;