FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust
Timeline: fit a new empty sequence again when its first clip arrives
storybored379883e2caaa421
diff --git a/crates/ui-egui/src/panels/timeline.rs b/crates/ui-egui/src/panels/timeline.rsindex 11f327e4f..a49c409d5 100644--- a/crates/ui-egui/src/panels/timeline.rs+++ b/crates/ui-egui/src/panels/timeline.rs@@ -171,13 +171,21 @@ pub fn show(app: &mut FilmcraftApp, ui: &mut egui::Ui, rect: Rect) {// ---- sequence tabs strip (top-left header block)// ---- animated zoom / scroll+ let empty = seq.duration().seconds() <= 0.0;let dur_s = seq.duration().seconds().max(1.0);{let v = &mut app.ui.timeline;+ if let Some(p) = v.fit_empty+ && (!empty || v.target_pps != p)+ {+ v.fit_pending |= v.target_pps == p;+ v.fit_empty = None;+ }if v.fit_pending && content.width() > 50.0 {v.target_pps = (content.width() as f64 * 0.94 / dur_s).clamp(0.05, 24_000.0);v.target_scroll = 0.0;v.fit_pending = false;+ v.fit_empty = empty.then_some(v.target_pps);}let k = 1.0 - (-dt * 20.0).exp();let zooming = (v.pps - v.target_pps).abs() / v.target_pps > 0.001;diff --git a/crates/ui-egui/src/state.rs b/crates/ui-egui/src/state.rsindex 42a61fb39..401e6cc0c 100644--- a/crates/ui-egui/src/state.rs+++ b/crates/ui-egui/src/state.rs@@ -190,6 +190,10 @@ pub struct TimelineView {/// Follow playhead during playback (page scroll).pub follow: bool,pub fit_pending: bool,+ /// The zoom a fit gave an empty sequence (which fits its 1 s minimum): the first clip to arrive+ /// fits again, unless the zoom was changed in between.+ #[serde(skip)]+ pub fit_empty: Option<f64>,/// Audio tracks showing track keyframes instead of clip keyframes: track id → lane/// (`volume`, `pan`, `mute`, `send.<i>.level`, `fx.<slot>.<param>`).#[serde(default)]@@ -213,6 +217,7 @@ impl Default for TimelineView {show_waveforms: true,follow: true,fit_pending: true,+ fit_empty: None,track_lanes: Default::default(),}}diff --git a/crates/ui-egui/tests/sequence_ui.rs b/crates/ui-egui/tests/sequence_ui.rsindex 9ef4be9f8..853f4cda8 100644--- a/crates/ui-egui/tests/sequence_ui.rs+++ b/crates/ui-egui/tests/sequence_ui.rs@@ -155,3 +155,49 @@ fn shift_semicolon_goes_to_the_next_gap() {let want = d.exec("playhead.set", json!({"frame": 48}))["time"].clone();assert_eq!(ph, want);}++fn first_movie(v: &Value) -> Option<u64> {+ match v {+ Value::Object(m) => {+ if let Some(id) = m.get("item").and_then(Value::as_u64)+ && m.get("type").and_then(Value::as_str) == Some("Movie")+ {+ return Some(id);+ }+ m.values().find_map(first_movie)+ }+ Value::Array(a) => a.iter().find_map(first_movie),+ _ => None,+ }+}++/// On-screen x of a clip's in and out edges in the timeline (not clipped to the panel).+fn clip_span(d: &mut Driver, clip: u64) -> (f64, f64) {+ let x = |d: &mut Driver, edge: &str| d.ok("ui.timeline.locate", json!({"clip": clip, "edge": edge}))["x"].as_f64().expect("x");+ (x(d, "in"), x(d, "out"))+}++#[test]+fn new_empty_sequence_fits_its_first_clip() {+ let mut d = Driver::demo();+ let project = d.exec("project.inspect", json!({}));+ let item = first_movie(&project).expect("a movie in the demo project");+ // an empty sequence fits its 1 s minimum; the clip placed into it afterwards is fitted again+ d.exec("file.newSequence", json!({"name": "Empty"}));+ d.frames(30);+ let clip = d.exec("timeline.place", json!({"item": item, "track": "V1", "seconds": 0}))["clips"][0].as_u64().expect("clip");+ d.frames(60);+ let (x_in, x_out) = clip_span(&mut d, clip);+ assert!(x_out < 1600.0 && x_out - x_in > 500.0, "clip spans x {x_in}..{x_out}: not fitted to the 1600 px window");++ // a zoom chosen while the sequence is still empty is kept+ d.exec("file.newSequence", json!({"name": "Zoomed"}));+ d.frames(30);+ d.ok("ui.set", json!({"timeline": {"pps": 300.0}}));+ d.frames(30);+ let clip = d.exec("timeline.place", json!({"item": item, "track": "V1", "seconds": 0}))["clips"][0].as_u64().expect("clip");+ d.frames(60);+ let secs = d.exec("sequence.inspect", json!({}))["video"][0]["items"][0]["duration"].as_f64().expect("duration") / 254_016_000_000.0;+ let (x_in, x_out) = clip_span(&mut d, clip);+ assert!(((x_out - x_in) - (secs * 300.0 - 4.0)).abs() < 2.0, "zoom not kept: {} px for {secs} s at 300 px/s", x_out - x_in);+}