From db6acfe9b54883485590b63e7a7d524e9a1a53d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toma=C5=BE=20V=C3=B6r=C3=B6=C5=A1?= Date: Sun, 18 Dec 2022 20:06:10 +0100 Subject: [PATCH 1/6] Change resize logic such that TimelineItem instances "don't chase" each other anymore. --- server/TracyTimelineItem.cpp | 49 +++++++++++++----------------------- server/TracyTimelineItem.hpp | 2 -- 2 files changed, 17 insertions(+), 34 deletions(-) diff --git a/server/TracyTimelineItem.cpp b/server/TracyTimelineItem.cpp index ca1d9dc7..6a2184be 100644 --- a/server/TracyTimelineItem.cpp +++ b/server/TracyTimelineItem.cpp @@ -12,7 +12,6 @@ TimelineItem::TimelineItem( View& view, Worker& worker ) : m_visible( true ) , m_showFull( true ) , m_height( 0 ) - , m_offset( 0 ) , m_view( view ) , m_worker( worker ) { @@ -22,8 +21,8 @@ void TimelineItem::Draw( bool firstFrame, double pxns, int& offset, const ImVec2 { if( !IsVisible() ) { - m_height = 0; - m_offset = 0; + if( m_height != 0 ) + AdjustThreadHeight( firstFrame, offset, offset ); return; } if( IsEmpty() ) return; @@ -31,7 +30,7 @@ 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 = AdjustThreadPosition( wpos.y, offset ); + const auto yPos = wpos.y + offset; const auto dpos = wpos + ImVec2( 0.5f, 0.5f ); const auto oldOffset = offset; auto draw = ImGui::GetWindowDrawList(); @@ -44,9 +43,8 @@ void TimelineItem::Draw( bool firstFrame, double pxns, int& offset, const ImVec2 { if( !DrawContents( pxns, offset, wpos, hover, yMin, yMax ) && !m_view.GetViewData().drawEmptyLabels ) { - m_height = 0; - m_offset = 0; offset = oldOffset; + AdjustThreadHeight( firstFrame, oldOffset, offset ); ImGui::PopClipRect(); ImGui::PopID(); return; @@ -123,44 +121,31 @@ void TimelineItem::Draw( bool firstFrame, double pxns, int& offset, const ImVec2 void TimelineItem::AdjustThreadHeight( bool firstFrame, int oldOffset, int& offset ) { + const auto speed = 10.0; + const auto minMove = 2.0; + const auto h = offset - oldOffset; - if( m_height > h ) + if( firstFrame ) { m_height = h; - offset = oldOffset + m_height; } - else if( m_height < h ) + else if( m_height != h ) { - if( firstFrame ) + const auto diff = h - m_height; + const auto preClampMove = diff * speed * ImGui::GetIO().DeltaTime; + if( diff > 0 ) { - m_height = h; - offset = oldOffset + h; + const auto move = std::max( minMove, preClampMove ); + m_height = int( std::min( m_height + move, h ) ); } else { - const auto diff = h - m_height; - const auto move = std::max( 2.0, diff * 10.0 * ImGui::GetIO().DeltaTime ); - m_height = int( std::min( m_height + move, h ) ); - offset = oldOffset + m_height; - s_wasActive = true; + const auto move = std::min( -minMove, preClampMove ); + m_height = int( std::max( m_height + move, h ) ); } - } -} - -float TimelineItem::AdjustThreadPosition( float wy, int& offset ) -{ - if( m_offset < offset ) - { - m_offset = offset; - } - else if( m_offset > offset ) - { - const auto diff = m_offset - offset; - const auto move = std::max( 2.0, diff * 10.0 * ImGui::GetIO().DeltaTime ); - offset = m_offset = int( std::max( m_offset - move, offset ) ); s_wasActive = true; } - return offset + wy; + offset = oldOffset + m_height; } void TimelineItem::VisibilityCheckbox() diff --git a/server/TracyTimelineItem.hpp b/server/TracyTimelineItem.hpp index c08d911a..54e154aa 100644 --- a/server/TracyTimelineItem.hpp +++ b/server/TracyTimelineItem.hpp @@ -47,10 +47,8 @@ protected: private: void AdjustThreadHeight( bool firstFrame, int oldOffset, int& offset ); - float AdjustThreadPosition( float wy, int& offset ); int m_height; - int m_offset; protected: View& m_view; From 0cc6bb4ff9c6318febac257091366547223de6c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toma=C5=BE=20V=C3=B6r=C3=B6=C5=A1?= Date: Sun, 18 Dec 2022 20:06:57 +0100 Subject: [PATCH 2/6] More pleasant TimelineItem resizing parameters. --- server/TracyTimelineItem.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/TracyTimelineItem.cpp b/server/TracyTimelineItem.cpp index 6a2184be..2d71330e 100644 --- a/server/TracyTimelineItem.cpp +++ b/server/TracyTimelineItem.cpp @@ -121,8 +121,8 @@ void TimelineItem::Draw( bool firstFrame, double pxns, int& offset, const ImVec2 void TimelineItem::AdjustThreadHeight( bool firstFrame, int oldOffset, int& offset ) { - const auto speed = 10.0; - const auto minMove = 2.0; + const auto speed = 5.0; + const auto minMove = 1.0; const auto h = offset - oldOffset; if( firstFrame ) From d6772900add761b54fd9b316f033fdbd722ef7ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toma=C5=BE=20V=C3=B6r=C3=B6=C5=A1?= Date: Sun, 18 Dec 2022 20:09:15 +0100 Subject: [PATCH 3/6] Get rid of a non-linearity in TimelineItem resizing animation. --- server/TracyTimelineItem.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/server/TracyTimelineItem.cpp b/server/TracyTimelineItem.cpp index 2d71330e..498ea205 100644 --- a/server/TracyTimelineItem.cpp +++ b/server/TracyTimelineItem.cpp @@ -121,8 +121,8 @@ void TimelineItem::Draw( bool firstFrame, double pxns, int& offset, const ImVec2 void TimelineItem::AdjustThreadHeight( bool firstFrame, int oldOffset, int& offset ) { - const auto speed = 5.0; - const auto minMove = 1.0; + const auto speed = 4.0; + const auto baseMove = 1.0; const auto h = offset - oldOffset; if( firstFrame ) @@ -135,12 +135,12 @@ void TimelineItem::AdjustThreadHeight( bool firstFrame, int oldOffset, int& offs const auto preClampMove = diff * speed * ImGui::GetIO().DeltaTime; if( diff > 0 ) { - const auto move = std::max( minMove, preClampMove ); + const auto move = preClampMove + baseMove; m_height = int( std::min( m_height + move, h ) ); } else { - const auto move = std::min( -minMove, preClampMove ); + const auto move = preClampMove - baseMove; m_height = int( std::max( m_height + move, h ) ); } s_wasActive = true; From e4ab6cdaf1928ae80abb4d362f5ed642f461f390 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toma=C5=BE=20V=C3=B6r=C3=B6=C5=A1?= Date: Sun, 18 Dec 2022 20:45:05 +0100 Subject: [PATCH 4/6] Fix TimelineController height calculation. --- server/TracyTimelineController.cpp | 12 +----------- server/TracyTimelineController.hpp | 1 - server/TracyView_Timeline.cpp | 1 + 3 files changed, 2 insertions(+), 12 deletions(-) diff --git a/server/TracyTimelineController.cpp b/server/TracyTimelineController.cpp index 7cabd444..296a0e88 100644 --- a/server/TracyTimelineController.cpp +++ b/server/TracyTimelineController.cpp @@ -7,7 +7,6 @@ namespace tracy TimelineController::TimelineController( View& view, Worker& worker ) : m_height( 0 ) - , m_scroll( 0 ) , m_firstFrame( true ) , m_view( view ) , m_worker( worker ) @@ -31,16 +30,7 @@ void TimelineController::End( double pxns, int offset, const ImVec2& wpos, bool item->Draw( m_firstFrame, pxns, offset, wpos, hover, yMin, yMax ); } - const auto scrollPos = ImGui::GetScrollY(); - if( scrollPos == 0 && m_scroll != 0 ) - { - m_height = 0; - } - else - { - if( offset > m_height ) m_height = offset; - } - m_scroll = scrollPos; + m_height = offset; } } diff --git a/server/TracyTimelineController.hpp b/server/TracyTimelineController.hpp index 1d8e4f37..58f9bb15 100644 --- a/server/TracyTimelineController.hpp +++ b/server/TracyTimelineController.hpp @@ -43,7 +43,6 @@ private: unordered_flat_map> m_itemMap; float m_height; - float m_scroll; bool m_firstFrame; diff --git a/server/TracyView_Timeline.cpp b/server/TracyView_Timeline.cpp index d7a3f996..406a945b 100644 --- a/server/TracyView_Timeline.cpp +++ b/server/TracyView_Timeline.cpp @@ -333,6 +333,7 @@ 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 b4e8e042a8d687366a1fec8060f61cf75b5986a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toma=C5=BE=20V=C3=B6r=C3=B6=C5=A1?= Date: Sun, 18 Dec 2022 23:30:47 +0100 Subject: [PATCH 5/6] Fix a code style issue. --- server/TracyTimelineItem.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/server/TracyTimelineItem.cpp b/server/TracyTimelineItem.cpp index 498ea205..747be77b 100644 --- a/server/TracyTimelineItem.cpp +++ b/server/TracyTimelineItem.cpp @@ -21,8 +21,7 @@ void TimelineItem::Draw( bool firstFrame, double pxns, int& offset, const ImVec2 { if( !IsVisible() ) { - if( m_height != 0 ) - AdjustThreadHeight( firstFrame, offset, offset ); + if( m_height != 0 ) AdjustThreadHeight( firstFrame, offset, offset ); return; } if( IsEmpty() ) return; From 1969ef0f43580ead5f397d45a1ce606984abe065 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toma=C5=BE=20V=C3=B6r=C3=B6=C5=A1?= Date: Sun, 18 Dec 2022 23:40:03 +0100 Subject: [PATCH 6/6] Reintroduce the vertical scroll-bar reset logic in TimelineController. --- server/TracyTimelineController.cpp | 8 +++++++- server/TracyTimelineController.hpp | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/server/TracyTimelineController.cpp b/server/TracyTimelineController.cpp index 296a0e88..e7efe3f3 100644 --- a/server/TracyTimelineController.cpp +++ b/server/TracyTimelineController.cpp @@ -7,6 +7,7 @@ namespace tracy TimelineController::TimelineController( View& view, Worker& worker ) : m_height( 0 ) + , m_scroll( 0 ) , m_firstFrame( true ) , m_view( view ) , m_worker( worker ) @@ -30,7 +31,12 @@ void TimelineController::End( double pxns, int offset, const ImVec2& wpos, bool item->Draw( m_firstFrame, pxns, offset, wpos, hover, yMin, yMax ); } - m_height = offset; + const auto scrollPos = ImGui::GetScrollY(); + if( ( scrollPos == 0 && m_scroll != 0 ) || offset > m_height ) + { + m_height = offset; + } + m_scroll = scrollPos; } } diff --git a/server/TracyTimelineController.hpp b/server/TracyTimelineController.hpp index 58f9bb15..1d8e4f37 100644 --- a/server/TracyTimelineController.hpp +++ b/server/TracyTimelineController.hpp @@ -43,6 +43,7 @@ private: unordered_flat_map> m_itemMap; float m_height; + float m_scroll; bool m_firstFrame;