From 6d8a82c6188af8615845b9408101b5da02ef763b 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] Add switch for vertical centering on/off at run-time. --- server/TracyView.hpp | 1 + server/TracyView_Options.cpp | 3 +++ server/TracyView_Timeline.cpp | 8 +++++++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/server/TracyView.hpp b/server/TracyView.hpp index 479c6530a4..6993dbec65 100644 --- a/server/TracyView.hpp +++ b/server/TracyView.hpp @@ -407,6 +407,7 @@ class View std::string m_filename, m_filenameStaging; bool m_staticView; ViewMode m_viewMode; + bool m_verticallyCenterTimeline = false; bool m_viewModeHeuristicTry = false; DecayValue m_forceConnectionPopup = false; uint64_t m_totalMemory; diff --git a/server/TracyView_Options.cpp b/server/TracyView_Options.cpp index 726d567e63..9ee55d3d96 100644 --- a/server/TracyView_Options.cpp +++ b/server/TracyView_Options.cpp @@ -52,6 +52,9 @@ void View::DrawOptions() SmallColorBox( 0xFFDD9900 ); ImGui::PopFont(); ImGui::Unindent(); + val = m_verticallyCenterTimeline; + ImGui::Checkbox( "Vertically center timeline", &val ); + m_verticallyCenterTimeline = val; if( m_worker.HasContextSwitches() ) { ImGui::Separator(); diff --git a/server/TracyView_Timeline.cpp b/server/TracyView_Timeline.cpp index 0b88fdd068..e4174c9ef4 100644 --- a/server/TracyView_Timeline.cpp +++ b/server/TracyView_Timeline.cpp @@ -327,6 +327,11 @@ void View::DrawTimeline() if( m_yDelta != 0 ) { auto& io = ImGui::GetIO(); + if( !m_verticallyCenterTimeline ) + { + auto y = ImGui::GetScrollY(); + ImGui::SetScrollY( y - m_yDelta ); + } io.MouseClickedPos[1].y = io.MousePos.y; } @@ -378,7 +383,8 @@ void View::DrawTimeline() } } - m_tc.End( pxns, wpos, hover, drawMouseLine && m_viewMode == ViewMode::Paused, yMin, yMax ); + const auto vcenter = m_verticallyCenterTimeline && drawMouseLine && m_viewMode == ViewMode::Paused; + m_tc.End( pxns, wpos, hover, vcenter, yMin, yMax ); ImGui::EndChild(); m_lockHighlight = m_nextLockHighlight;