Skip to content

Commit

Permalink
Adjust timecode track height dynamically (#75)
Browse files Browse the repository at this point in the history
Signed-off-by: TrevorAyl <37515792+TrevorAyl@users.noreply.github.com>
  • Loading branch information
TrevorAyl authored and Jspada200ilm committed Oct 1, 2024
1 parent 2432f70 commit 75a333d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@


build
.vscode
.vscode
*.DS_Store
22 changes: 21 additions & 1 deletion app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions app.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions timeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 75a333d

Please sign in to comment.