FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust
#2358: stopwatches in the Essential Graphics panel animate layer properties
irgendwasmitfelixa0a75e728e34
diff --git a/crates/ui-egui/src/panels/graphics.rs b/crates/ui-egui/src/panels/graphics.rsindex 1b9e5438c..ad1f180ca 100644--- a/crates/ui-egui/src/panels/graphics.rs+++ b/crates/ui-egui/src/panels/graphics.rs@@ -1198,6 +1198,8 @@ fn color32(c: [f32; 4]) -> Color32 {struct Ctx<'a> {clip: ClipId,layer: usize,+ /// The layer's index in the clip's effect list (what `effects.toggleAnimation` addresses).+ eidx: usize,e: &'a EffectInstance,mt: Tick,t: Tokens,@@ -1245,12 +1247,37 @@ impl Ctx<'_> {);(r, v)}+ /// The stopwatch in front of an animatable property's label (#2358): turns keyframing on or+ /// off at the playhead, like the one in Effect Controls. While a property animates, changing+ /// it here adds or updates a keyframe at the playhead instead of changing it everywhere. A+ /// Type-tool selection edits the selected characters, which have no keyframes: no stopwatch.+ fn stopwatch(&mut self, ui: &egui::Ui, row: Rect, id: &str) {+ let animatable = self.e.def().and_then(|d| d.param(id)).is_some_and(|d| d.animatable);+ if !animatable || (self.range.is_some() && char_style_key(id).is_some()) {+ return;+ }+ let animated = self.e.params.get(id).is_some_and(|p| p.is_animated());+ let sw = Rect::from_center_size(pos2(row.min.x + 8.0, row.center().y), vec2(12.0, 12.0));+ let resp = ui.interact(sw.expand(2.0), egui::Id::new(("gfxsw", self.clip.0, self.layer, id)), Sense::click()).on_hover_text(tl!("Toggle animation"));+ let tint = if animated {+ self.t.accent+ } else if resp.hovered() {+ self.t.text+ } else {+ self.t.text_faint+ };+ icons::paint(ui.painter(), sw, Icon::Stopwatch, tint);+ self.autos.push((format!("graphics.prop.{id}.stopwatch"), sw, "Toggle animation".to_string()));+ if resp.clicked() {+ self.actions.push(("effects.toggleAnimation".into(), json!({"clip": self.clip.0, "effect": self.eidx, "param": id})));+ }+ }fn number(&mut self, ui: &mut egui::Ui, label: &str, id: &str, speed: f64, range: (f64, f64), dec: usize, unit: &str) {let v = pv(self.e, id, self.mt).as_f64().unwrap_or(0.0);let (r, mut vui) = self.row(ui, label);let (resp, nv) = crate::widgets::hot_number(&mut vui, egui::Id::new(("gfxp", self.clip.0, self.layer, id)), v, speed, range, dec, unit, &self.t);self.auto(id, resp.rect, label);- let _ = r;+ self.stopwatch(ui, r, id);if let Some(nv) = nv {self.set(id, json!(nv));}@@ -1265,7 +1292,8 @@ impl Ctx<'_> {}fn point(&mut self, ui: &mut egui::Ui, label: &str, id: &str) {let v = pv(self.e, id, self.mt).as_vec2().unwrap_or_default();- let (_, mut vui) = self.row(ui, label);+ let (r, mut vui) = self.row(ui, label);+ self.stopwatch(ui, r, id);let (rx, nx) = crate::widgets::hot_number(&mut vui,egui::Id::new(("gfxp", self.clip.0, self.layer, id, "x")),@@ -1565,7 +1593,7 @@ pub fn properties(app: &mut FilmcraftApp, ui: &mut egui::Ui, rect: Rect) {let ch = |b: usize| text.get(..b.min(text.len())).map_or(0, |s| s.chars().count());Some((ch(ed.caret.min(ed.anchor)), ch(ed.caret.max(ed.anchor))))});- let mut cx = Ctx { clip, layer: l, e, mt, t, actions: Vec::new(), autos: Vec::new(), range };+ let mut cx = Ctx { clip, layer: l, eidx: idx[l], e, mt, t, actions: Vec::new(), autos: Vec::new(), range };if section(ui, app, "Responsive Design - Position", &t) {crate::panels::graphics_templates::responsive_position(app, ui, clip, &it, l, &mut cx.autos, &mut cx.actions);}diff --git a/crates/ui-egui/tests/graphics_ui.rs b/crates/ui-egui/tests/graphics_ui.rsindex c7aa5138e..d560d20c5 100644--- a/crates/ui-egui/tests/graphics_ui.rs+++ b/crates/ui-egui/tests/graphics_ui.rs@@ -230,3 +230,58 @@ fn shadow_color_drag_is_one_undo_step() {d.exec("edit.undo", json!({}));assert_eq!(color(&mut d), before, "one undo restores the original color");}++/// The Properties panel's stopwatches animate a layer property (#2358): Tracking (letter+/// spacing) gets keyframes from the Essential Graphics panel itself, a change at another time+/// adds a keyframe there instead of changing the value everywhere, and the stopwatch turns+/// keyframing off again.+#[test]+fn the_tracking_stopwatch_animates_letter_spacing() {+ let mut d = Driver::demo();+ d.ok("ui.set", json!({"workspace": "Captions and Graphics"}));+ d.exec("playhead.set", json!({"seconds": 0.0}));+ let r = d.exec("graphics.newText", json!({"text": "Title", "seconds": 4}));+ let clip = r["clip"].as_u64().unwrap();+ d.exec("graphics.selectLayer", json!({"clip": clip, "layers": [0]}));+ d.frames(4);+ for _ in 0..20 {+ if d.rect("graphics.prop.tracking")[1] < 800.0 {+ break;+ }+ d.ok("ui.scroll", json!({"id": "graphics.prop.scale", "dy": -200.0}));+ d.frames(2);+ }+ let keys = |d: &mut Driver| -> Vec<(i64, f64)> {+ let s = &d.harness.state().session;+ let (_, it) = s.active_sequence().unwrap().find_item(filmcraft_project::ClipId(clip)).unwrap();+ let e = it.effects.iter().find(|e| e.effect == "graphic_text").unwrap();+ e.params.get("tracking").map(|p| p.keyframes.iter().map(|k| (k.time.0, k.value.as_f64().unwrap())).collect()).unwrap_or_default()+ };+ assert!(keys(&mut d).is_empty());+ d.ok("ui.click", json!({"id": "graphics.prop.tracking.stopwatch"}));+ d.frames(2);+ assert_eq!(keys(&mut d).len(), 1, "the stopwatch sets a keyframe at the playhead");+ // two seconds later, drag the Tracking number: a second keyframe, the first stays+ d.exec("playhead.set", json!({"seconds": 2.0}));+ d.frames(2);+ let n = d.rect("graphics.prop.tracking");+ let (cx, cy) = (n[0] + n[2] / 2.0, n[1] + n[3] / 2.0);+ d.ok("ui.drag", json!({"from": {"x": cx, "y": cy}, "to": {"x": cx + 60.0, "y": cy}, "steps": 6}));+ d.frames(4);+ let k = keys(&mut d);+ assert_eq!(k.len(), 2, "{k:?}");+ assert_eq!(k[0].1, 0.0, "the first keyframe keeps its value: {k:?}");+ assert!(k[1].1 > 10.0, "the new keyframe has the dragged value: {k:?}");+ // letter spacing now animates: halfway between the keyframes the value is in between+ let mid = {+ let s = &d.harness.state().session;+ let (_, it) = s.active_sequence().unwrap().find_item(filmcraft_project::ClipId(clip)).unwrap();+ let e = it.effects.iter().find(|e| e.effect == "graphic_text").unwrap();+ e.param("tracking").unwrap().value_at(filmcraft_time::Tick((k[0].0 + k[1].0) / 2)).as_f64().unwrap()+ };+ assert!(mid > 0.0 && mid < k[1].1, "{mid} between 0 and {}", k[1].1);+ d.ok("ui.click", json!({"id": "graphics.prop.tracking.stopwatch"}));+ d.frames(2);+ assert!(keys(&mut d).is_empty(), "the stopwatch turns keyframing off");+ d.shot("tracking-stopwatch");+}diff --git a/docs/graphics.md b/docs/graphics.mdindex cacf61732..61030d146 100644--- a/docs/graphics.md+++ b/docs/graphics.md@@ -13,7 +13,10 @@ kerning and ligatures, bidi, line breaking, all drawn as vectors in linear light- Its **layers** are effect instances `graphic_text` / `graphic_shape` in the clip's effect list,in paint order (first = back). They are hidden from the Effects panel. Because they are effectinstances they save with the project, take keyframes on every animatable property (Source Text- keyframes hold), appear in Effect Controls and copy with the clip. Standard effects on a graphic+ keyframes hold), appear in Effect Controls and copy with the clip. The Essential Graphics+ panel's number and point properties (Tracking, Leading, Font Size, Position, Opacity…) carry+ the same stopwatch as Effect Controls (`graphics.prop.<id>.stopwatch`, #2358): once a property+ animates, changing it in the panel adds or updates a keyframe at the playhead. Standard effects on a graphicclip apply to the composed graphic; Motion and Opacity apply last.- `filmcraft_project::graphic::eval_layer` evaluates a layer at a time into a `LayerSpec`.- Projects with graphics need no schema migration: everything is additive (new item kind, new