Skip to content

FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust

Merge pull request #1526 from marcoarnulfo/fix/timeline-fourth-video-track

Brandon Thomas1c7aa2195775
diff --cc crates/ui-egui/src/panels/timeline.rs
index f5b3ab070,3c513a675..88ee963fd
--- a/crates/ui-egui/src/panels/timeline.rs
+++ b/crates/ui-egui/src/panels/timeline.rs
@@@ -3219,44 -3209,42 +3227,82 @@@ mod new_track_tests
assert_eq!(at(y), None, "y = {y}");
}
}
+
+ /// #1522: when the video tracks fill the video area, scrolling all the way up still leaves a
+ /// track's height of empty space above the top one, so a drop there can add a fourth track.
+ #[test]
+ fn a_full_video_area_scrolls_to_space_for_a_new_track() {
+ let mut p = Project::new("t");
+ let id = p.new_sequence("s", SequenceSettings::default(), 3, 1, None);
+ let seq = p.sequence(id).cloned().expect("sequence");
+ // video area 0..150 holds V1..V3 exactly; scrolled up as far as it goes
+ let area = Rect::from_min_max(pos2(0.0, 0.0), pos2(800.0, 150.0));
+ let mut v_scroll = f32::MAX;
+ let (tops, _) = video_row_tops(area, 3, 50.0, &mut v_scroll);
+ let rows = seq
+ .video_tracks
+ .iter()
+ .zip(&tops)
+ .enumerate()
+ .map(|(index, (t, &y0))| Row {
+ track: t.id,
+ kind: TrackKind::Video,
+ index,
+ rect: Rect::from_min_max(pos2(0.0, y0), pos2(800.0, y0 + 50.0)),
+ lane: false,
+ })
+ .collect();
+ let layout = Layout {
+ content: Rect::from_min_max(pos2(0.0, 0.0), pos2(800.0, 500.0)),
+ ruler: Rect::from_min_max(pos2(0.0, -20.0), pos2(800.0, 0.0)),
+ rows,
+ pps: 100.0,
+ scroll: 0.0,
+ split_y: 150.0,
+ };
+ assert_eq!(new_track_at(&seq, &layout, 10.0, 50.0, 50.0), Some((TrackKind::Video, Rect::from_min_max(pos2(0.0, 0.0), pos2(800.0, 50.0)))));
+ // scrolled to the bottom, V1..V3 fill the area as before
+ let mut v_scroll = 0.0;
+ assert_eq!(video_row_tops(area, 3, 50.0, &mut v_scroll).0, vec![100.0, 50.0, 0.0]);
+ }
}
+
+#[cfg(test)]
+mod ruler_tests {
+ use super::ruler_steps;
+
+ /// Every combination keeps both minimums and has the tick stride divide the label stride.
+ #[test]
+ fn labels_sit_on_evenly_spaced_ticks() {
+ for base in [24, 25, 30, 50, 60, 120] {
+ for frame_px in [0.05, 0.1, 0.25, 0.5, 1.0, 2.5, 8.0, 20.0, 400.0] {
+ let (minor, label) = ruler_steps(frame_px, base);
+ let what = format!("{base} fps at {frame_px} pt a frame: tick {minor}, label {label}");
+ assert!(minor >= 1, "{what}");
+ assert_eq!(label % minor, 0, "every label must fall on a tick: {what}");
+ assert!(minor as f64 * frame_px >= 12.0 || minor == label, "ticks at least 12 pt apart: {what}");
+ assert!(label as f64 * frame_px >= 110.0, "labels at least 110 pt apart: {what}");
+ }
+ }
+ }
+
+ /// At 24 fps and 100 pt a second the ruler labels every 2 s, with evenly spaced ticks between.
+ #[test]
+ fn a_24_fps_view_at_100_pt_a_second_labels_every_two_seconds() {
+ let (minor, label) = ruler_steps(100.0 / 24.0, 24);
+ assert_eq!(label, 48, "2 s at 24 fps");
+ assert_eq!(label % minor, 0);
+ assert!(minor as f64 * (100.0 / 24.0) >= 12.0);
+ }
+
+ /// Degenerate inputs still give non-zero strides that divide.
+ #[test]
+ fn damaged_rates_give_usable_strides() {
+ for frame_px in [f64::NAN, f64::INFINITY, 0.0, -1.0] {
+ let (minor, label) = ruler_steps(frame_px, 24);
+ assert!(minor >= 1 && label >= 1 && label % minor == 0, "{frame_px} pt a frame: tick {minor}, label {label}");
+ }
+ let (minor, label) = ruler_steps(1.0, i64::MAX);
+ assert!(minor >= 1 && label >= 1 && label % minor == 0, "an unrepresentable rate: tick {minor}, label {label}");
+ }
+}