From 7b9b8104211b5afb8465f22aded0282d4c96eda8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toma=C5=BE=20V=C3=B6r=C3=B6=C5=A1?= Date: Fri, 27 Jan 2023 20:00:05 +0100 Subject: [PATCH 1/6] Refactor the use of offset in TimelineItem::Draw() and TimelineController::End(). --- server/TracyTimelineController.cpp | 11 +++++--- server/TracyTimelineController.hpp | 2 +- server/TracyTimelineItem.cpp | 43 +++++++++++++++--------------- server/TracyTimelineItem.hpp | 8 ++++-- server/TracyView_Timeline.cpp | 3 +-- 5 files changed, 37 insertions(+), 30 deletions(-) diff --git a/server/TracyTimelineController.cpp b/server/TracyTimelineController.cpp index e7efe3f3..f0e0b648 100644 --- a/server/TracyTimelineController.cpp +++ b/server/TracyTimelineController.cpp @@ -24,17 +24,20 @@ void TimelineController::Begin() m_items.clear(); } -void TimelineController::End( double pxns, int offset, const ImVec2& wpos, bool hover, float yMin, float yMax ) +void TimelineController::End( double pxns, const ImVec2& wpos, bool hover, float yMin, float yMax ) { + int yOffset = 0; + for( auto& item : m_items ) { - item->Draw( m_firstFrame, pxns, offset, wpos, hover, yMin, yMax ); + item->Draw( m_firstFrame, pxns, yOffset, wpos, hover, yMin, yMax ); + yOffset += item->GetNextFrameHeight(); } const auto scrollPos = ImGui::GetScrollY(); - if( ( scrollPos == 0 && m_scroll != 0 ) || offset > m_height ) + if( ( scrollPos == 0 && m_scroll != 0 ) || yOffset > m_height ) { - m_height = offset; + m_height = yOffset; } m_scroll = scrollPos; } diff --git a/server/TracyTimelineController.hpp b/server/TracyTimelineController.hpp index 1d8e4f37..eb9e0af6 100644 --- a/server/TracyTimelineController.hpp +++ b/server/TracyTimelineController.hpp @@ -18,7 +18,7 @@ public: void FirstFrameExpired(); void Begin(); - void End( double pxns, int offset, const ImVec2& wpos, bool hover, float yMin, float yMax ); + void End( double pxns, const ImVec2& wpos, bool hover, float yMin, float yMax ); template void AddItem( U* data ) diff --git a/server/TracyTimelineItem.cpp b/server/TracyTimelineItem.cpp index 747be77b..54ac5ff6 100644 --- a/server/TracyTimelineItem.cpp +++ b/server/TracyTimelineItem.cpp @@ -17,11 +17,14 @@ TimelineItem::TimelineItem( View& view, Worker& worker ) { } -void TimelineItem::Draw( bool firstFrame, double pxns, int& offset, const ImVec2& wpos, bool hover, float yMin, float yMax ) +void TimelineItem::Draw( bool firstFrame, double pxns, int yOffset, const ImVec2& wpos, bool hover, float yMin, float yMax ) { + const auto yBegin = yOffset; + auto yEnd = yOffset; + if( !IsVisible() ) { - if( m_height != 0 ) AdjustThreadHeight( firstFrame, offset, offset ); + if( m_height != 0 ) AdjustThreadHeight( firstFrame, yBegin, yEnd ); return; } if( IsEmpty() ) return; @@ -29,32 +32,31 @@ void TimelineItem::Draw( bool firstFrame, double pxns, int& offset, const ImVec2 const auto w = ImGui::GetContentRegionAvail().x - 1; const auto ty = ImGui::GetTextLineHeight(); const auto ostep = ty + 1; - const auto yPos = wpos.y + offset; + const auto yPos = wpos.y + yBegin; const auto dpos = wpos + ImVec2( 0.5f, 0.5f ); - const auto oldOffset = offset; auto draw = ImGui::GetWindowDrawList(); ImGui::PushID( this ); - ImGui::PushClipRect( wpos + ImVec2( 0, offset ), wpos + ImVec2( w, offset + m_height ), true ); + ImGui::PushClipRect( wpos + ImVec2( 0, yBegin ), wpos + ImVec2( w, yBegin + m_height ), true ); - offset += ostep; + yEnd += ostep; if( m_showFull ) { - if( !DrawContents( pxns, offset, wpos, hover, yMin, yMax ) && !m_view.GetViewData().drawEmptyLabels ) + if( !DrawContents( pxns, yEnd, wpos, hover, yMin, yMax ) && !m_view.GetViewData().drawEmptyLabels ) { - offset = oldOffset; - AdjustThreadHeight( firstFrame, oldOffset, offset ); + yEnd = yBegin; + AdjustThreadHeight( firstFrame, yBegin, yEnd ); ImGui::PopClipRect(); ImGui::PopID(); return; } } - DrawOverlay( wpos + ImVec2( 0, oldOffset ), wpos + ImVec2( w, offset ) ); + DrawOverlay( wpos + ImVec2( 0, yBegin ), wpos + ImVec2( w, yEnd ) ); ImGui::PopClipRect(); float labelWidth; - const auto hdrOffset = oldOffset; + const auto hdrOffset = yBegin; const bool drawHeader = yPos + ty >= yMin && yPos <= yMax; if( drawHeader ) { @@ -112,39 +114,38 @@ void TimelineItem::Draw( bool firstFrame, double pxns, int& offset, const ImVec2 ImGui::EndPopup(); } - offset += 0.2f * ostep; - AdjustThreadHeight( firstFrame, oldOffset, offset ); + yEnd += 0.2f * ostep; + AdjustThreadHeight( firstFrame, yBegin, yEnd ); ImGui::PopID(); } -void TimelineItem::AdjustThreadHeight( bool firstFrame, int oldOffset, int& offset ) +void TimelineItem::AdjustThreadHeight( bool firstFrame, int yBegin, int yEnd ) { const auto speed = 4.0; const auto baseMove = 1.0; - const auto h = offset - oldOffset; + const auto newHeight = yEnd - yBegin; if( firstFrame ) { - m_height = h; + m_height = newHeight; } - else if( m_height != h ) + else if( m_height != newHeight ) { - const auto diff = h - m_height; + const auto diff = newHeight - m_height; const auto preClampMove = diff * speed * ImGui::GetIO().DeltaTime; if( diff > 0 ) { const auto move = preClampMove + baseMove; - m_height = int( std::min( m_height + move, h ) ); + m_height = int( std::min( m_height + move, newHeight ) ); } else { const auto move = preClampMove - baseMove; - m_height = int( std::max( m_height + move, h ) ); + m_height = int( std::max( m_height + move, newHeight ) ); } s_wasActive = true; } - offset = oldOffset + m_height; } void TimelineItem::VisibilityCheckbox() diff --git a/server/TracyTimelineItem.hpp b/server/TracyTimelineItem.hpp index 54e154aa..78a2725c 100644 --- a/server/TracyTimelineItem.hpp +++ b/server/TracyTimelineItem.hpp @@ -17,7 +17,8 @@ public: TimelineItem( View& view, Worker& worker ); virtual ~TimelineItem() = default; - void Draw( bool firstFrame, double pxns, int& offset, const ImVec2& wpos, bool hover, float yMin, float yMax ); + // draws the timeilne item and also updates the next frame height value + void Draw( bool firstFrame, double pxns, int yOffset, const ImVec2& wpos, bool hover, float yMin, float yMax ); void VisibilityCheckbox(); virtual void SetVisible( bool visible ) { m_visible = visible; } @@ -25,6 +26,9 @@ public: void SetShowFull( bool showFull ) { m_showFull = showFull; } + // returns 0 instead of the correct value for the first frame + int GetNextFrameHeight() const { return m_height; } + protected: virtual uint32_t HeaderColor() const = 0; virtual uint32_t HeaderColorInactive() const = 0; @@ -46,7 +50,7 @@ protected: bool m_showFull; private: - void AdjustThreadHeight( bool firstFrame, int oldOffset, int& offset ); + void AdjustThreadHeight( bool firstFrame, int yBegin, int yEnd ); int m_height; diff --git a/server/TracyView_Timeline.cpp b/server/TracyView_Timeline.cpp index 406a945b..cc656955 100644 --- a/server/TracyView_Timeline.cpp +++ b/server/TracyView_Timeline.cpp @@ -341,7 +341,6 @@ void View::DrawTimeline() draw = ImGui::GetWindowDrawList(); const auto ty = ImGui::GetTextLineHeight(); - int offset = 0; const auto to = 9.f; const auto th = ( ty - to ) * sqrt( 3 ) * 0.5; @@ -381,7 +380,7 @@ void View::DrawTimeline() } } - m_tc.End( pxns, offset, wpos, hover, yMin, yMax ); + m_tc.End( pxns, wpos, hover, yMin, yMax ); ImGui::EndChild(); m_lockHighlight = m_nextLockHighlight; From 2df56e9941d40bfea8624cdbb684f777e70dec9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toma=C5=BE=20V=C3=B6r=C3=B6=C5=A1?= Date: Fri, 27 Jan 2023 20:00:05 +0100 Subject: [PATCH 2/6] Fix off-by-one-frame in timeline item height. --- server/TracyTimelineController.cpp | 4 +++- server/TracyView_Timeline.cpp | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/server/TracyTimelineController.cpp b/server/TracyTimelineController.cpp index f0e0b648..2badc31c 100644 --- a/server/TracyTimelineController.cpp +++ b/server/TracyTimelineController.cpp @@ -30,8 +30,10 @@ void TimelineController::End( double pxns, const ImVec2& wpos, bool hover, float for( auto& item : m_items ) { + auto currentFrameItemHeight = item->GetNextFrameHeight(); item->Draw( m_firstFrame, pxns, yOffset, wpos, hover, yMin, yMax ); - yOffset += item->GetNextFrameHeight(); + if( m_firstFrame ) currentFrameItemHeight = item->GetNextFrameHeight(); + yOffset += currentFrameItemHeight; } const auto scrollPos = ImGui::GetScrollY(); diff --git a/server/TracyView_Timeline.cpp b/server/TracyView_Timeline.cpp index cc656955..eddba3d0 100644 --- a/server/TracyView_Timeline.cpp +++ b/server/TracyView_Timeline.cpp @@ -321,6 +321,7 @@ void View::DrawTimeline() const auto yMin = ImGui::GetCursorScreenPos().y; const auto yMax = linepos.y + lineh; + ImGui::SetNextWindowContentSize( ImVec2( 0, m_tc.GetHeight() ) ); ImGui::BeginChild( "##zoneWin", ImVec2( ImGui::GetContentRegionAvail().x, ImGui::GetContentRegionAvail().y ), false, ImGuiWindowFlags_AlwaysVerticalScrollbar | ImGuiWindowFlags_NoScrollWithMouse ); if( m_yDelta != 0 ) @@ -333,7 +334,6 @@ void View::DrawTimeline() const auto wpos = ImGui::GetCursorScreenPos(); const auto dpos = wpos + ImVec2( 0.5f, 0.5f ); - // note that m_tc.GetHeight() returns the height from the previous draw const auto h = std::max( m_tc.GetHeight(), ImGui::GetContentRegionAvail().y - 4 ); // magic border value ImGui::ItemSize( ImVec2( w, h ) ); From dbefb70db33cb8dbc886b02f2ee98666030dc9dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toma=C5=BE=20V=C3=B6r=C3=B6=C5=A1?= Date: Fri, 27 Jan 2023 20:00:05 +0100 Subject: [PATCH 3/6] Add key to TimelineItem. --- server/TracyTimelineItem.cpp | 3 ++- server/TracyTimelineItem.hpp | 6 +++++- server/TracyTimelineItemCpuData.cpp | 4 ++-- server/TracyTimelineItemCpuData.hpp | 2 +- server/TracyTimelineItemGpu.cpp | 2 +- server/TracyTimelineItemPlot.cpp | 2 +- server/TracyTimelineItemThread.cpp | 2 +- 7 files changed, 13 insertions(+), 8 deletions(-) diff --git a/server/TracyTimelineItem.cpp b/server/TracyTimelineItem.cpp index 54ac5ff6..c934fb7e 100644 --- a/server/TracyTimelineItem.cpp +++ b/server/TracyTimelineItem.cpp @@ -8,10 +8,11 @@ namespace tracy { -TimelineItem::TimelineItem( View& view, Worker& worker ) +TimelineItem::TimelineItem( View& view, Worker& worker, const void* key ) : m_visible( true ) , m_showFull( true ) , m_height( 0 ) + , m_key( key ) , m_view( view ) , m_worker( worker ) { diff --git a/server/TracyTimelineItem.hpp b/server/TracyTimelineItem.hpp index 78a2725c..068bf1f1 100644 --- a/server/TracyTimelineItem.hpp +++ b/server/TracyTimelineItem.hpp @@ -14,7 +14,7 @@ class Worker; class TimelineItem { public: - TimelineItem( View& view, Worker& worker ); + TimelineItem( View& view, Worker& worker, const void* key ); virtual ~TimelineItem() = default; // draws the timeilne item and also updates the next frame height value @@ -29,6 +29,8 @@ public: // returns 0 instead of the correct value for the first frame int GetNextFrameHeight() const { return m_height; } + const void* GetKey() const { return m_key; } + protected: virtual uint32_t HeaderColor() const = 0; virtual uint32_t HeaderColorInactive() const = 0; @@ -54,6 +56,8 @@ private: int m_height; + const void* m_key; + protected: View& m_view; Worker& m_worker; diff --git a/server/TracyTimelineItemCpuData.cpp b/server/TracyTimelineItemCpuData.cpp index 9664c109..1701889f 100644 --- a/server/TracyTimelineItemCpuData.cpp +++ b/server/TracyTimelineItemCpuData.cpp @@ -8,8 +8,8 @@ namespace tracy { -TimelineItemCpuData::TimelineItemCpuData( View& view, Worker& worker, void* ) - : TimelineItem( view, worker ) +TimelineItemCpuData::TimelineItemCpuData( View& view, Worker& worker, void* key ) + : TimelineItem( view, worker, key ) { } diff --git a/server/TracyTimelineItemCpuData.hpp b/server/TracyTimelineItemCpuData.hpp index 642ba52c..399667a9 100644 --- a/server/TracyTimelineItemCpuData.hpp +++ b/server/TracyTimelineItemCpuData.hpp @@ -10,7 +10,7 @@ namespace tracy class TimelineItemCpuData final : public TimelineItem { public: - TimelineItemCpuData( View& view, Worker& worker, void* ); + TimelineItemCpuData( View& view, Worker& worker, void* key ); void SetVisible( bool visible ) override; bool IsVisible() const override; diff --git a/server/TracyTimelineItemGpu.cpp b/server/TracyTimelineItemGpu.cpp index 11506e9b..2974eb56 100644 --- a/server/TracyTimelineItemGpu.cpp +++ b/server/TracyTimelineItemGpu.cpp @@ -10,7 +10,7 @@ namespace tracy { TimelineItemGpu::TimelineItemGpu( View& view, Worker& worker, GpuCtxData* gpu ) - : TimelineItem( view, worker ) + : TimelineItem( view, worker, gpu ) , m_gpu( gpu ) , m_idx( view.GetNextGpuIdx() ) { diff --git a/server/TracyTimelineItemPlot.cpp b/server/TracyTimelineItemPlot.cpp index 07e45ef1..6580d44a 100644 --- a/server/TracyTimelineItemPlot.cpp +++ b/server/TracyTimelineItemPlot.cpp @@ -9,7 +9,7 @@ namespace tracy { TimelineItemPlot::TimelineItemPlot( View& view, Worker& worker, PlotData* plot ) - : TimelineItem( view, worker ) + : TimelineItem( view, worker, plot ) , m_plot( plot ) { } diff --git a/server/TracyTimelineItemThread.cpp b/server/TracyTimelineItemThread.cpp index c100bd5c..b0f7f785 100644 --- a/server/TracyTimelineItemThread.cpp +++ b/server/TracyTimelineItemThread.cpp @@ -12,7 +12,7 @@ namespace tracy { TimelineItemThread::TimelineItemThread( View& view, Worker& worker, const ThreadData* thread ) - : TimelineItem( view, worker ) + : TimelineItem( view, worker, thread ) , m_thread( thread ) , m_ghost( false ) { From bca8f28f43c4e0d647fe042ef3002fec91805190 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toma=C5=BE=20V=C3=B6r=C3=B6=C5=A1?= Date: Fri, 27 Jan 2023 20:00:05 +0100 Subject: [PATCH 4/6] Centering around the mouse pointer. --- server/TracyTimelineController.cpp | 89 +++++++++++++++++++++++++++++- server/TracyTimelineController.hpp | 9 ++- server/TracyView_Timeline.cpp | 4 +- 3 files changed, 97 insertions(+), 5 deletions(-) diff --git a/server/TracyTimelineController.cpp b/server/TracyTimelineController.cpp index 2badc31c..990a34df 100644 --- a/server/TracyTimelineController.cpp +++ b/server/TracyTimelineController.cpp @@ -1,3 +1,5 @@ +#include + #include "imgui.h" #include "TracyTimelineController.hpp" @@ -8,6 +10,8 @@ namespace tracy TimelineController::TimelineController( View& view, Worker& worker ) : m_height( 0 ) , m_scroll( 0 ) + , m_centerItemkey( nullptr ) + , m_centerItemOffsetY( 0 ) , m_firstFrame( true ) , m_view( view ) , m_worker( worker ) @@ -24,8 +28,83 @@ void TimelineController::Begin() m_items.clear(); } -void TimelineController::End( double pxns, const ImVec2& wpos, bool hover, float yMin, float yMax ) +void TimelineController::UpdateCenterItem() { + ImVec2 mousePos = ImGui::GetMousePos(); + + m_centerItemkey = nullptr; + m_centerItemOffsetY = 0; + + if( m_firstFrame || !ImGui::IsMousePosValid( &mousePos ) ) return; + + const auto timelineMousePosY = mousePos.y - ImGui::GetWindowPos().y; + int centerY = timelineMousePosY + ImGui::GetScrollY(); + + int yBegin = 0; + int yEnd = 0; + for( auto& item : m_items ) + { + m_centerItemkey = item->GetKey(); + yBegin = yEnd; + yEnd += item->GetNextFrameHeight(); + + const auto inLowerBounds = m_centerItemkey == m_items.front()->GetKey() || yBegin <= centerY; + const auto inUpperBounds = m_centerItemkey == m_items.back()->GetKey() || centerY < yEnd; + + if( inLowerBounds && inUpperBounds ) + { + m_centerItemOffsetY = centerY - yBegin; + break; + } + } +} + +std::optional TimelineController::CalculateScrollPosition() const +{ + if( !m_centerItemkey ) return std::nullopt; + + ImVec2 mousePos = ImGui::GetMousePos(); + + if( !ImGui::IsMousePosValid( &mousePos ) ) return std::nullopt; + + const auto timelineMousePosY = mousePos.y - ImGui::GetWindowPos().y; + + int yBegin = 0; + int yEnd = 0; + for( auto& item : m_items ) + { + yBegin = yEnd; + yEnd += item->GetNextFrameHeight(); + + if( item->GetKey() != m_centerItemkey ) continue; + + int scrollY = yBegin + m_centerItemOffsetY - timelineMousePosY; + + return scrollY; + } + + return std::nullopt; +} + +void TimelineController::End( double pxns, const ImVec2& wpos, bool hover, bool vcenter, float yMin, float yMax ) +{ + auto shouldUpdateCenterItem = [&] () { + const auto& mouseDelta = ImGui::GetIO().MouseDelta; + const auto mouseMoved = mouseDelta.x != 0.0f || mouseDelta.y != 0.0f; + const auto imguiChangedScroll = m_scroll != ImGui::GetScrollY(); + return ( ( imguiChangedScroll || mouseMoved ) && !ImGui::IsMouseDown( 1 ) ) || !m_centerItemkey; + }; + + if( !vcenter ) + { + m_centerItemkey = nullptr; + m_centerItemOffsetY = 0; + } + else if( shouldUpdateCenterItem() ) + { + UpdateCenterItem(); + } + int yOffset = 0; for( auto& item : m_items ) @@ -36,6 +115,14 @@ void TimelineController::End( double pxns, const ImVec2& wpos, bool hover, float yOffset += currentFrameItemHeight; } + if( const auto scrollY = CalculateScrollPosition() ) + { + int clampedScrollY = std::min( *scrollY, yOffset ); + ImGui::SetScrollY( clampedScrollY ); + int minHeight = ImGui::GetWindowHeight() + clampedScrollY; + yOffset = std::max( yOffset, minHeight ); + } + const auto scrollPos = ImGui::GetScrollY(); if( ( scrollPos == 0 && m_scroll != 0 ) || yOffset > m_height ) { diff --git a/server/TracyTimelineController.hpp b/server/TracyTimelineController.hpp index eb9e0af6..b14dca67 100644 --- a/server/TracyTimelineController.hpp +++ b/server/TracyTimelineController.hpp @@ -2,6 +2,7 @@ #define __TRACYTIMELINECONTROLLER_HPP__ #include +#include #include #include "../public/common/TracyForceInline.hpp" @@ -18,7 +19,7 @@ public: void FirstFrameExpired(); void Begin(); - void End( double pxns, const ImVec2& wpos, bool hover, float yMin, float yMax ); + void End( double pxns, const ImVec2& wpos, bool hover, bool vcenter, float yMin, float yMax ); template void AddItem( U* data ) @@ -39,12 +40,18 @@ public: } private: + void UpdateCenterItem(); + std::optional CalculateScrollPosition() const; + std::vector m_items; unordered_flat_map> m_itemMap; float m_height; float m_scroll; + const void* m_centerItemkey; + int m_centerItemOffsetY; + bool m_firstFrame; View& m_view; diff --git a/server/TracyView_Timeline.cpp b/server/TracyView_Timeline.cpp index eddba3d0..0b88fdd0 100644 --- a/server/TracyView_Timeline.cpp +++ b/server/TracyView_Timeline.cpp @@ -327,8 +327,6 @@ void View::DrawTimeline() if( m_yDelta != 0 ) { auto& io = ImGui::GetIO(); - auto y = ImGui::GetScrollY(); - ImGui::SetScrollY( y - m_yDelta ); io.MouseClickedPos[1].y = io.MousePos.y; } @@ -380,7 +378,7 @@ void View::DrawTimeline() } } - m_tc.End( pxns, wpos, hover, yMin, yMax ); + m_tc.End( pxns, wpos, hover, drawMouseLine && m_viewMode == ViewMode::Paused, yMin, yMax ); ImGui::EndChild(); m_lockHighlight = m_nextLockHighlight; From ea1a0299f31fc490e983836e6efb8ca7282b9dbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toma=C5=BE=20V=C3=B6r=C3=B6=C5=A1?= Date: Fri, 27 Jan 2023 20:00:05 +0100 Subject: [PATCH 5/6] Add switch for vertical centering on/off at compile-time. --- server/TracyView_Timeline.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/server/TracyView_Timeline.cpp b/server/TracyView_Timeline.cpp index 0b88fdd0..18241db6 100644 --- a/server/TracyView_Timeline.cpp +++ b/server/TracyView_Timeline.cpp @@ -324,9 +324,16 @@ void View::DrawTimeline() ImGui::SetNextWindowContentSize( ImVec2( 0, m_tc.GetHeight() ) ); ImGui::BeginChild( "##zoneWin", ImVec2( ImGui::GetContentRegionAvail().x, ImGui::GetContentRegionAvail().y ), false, ImGuiWindowFlags_AlwaysVerticalScrollbar | ImGuiWindowFlags_NoScrollWithMouse ); + const auto verticallyCenterTimeline = true; + if( m_yDelta != 0 ) { auto& io = ImGui::GetIO(); + if( !verticallyCenterTimeline ) + { + auto y = ImGui::GetScrollY(); + ImGui::SetScrollY( y - m_yDelta ); + } io.MouseClickedPos[1].y = io.MousePos.y; } @@ -378,7 +385,8 @@ void View::DrawTimeline() } } - m_tc.End( pxns, wpos, hover, drawMouseLine && m_viewMode == ViewMode::Paused, yMin, yMax ); + const auto vcenter = verticallyCenterTimeline && drawMouseLine && m_viewMode == ViewMode::Paused; + m_tc.End( pxns, wpos, hover, vcenter, yMin, yMax ); ImGui::EndChild(); m_lockHighlight = m_nextLockHighlight; From 645d53f2547b5c9c3ddee6c01a50cfe17aead60a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toma=C5=BE=20V=C3=B6r=C3=B6=C5=A1?= Date: Tue, 31 Jan 2023 20:35:17 +0100 Subject: [PATCH 6/6] More correct `shouldUpdateCenterItem`. --- server/TracyTimelineController.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/server/TracyTimelineController.cpp b/server/TracyTimelineController.cpp index 990a34df..5161fa29 100644 --- a/server/TracyTimelineController.cpp +++ b/server/TracyTimelineController.cpp @@ -89,10 +89,12 @@ std::optional TimelineController::CalculateScrollPosition() const void TimelineController::End( double pxns, const ImVec2& wpos, bool hover, bool vcenter, float yMin, float yMax ) { auto shouldUpdateCenterItem = [&] () { + const auto imguiChangedScroll = m_scroll != ImGui::GetScrollY(); const auto& mouseDelta = ImGui::GetIO().MouseDelta; const auto mouseMoved = mouseDelta.x != 0.0f || mouseDelta.y != 0.0f; - const auto imguiChangedScroll = m_scroll != ImGui::GetScrollY(); - return ( ( imguiChangedScroll || mouseMoved ) && !ImGui::IsMouseDown( 1 ) ) || !m_centerItemkey; + const auto& mousePos = ImGui::GetIO().MousePos; + const auto mouseVisible = ImGui::IsMousePosValid( &mousePos ); + return ( ( imguiChangedScroll || mouseMoved || !mouseVisible ) && !ImGui::IsMouseDown( 1 ) ) || !m_centerItemkey; }; if( !vcenter )