Skip to content

Commit 4be2e88

Browse files
committed
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
1 parent d61e4ae commit 4be2e88

2 files changed

Lines changed: 15 additions & 13 deletions

File tree

profiler/src/profiler/TracyView.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ class View
253253
void DrawTimeline();
254254
void DrawSampleList( const TimelineContext& ctx, const std::vector<SamplesDraw>& drawList, const Vector<SampleData>& vec, int offset );
255255
void DrawZoneList( const TimelineContext& ctx, const std::vector<TimelineDraw>& drawList, int offset, uint64_t tid, int maxDepth, double margin );
256-
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 );
256+
void DrawThreadCropper( const int depth, const uint64_t tid, const float xPos, const float yPos, const float ostep, const float cropperWidth, const bool hasCtxSwitches );
257257
void DrawContextSwitchList( const TimelineContext& ctx, const std::vector<ContextSwitchDraw>& drawList, const Vector<ContextSwitchData>& ctxSwitch, int offset, int endOffset, bool isFiber );
258258
int DispatchGpuZoneLevel( const Vector<short_ptr<GpuEvent>>& 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 );
259259
template<typename Adapter, typename V>

profiler/src/profiler/TracyView_ZoneTimeline.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,21 +57,21 @@ void View::DrawThread( const TimelineContext& ctx, const ThreadData& thread, con
5757
}
5858

5959
const auto yPos = wpos.y + offset;
60-
const float cropperWidth = ImGui::CalcTextSize( ICON_FA_CARET_DOWN ).x;
61-
const float cropperCircleRadius = ( cropperWidth - 2.0f * GetScale() ) / 2.0f ;
62-
const float cropperAdditionalMargin = cropperWidth + wpos.x; // We add the left window margin for symmetry
63-
60+
const auto* drawList = ImGui::GetWindowDrawList();
61+
const float croppperPosX = wpos.x;
62+
const float cropperWidth = ImGui::CalcTextSize( ICON_FA_CARET_DOWN ).x + 2.0f * GetScale();
63+
const float cropperAdditionalMargin = cropperWidth + ImGui::GetStyle().WindowBorderSize; // We add the left window margin for symmetry
64+
6465
// Display cropper if currently limited or if hovering the cropper area
6566
const auto threadDepthLimitIt = m_threadDepthLimit.find( thread.id );
6667
const bool croppingActive = ( threadDepthLimitIt != m_threadDepthLimit.end() && threadDepthLimitIt->second <= depth );
6768
const int croppedDepth = croppingActive ? threadDepthLimitIt->second : depth;
68-
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;
69+
const bool mouseInCropperDisplayZone = ctx.hover && ImGui::GetMousePos().x >= croppperPosX && ImGui::GetMousePos().x < croppperPosX + cropperWidth && ImGui::GetMousePos().y > ctx.yMin && ImGui::GetMousePos().y < ctx.yMax;
6970

7071
const bool displayCropper = croppingActive || mouseInCropperDisplayZone;
7172
if( displayCropper )
7273
{
73-
const auto* drawList = ImGui::GetWindowDrawList();
74-
ImGui::PushClipRect( drawList->GetClipRectMin() + ImVec2( cropperAdditionalMargin, 0 ), drawList->GetClipRectMax(), true );
74+
ImGui::PushClipRect( ImVec2( croppperPosX + cropperAdditionalMargin, drawList->GetClipRectMin().y ), drawList->GetClipRectMax(), true );
7575
}
7676
if( !draw.empty() && yPos <= yMax && yPos + ostep * croppedDepth >= yMin )
7777
{
@@ -99,7 +99,7 @@ void View::DrawThread( const TimelineContext& ctx, const ThreadData& thread, con
9999
if( displayCropper )
100100
{
101101
ImGui::PopClipRect();
102-
if( depth > 0 ) DrawThreadCropper( depth, thread.id, wpos.x, yPos, ostep, cropperCircleRadius, cropperWidth, hasCtxSwitch );
102+
if( depth > 0 ) DrawThreadCropper( depth, thread.id, croppperPosX, yPos, ostep, cropperWidth, hasCtxSwitch );
103103
}
104104
}
105105

@@ -605,7 +605,7 @@ void View::DrawZoneList( const TimelineContext& ctx, const std::vector<TimelineD
605605
}
606606
}
607607

608-
void View::DrawThreadCropper( const int depth, const uint64_t tid, const float xPos, const float yPos, const float ostep, const float radius, const float cropperWidth, const bool hasCtxSwitches )
608+
void View::DrawThreadCropper( const int depth, const uint64_t tid, const float xPos, const float yPos, const float ostep, const float cropperWidth, const bool hasCtxSwitches )
609609
{
610610
const ImVec2 mousePos = ImGui::GetMousePos();
611611
const bool clicked = ImGui::IsMouseClicked( 0 );
@@ -616,6 +616,8 @@ void View::DrawThreadCropper( const int depth, const uint64_t tid, const float x
616616
if( !hasCtxSwitches && isCropped && depthLimit == 0 ) m_threadDepthLimit[tid] = 1;
617617

618618
const float cropperCenterX = xPos + cropperWidth / 2.0;
619+
const float hoverCircleThickness = GetScale();
620+
const float circleRadius = cropperWidth / 2.0 - 2.0f * GetScale();
619621

620622
const auto CircleCenterYForLine = [=]( int lane ){
621623
return yPos + ostep * ( lane + 0.5 );
@@ -636,13 +638,13 @@ void View::DrawThreadCropper( const int depth, const uint64_t tid, const float x
636638
for( ; lane < depthLimit; lane++ )
637639
{
638640
const ImVec2 center = ImVec2( cropperCenterX, CircleCenterYForLine( lane ) );
639-
const float hradius = radius + 2.0f * GetScale();
641+
const float hradius = circleRadius + 2.0f * GetScale();
640642
const float dx = mousePos.x - center.x;
641643
const float dy = mousePos.y - center.y;
642644

643645
if( dx * dx + dy * dy <= hradius * hradius )
644646
{
645-
draw->AddCircle( center, hradius, 0xFFFFFFFF, 0, GetScale() );
647+
draw->AddCircle( center, hradius, 0xFFFFFFFF, 0, hoverCircleThickness );
646648
const float wPosX = ImGui::GetWindowPos().x + ImGui::GetWindowContentRegionMin().x;
647649
const float wSizeX = ImGui::GetWindowContentRegionMax().x;
648650
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
664666
{
665667
color = 0xFF888888;
666668
}
667-
draw->AddCircleFilled( center, radius, color );
669+
draw->AddCircleFilled( center, circleRadius, color );
668670
}
669671
}
670672

0 commit comments

Comments
 (0)