Skip to content

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

#1487: a Graphics tab edit writes keyframed text where it is shown

irgendwasmitfelix3d16f9323fa4
diff --git a/crates/ui-egui/src/panels/text.rs b/crates/ui-egui/src/panels/text.rs
index f1325aac3..b6eaca3c9 100644
--- a/crates/ui-egui/src/panels/text.rs
+++ b/crates/ui-egui/src/panels/text.rs
@@ -296,6 +296,10 @@ pub struct GraphicText {
/// The layer's own name, when it has one.
pub name: Option<String>,
pub text: String,
+ /// The timeline time the text was read at (the playhead, or the clip's start when the
+ /// playhead is outside the clip): an edit is written there, so keyframed text changes the
+ /// value that is shown.
+ pub at: filmcraft_time::Tick,
}
/// Every text layer of every graphic clip in `seq`, in timeline order (then lower tracks first,
@@ -318,7 +322,7 @@ pub fn graphic_texts(seq: &filmcraft_project::Sequence, at: filmcraft_time::Tick
Some(filmcraft_project::ParamValue::Text(n)) if !n.trim().is_empty() => Some(n),
_ => None,
};
- out.push((ti, GraphicText { clip: it.id, layer, start: it.start, track: format!("V{}", ti + 1), name, text }));
+ out.push((ti, GraphicText { clip: it.id, layer, start: it.start, track: format!("V{}", ti + 1), name, text, at: t }));
}
}
}
@@ -415,7 +419,7 @@ fn graphics(app: &mut FilmcraftApp, ui: &mut egui::Ui, rect: Rect) {
ui.data_mut(|d| d.remove::<String>(tkey));
}
if resp.lost_focus() && buf != g.text {
- actions.push(("graphics.set".into(), json!({"clip": g.clip.0, "layer": g.layer, "props": {"text": buf}})));
+ actions.push(("graphics.set".into(), json!({"clip": g.clip.0, "layer": g.layer, "props": {"text": buf}, "time": g.at.0})));
}
});
});
diff --git a/crates/ui-egui/tests/graphics_ui.rs b/crates/ui-egui/tests/graphics_ui.rs
index 0352cf5bd..69bf19880 100644
--- a/crates/ui-egui/tests/graphics_ui.rs
+++ b/crates/ui-egui/tests/graphics_ui.rs
@@ -282,3 +282,35 @@ fn the_text_panels_graphics_tab_lists_and_edits_graphic_text() {
assert_eq!(rows(&mut d), ["Night Drive", "Closing credits"]);
d.shot("text-panel-graphics");
}
+
+/// Keyframed text: the Graphics tab shows a clip's text at the clip's start when the playhead is
+/// past the clip, and an edit is written there (not at the clip's last frame), so the value shown
+/// is the one that changes.
+#[test]
+fn a_graphics_tab_edit_writes_keyframed_text_where_it_is_shown() {
+ let mut d = Driver::demo();
+ d.ok("ui.set", json!({"workspace": "Captions and Graphics"}));
+ d.exec("playhead.set", json!({"seconds": 1.0}));
+ let clip = d.exec("graphics.newText", json!({"text": "Start", "seconds": 2}))["clip"].as_u64().unwrap();
+ let it = d.harness.state().session.active_sequence().unwrap().find_item(filmcraft_project::ClipId(clip)).unwrap().1.clone();
+ // animate the text: "Start" at the clip's start, "End" near its end
+ d.exec("effects.toggleAnimation", json!({"clip": clip, "effect": "graphic_text", "param": "text"}));
+ let late = it.start.0 + (it.duration.0 * 9) / 10;
+ d.exec("graphics.set", json!({"clip": clip, "layer": 0, "props": {"text": "End"}, "time": late}));
+ // the playhead past the clip: the row shows the start's text
+ d.exec("playhead.set", json!({"seconds": 10.0}));
+ d.ok("ui.click", json!({"id": "text.tab.Graphics"}));
+ d.frames(3);
+ d.ok("ui.click", json!({"id": format!("text.graphics.{clip}.0.text")}));
+ d.ok("ui.key", json!({"key": "A", "command": true}));
+ d.ok("ui.type", json!({"text": "Edited"}));
+ d.ok("ui.click", json!({"id": "text.graphics.search"}));
+ d.frames(3);
+ let at = |d: &mut Driver, t: i64| {
+ let it = d.harness.state().session.active_sequence().unwrap().find_item(filmcraft_project::ClipId(clip)).unwrap().1.clone();
+ let mt = it.effect_time_at(filmcraft_time::Tick(t));
+ it.effects.iter().find(|e| e.effect == "graphic_text").unwrap().param("text").unwrap().value_at(mt)
+ };
+ assert_eq!(at(&mut d, it.start.0), filmcraft_project::ParamValue::Text("Edited".into()), "the shown (start) value changed");
+ assert_eq!(at(&mut d, late), filmcraft_project::ParamValue::Text("End".into()), "the end keeps its own");
+}