From 4be2e88292222a90ddf80e76ece258bed9a40b2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Gr=C3=A9goire?= Date: Tue, 9 Sep 2025 15:18:01 +0200 Subject: [PATCH] Rework the way the cropper computes its sizes and position - No long assumes timelines are on the left of the window - Derive circle size from cropper width --- profiler/src/profiler/TracyView.hpp | 2 +- .../src/profiler/TracyView_ZoneTimeline.cpp | 26 ++++++++++--------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/profiler/src/profiler/TracyView.hpp b/profiler/src/profiler/TracyView.hpp index 3090fc9c..23f308ed 100644 --- a/profiler/src/profiler/TracyView.hpp +++ b/profiler/src/profiler/TracyView.hpp @@ -253,7 +253,7 @@ private: void DrawTimeline(); void DrawSampleList( const TimelineContext& ctx, const std::vector& drawList, const Vector& vec, int offset ); void DrawZoneList( const TimelineContext& ctx, const std::vector& drawList, int offset, uint64_t tid, int maxDepth, double margin ); - void DrawThreadCropper( const int depth, const uint64_t tid, const float xPos, const float yPos, const float ostep, const float radius, const float margin, const bool hasCtxSwitches ); + void DrawThreadCropper( const int depth, const uint64_t tid, const float xPos, const float yPos, const float ostep, const float cropperWidth, const bool hasCtxSwitches ); void DrawContextSwitchList( const TimelineContext& ctx, const std::vector& drawList, const Vector& ctxSwitch, int offset, int endOffset, bool isFiber ); int DispatchGpuZoneLevel( const Vector>& vec, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset, int depth, uint64_t thread, float yMin, float yMax, int64_t begin, int drift ); template diff --git a/profiler/src/profiler/TracyView_ZoneTimeline.cpp b/profiler/src/profiler/TracyView_ZoneTimeline.cpp index 6bd9d2de..7cdac674 100644 --- a/profiler/src/profiler/TracyView_ZoneTimeline.cpp +++ b/profiler/src/profiler/TracyView_ZoneTimeline.cpp @@ -57,21 +57,21 @@ void View::DrawThread( const TimelineContext& ctx, const ThreadData& thread, con } const auto yPos = wpos.y + offset; - const float cropperWidth = ImGui::CalcTextSize( ICON_FA_CARET_DOWN ).x; - const float cropperCircleRadius = ( cropperWidth - 2.0f * GetScale() ) / 2.0f ; - const float cropperAdditionalMargin = cropperWidth + wpos.x; // We add the left window margin for symmetry - + const auto* drawList = ImGui::GetWindowDrawList(); + const float croppperPosX = wpos.x; + const float cropperWidth = ImGui::CalcTextSize( ICON_FA_CARET_DOWN ).x + 2.0f * GetScale(); + const float cropperAdditionalMargin = cropperWidth + ImGui::GetStyle().WindowBorderSize; // We add the left window margin for symmetry + // Display cropper if currently limited or if hovering the cropper area const auto threadDepthLimitIt = m_threadDepthLimit.find( thread.id ); const bool croppingActive = ( threadDepthLimitIt != m_threadDepthLimit.end() && threadDepthLimitIt->second <= depth ); const int croppedDepth = croppingActive ? threadDepthLimitIt->second : depth; - const bool mouseInCropperDisplayZone = ctx.hover && ImGui::GetMousePos().x >= wpos.x && ImGui::GetMousePos().x < wpos.x + cropperAdditionalMargin && ImGui::GetMousePos().y > ctx.yMin && ImGui::GetMousePos().y < ctx.yMax; + const bool mouseInCropperDisplayZone = ctx.hover && ImGui::GetMousePos().x >= croppperPosX && ImGui::GetMousePos().x < croppperPosX + cropperWidth && ImGui::GetMousePos().y > ctx.yMin && ImGui::GetMousePos().y < ctx.yMax; const bool displayCropper = croppingActive || mouseInCropperDisplayZone; if( displayCropper ) { - const auto* drawList = ImGui::GetWindowDrawList(); - ImGui::PushClipRect( drawList->GetClipRectMin() + ImVec2( cropperAdditionalMargin, 0 ), drawList->GetClipRectMax(), true ); + ImGui::PushClipRect( ImVec2( croppperPosX + cropperAdditionalMargin, drawList->GetClipRectMin().y ), drawList->GetClipRectMax(), true ); } if( !draw.empty() && yPos <= yMax && yPos + ostep * croppedDepth >= yMin ) { @@ -99,7 +99,7 @@ void View::DrawThread( const TimelineContext& ctx, const ThreadData& thread, con if( displayCropper ) { ImGui::PopClipRect(); - if( depth > 0 ) DrawThreadCropper( depth, thread.id, wpos.x, yPos, ostep, cropperCircleRadius, cropperWidth, hasCtxSwitch ); + if( depth > 0 ) DrawThreadCropper( depth, thread.id, croppperPosX, yPos, ostep, cropperWidth, hasCtxSwitch ); } } @@ -605,7 +605,7 @@ void View::DrawZoneList( const TimelineContext& ctx, const std::vectorAddCircle( center, hradius, 0xFFFFFFFF, 0, GetScale() ); + draw->AddCircle( center, hradius, 0xFFFFFFFF, 0, hoverCircleThickness ); const float wPosX = ImGui::GetWindowPos().x + ImGui::GetWindowContentRegionMin().x; const float wSizeX = ImGui::GetWindowContentRegionMax().x; draw->AddLine( ImVec2( wPosX, yPos + ( lane + 1 ) * ostep ), ImVec2( wPosX + wSizeX, yPos + ( lane + 1 ) * ostep ), 0x880000FF, 2.0f * GetScale() ); @@ -664,7 +666,7 @@ void View::DrawThreadCropper( const int depth, const uint64_t tid, const float x { color = 0xFF888888; } - draw->AddCircleFilled( center, radius, color ); + draw->AddCircleFilled( center, circleRadius, color ); } }