From 75a333dcb5e978f499685bd2aac81e2541df8d2d Mon Sep 17 00:00:00 2001 From: TrevorAyl <37515792+TrevorAyl@users.noreply.github.com> Date: Mon, 30 Sep 2024 17:20:49 +0100 Subject: [PATCH] Adjust timecode track height dynamically (#75) Signed-off-by: TrevorAyl <37515792+TrevorAyl@users.noreply.github.com> --- .gitignore | 3 ++- app.cpp | 22 +++++++++++++++++++++- app.h | 1 + timeline.cpp | 3 +++ 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index f22e2f5..1ed4f59 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ build -.vscode \ No newline at end of file +.vscode +*.DS_Store diff --git a/app.cpp b/app.cpp index adab59a..e26e4ee 100644 --- a/app.cpp +++ b/app.cpp @@ -923,7 +923,27 @@ void DetectPlayheadLimits() { void FitZoomWholeTimeline() { appState.scale = appState.timeline_width / appState.timeline->duration().to_seconds(); } - +// GUI utility to add dynamic height to GUI elements + +float CalculateDynamicHeight() { + // Get the current font size + float fontSize = ImGui::GetFontSize(); + // Get the vertical spacing from the ImGui style + float verticalSpacing = ImGui::GetStyle().ItemSpacing.y; + + // Determine how many elements are selected + int visibleElementCount = 0; + if (appState.display_timecode) visibleElementCount++; + if (appState.display_frames) visibleElementCount++; + if (appState.display_seconds) visibleElementCount++; + if (appState.display_rate) visibleElementCount++; + + // Set height based on selected elements + // Use fontSize as base height and verticalSpacing for additional height + float calculatedHeight = fontSize + (visibleElementCount - 1) * (fontSize + verticalSpacing); + // Return the maximum of calculatedHeight and the minimum height (10) + return std::max(calculatedHeight, 10.0f); +} std::string FormattedStringFromTime(otio::RationalTime time, bool allow_rate) { std::string result; if (appState.display_timecode) { diff --git a/app.h b/app.h index 02d0cf0..3c60bd0 100644 --- a/app.h +++ b/app.h @@ -142,6 +142,7 @@ void SeekPlayhead(double seconds); void SnapPlayhead(); void DetectPlayheadLimits(); void FitZoomWholeTimeline(); +float CalculateDynamicHeight(); std::string FormattedStringFromTime(otio::RationalTime time, bool allow_rate = true); std::string TimecodeStringFromTime(otio::RationalTime); std::string FramesStringFromTime(otio::RationalTime); diff --git a/timeline.cpp b/timeline.cpp index 00e1828..ccddf0e 100644 --- a/timeline.cpp +++ b/timeline.cpp @@ -887,6 +887,9 @@ bool DrawTimecodeTrack( bool interactive = true) { bool moved_playhead = false; + // Adjust track_height based on the number of visible elements + track_height = CalculateDynamicHeight(); + float width = ImGui::GetContentRegionAvail().x; ImVec2 size(fmaxf(full_width, width), track_height);