@@ -57,29 +57,28 @@ 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 );
67- const bool mouseInCropperDisplayZone = ImGui::GetMousePos ().x >= 0 && ImGui::GetMousePos ().x < wpos.x + cropperAdditionalMargin && ImGui::GetMousePos ().y > ctx.yMin && ImGui::GetMousePos ().y < ctx.yMax ;
68+ const int croppedDepth = croppingActive ? threadDepthLimitIt->second : depth;
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 ;
6870
6971 const bool displayCropper = croppingActive || mouseInCropperDisplayZone;
7072 if ( displayCropper )
7173 {
72- if (depth > 0 ) depth = DrawThreadCropper ( depth, thread.id , wpos.x , yPos, ostep, cropperCircleRadius, cropperWidth, hasCtxSwitch );
73-
74- const auto * drawList = ImGui::GetWindowDrawList ();
75- ImGui::PushClipRect ( drawList->GetClipRectMin () + ImVec2 ( cropperAdditionalMargin, 0 ), drawList->GetClipRectMax (), true );
74+ ImGui::PushClipRect ( ImVec2 ( croppperPosX + cropperAdditionalMargin, drawList->GetClipRectMin ().y ), drawList->GetClipRectMax (), true );
7675 }
77- if ( !draw.empty () && yPos <= yMax && yPos + ostep * depth >= yMin )
76+ if ( !draw.empty () && yPos <= yMax && yPos + ostep * croppedDepth >= yMin )
7877 {
7978 // Only apply margin when croppingActive to avoid text moving around when mouse is getting close to the cropper widget
80- DrawZoneList ( ctx, draw, offset, thread.id , depth , croppingActive ? cropperAdditionalMargin + GetScale () /* Ensure text has a bit of space for text */ : 0 .f );
79+ DrawZoneList ( ctx, draw, offset, thread.id , croppedDepth , croppingActive ? cropperAdditionalMargin + GetScale () /* Ensure text has a bit of space for text */ : 0 .f );
8180 }
82- offset += ostep * depth ;
81+ offset += ostep * croppedDepth ;
8382
8483 if ( hasCtxSwitch && !ctxDraw.empty () )
8584 {
@@ -97,7 +96,11 @@ void View::DrawThread( const TimelineContext& ctx, const ThreadData& thread, con
9796 const auto lockDepth = DrawLocks ( ctx, lockDraw, thread.id , offset, m_nextLockHighlight );
9897 offset += sstep * lockDepth;
9998 }
100- if ( displayCropper ) ImGui::PopClipRect ();
99+ if ( displayCropper )
100+ {
101+ ImGui::PopClipRect ();
102+ if ( depth > 0 ) DrawThreadCropper ( depth, thread.id , croppperPosX, yPos, ostep, cropperWidth, hasCtxSwitch );
103+ }
101104}
102105
103106void View::DrawThreadMessagesList ( const TimelineContext& ctx, const std::vector<MessagesDraw>& drawList, int offset, uint64_t tid )
@@ -602,18 +605,19 @@ void View::DrawZoneList( const TimelineContext& ctx, const std::vector<TimelineD
602605 }
603606}
604607
605- int 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 )
606609{
607610 const ImVec2 mousePos = ImGui::GetMousePos ();
608611 const bool clicked = ImGui::IsMouseClicked ( 0 );
609612 auto draw = ImGui::GetWindowDrawList ();
610- auto foreground = ImGui::GetForegroundDrawList ();
611613 bool isCropped = ( m_threadDepthLimit.find ( tid ) != m_threadDepthLimit.end () );
612614 const int depthLimit = isCropped ? m_threadDepthLimit[tid] : depth;
613615 // If user changes settings to hide Ctx Switches, he would be unable to remove the limit, so set the value to its minimum
614616 if ( !hasCtxSwitches && isCropped && depthLimit == 0 ) m_threadDepthLimit[tid] = 1 ;
615617
616618 const float cropperCenterX = xPos + cropperWidth / 2.0 ;
619+ const float hoverCircleThickness = GetScale ();
620+ const float circleRadius = cropperWidth / 2.0 - 2 .0f * GetScale ();
617621
618622 const auto CircleCenterYForLine = [=]( int lane ){
619623 return yPos + ostep * ( lane + 0.5 );
@@ -634,14 +638,16 @@ int View::DrawThreadCropper( const int depth, const uint64_t tid, const float xP
634638 for ( ; lane < depthLimit; lane++ )
635639 {
636640 const ImVec2 center = ImVec2 ( cropperCenterX, CircleCenterYForLine ( lane ) );
637- const float hradius = radius + 2 .0f * GetScale ();
641+ const float hradius = circleRadius + 2 .0f * GetScale ();
638642 const float dx = mousePos.x - center.x ;
639643 const float dy = mousePos.y - center.y ;
640644
641645 if ( dx * dx + dy * dy <= hradius * hradius )
642646 {
643- foreground->AddCircle ( center, hradius, 0xFFFFFFFF , 0 , GetScale () );
644- foreground->AddLine ( ImVec2 ( 0 , yPos + ( lane + 1 ) * ostep ), ImVec2 ( ImGui::GetWindowSize ().x , yPos + ( lane + 1 ) * ostep ), 0x880000FF , 2 .0f * GetScale () );
647+ draw->AddCircle ( center, hradius, 0xFFFFFFFF , 0 , hoverCircleThickness );
648+ const float wPosX = ImGui::GetWindowPos ().x + ImGui::GetWindowContentRegionMin ().x ;
649+ const float wSizeX = ImGui::GetWindowContentRegionMax ().x ;
650+ draw->AddLine ( ImVec2 ( wPosX, yPos + ( lane + 1 ) * ostep ), ImVec2 ( wPosX + wSizeX, yPos + ( lane + 1 ) * ostep ), 0x880000FF , 2 .0f * GetScale () );
645651 if ( clicked )
646652 {
647653 const int newDepthLimit = lane + 1 ;
@@ -660,11 +666,8 @@ int View::DrawThreadCropper( const int depth, const uint64_t tid, const float xP
660666 {
661667 color = 0xFF888888 ;
662668 }
663- draw->AddCircleFilled ( center, radius , color );
669+ draw->AddCircleFilled ( center, circleRadius , color );
664670 }
665-
666- // Need to take the minimum as depth may be lower after panning or zooming. We however keep the limit value
667- return isCropped && depthLimit < depth ? depthLimit : depth;
668671}
669672
670673}
0 commit comments