Skip to content

EffectCraft: An open-source motion graphics and compositing tool written by scratch in pure Rust

Merge main into #1342; carry main's Mute/Unmute Keyframes (keys.setMuted) into the shared key_menu, gated off on locked layers like the other edits (test covers it), delete_keys keeps locked keys selected and runs main's polystar sync, keep both sides' timeline tests

bflatastic666d929b5148
diff --cc crates/engine/src/cmd/prop.rs
index b08021b66,3c9ce42b8..ceda2d34f
--- a/crates/engine/src/cmd/prop.rs
+++ b/crates/engine/src/cmd/prop.rs
@@@ -1063,11 -1077,8 +1095,12 @@@ fn delete_keys(s: &mut Session, _: &Val
s.edit("Delete Keyframes", None, |proj, st| {
let comp = proj.comp_mut(cid).ok_or(EngineError::NoComp)?;
let mut removed = 0usize;
+ let mut changed = std::collections::BTreeSet::new();
for k in &sel {
+ // A layer locked after its keys were selected keeps them (the selection stays too).
+ if comp.layer(k.layer).is_some_and(|l| l.switches.locked) {
+ continue;
+ }
if let Some(pr) = comp.layer_mut(k.layer).and_then(|l| l.props.find_mut(k.prop))
&& let Some(i) = key_at(&pr.keys, k.time)
{
@@@ -1076,9 -1087,15 +1109,15 @@@
}
pr.keys.remove(i);
removed += 1;
+ if pr.match_id == "type" {
+ changed.insert((k.layer, k.prop));
+ }
}
}
- st.selected_keys.clear();
+ st.selected_keys.retain(|k| comp.layer(k.layer).is_some_and(|l| l.switches.locked));
+ for (layer, prop) in changed {
+ sync_polystar_property(proj, st, cid, layer, prop, time)?;
+ }
// The keys actually removed: a selected key that is gone (or listed twice) isn't counted,
// so a caller can tell that a delete changed nothing.
Ok(json!(removed))
diff --cc crates/ui-egui/src/panels/timeline.rs
index b94519713,cb61e6f08..df3c9a801
--- a/crates/ui-egui/src/panels/timeline.rs
+++ b/crates/ui-egui/src/panels/timeline.rs
@@@ -4006,56 -4100,41 +4100,57 @@@ fn key_double_click(g: &mut Rw, rc: &Ro
/// The keyframe right-click menu.
fn key_context_menu(app: &mut EffectcraftApp, g: &mut Rw, rc: &RowCtx<'_>, prop: &Property, kh: &KeyHit<'_>) {
let KeyHit { k, ks, ref kresp, .. } = *kh;
- let t = g.tl.t;
let actions = &mut g.tl.actions;
let layer = rc.layer;
- let uid = &prop.uid;
+ crate::widgets::context_menu(kresp, |ui| key_menu(ui, app, layer, prop, k, ks, actions));
+}
- crate::widgets::context_menu(kresp, |ui| {
- for (lbl, cmd, params) in [
- ("Edit Value…", "keys.set", json!({"layer": layer.id.0, "prop": uid, "time": k.time.seconds()})),
- ("-", "", json!({})),
- ("Copy", "keys.copy", json!({})),
- ("Paste", "keys.paste", json!({})),
- ("-", "", json!({})),
- ("Select Equal Keyframes", "keys.selectEqual", json!({})),
- ("Select Previous Keyframes", "keys.selectPrevious", json!({})),
- ("Select Following Keyframes", "keys.selectFollowing", json!({})),
- ("-", "", json!({})),
- ("Keyframe Interpolation…", "keys.interpolation", json!({})),
- ("Keyframe Velocity…", "keys.velocity", json!({})),
- ("Toggle Hold Keyframe", "keys.toggleHold", json!({})),
- (if k.muted { "Unmute Keyframes" } else { "Mute Keyframes" }, "keys.setMuted", json!({"muted": !k.muted})),
- ("Rove Across Time", "keys.interpolation", json!({"roving": !k.roving})),
- ("-", "", json!({})),
- ("Easy Ease", "keys.easyEase", json!({})),
- ("Easy Ease In", "keys.easyEaseIn", json!({})),
- ("Easy Ease Out", "keys.easyEaseOut", json!({})),
- ("Time-Reverse Keyframes", "keys.timeReverse", json!({})),
- ("-", "", json!({})),
- ("Linear", "keys.interpolation", json!({"interpolation": "linear"})),
- ("Bezier", "keys.interpolation", json!({"interpolation": "bezier"})),
- ("Auto Bezier", "keys.interpolation", json!({"interpolation": "autoBezier"})),
- ("Select All Keyframes", "keys.selectAll", json!({})),
- ("Delete", "keys.delete", json!({})),
- ] {
- if lbl == "Select All Keyframes" {
- // Keyframe colour labels.
+/// The commands of a keyframe's right-click menu, for the Timeline and the Graph Editor alike. They act
+/// on the selected keys, so a menu opened on an unselected key selects it first. A locked layer's keys
+/// can still be copied and selected, but not edited.
+pub(crate) fn key_menu(
+ ui: &mut egui::Ui,
+ app: &EffectcraftApp,
+ layer: &Layer,
+ prop: &Property,
+ k: &effectcraft_engine::keyframe::Keyframe,
+ selected: bool,
+ actions: &mut Vec<(String, serde_json::Value)>,
+) {
+ let t = app.tokens;
+ let locked = layer.switches.locked;
+ let uid = &prop.uid;
+ let this_key = json!({"layer": layer.id.0, "prop": uid, "time": k.time.seconds()});
+ for (lbl, cmd, params) in [
+ ("Edit Value…", "keys.set", this_key.clone()),
+ ("-", "", json!({})),
+ ("Copy", "keys.copy", json!({})),
+ ("Paste", "keys.paste", json!({})),
+ ("-", "", json!({})),
+ ("Select Equal Keyframes", "keys.selectEqual", json!({})),
+ ("Select Previous Keyframes", "keys.selectPrevious", json!({})),
+ ("Select Following Keyframes", "keys.selectFollowing", json!({})),
+ ("-", "", json!({})),
+ ("Keyframe Interpolation…", "keys.interpolation", json!({})),
+ ("Keyframe Velocity…", "keys.velocity", json!({})),
+ ("Toggle Hold Keyframe", "keys.toggleHold", json!({})),
++ (if k.muted { "Unmute Keyframes" } else { "Mute Keyframes" }, "keys.setMuted", json!({"muted": !k.muted})),
+ ("Rove Across Time", "keys.interpolation", json!({"roving": !k.roving})),
+ ("-", "", json!({})),
+ ("Easy Ease", "keys.easyEase", json!({})),
+ ("Easy Ease In", "keys.easyEaseIn", json!({})),
+ ("Easy Ease Out", "keys.easyEaseOut", json!({})),
+ ("Time-Reverse Keyframes", "keys.timeReverse", json!({})),
+ ("-", "", json!({})),
+ ("Linear", "keys.interpolation", json!({"interpolation": "linear"})),
+ ("Bezier", "keys.interpolation", json!({"interpolation": "bezier"})),
+ ("Auto Bezier", "keys.interpolation", json!({"interpolation": "autoBezier"})),
+ ("Select All Keyframes", "keys.selectAll", json!({})),
+ ("Delete", "keys.delete", json!({})),
+ ] {
+ if lbl == "Select All Keyframes" {
+ // Keyframe colour labels.
+ ui.add_enabled_ui(!locked, |ui| {
ui.menu_button(crate::i18n::tr("Label"), |ui| {
for (i, l) in effectcraft_engine::color::Label::ALL.into_iter().enumerate() {
if widgets::label_entry(ui, l, &app.session.prefs.label_name(l), k.label as usize == i, &t).clicked() {
diff --cc crates/ui-egui/src/panels/timeline/tests.rs
index c46699eeb,9a5c89f7d..3263a14ed
--- a/crates/ui-egui/src/panels/timeline/tests.rs
+++ b/crates/ui-egui/src/panels/timeline/tests.rs
@@@ -535,82 -540,13 +540,93 @@@ fn disk_bar_range_covers_partial_frames
let above_limit = TMap { start: 100_001.0, ..tm };
assert_eq!(disk_bar_range(&above_limit, clip, 1.0, i64::MAX), 100_000..100_000);
}
+
+/// The keyframe menu is one for the Timeline and the Graph Editor: its commands are drawn in the
+/// interface language, and a locked layer's keys can be copied and selected but not edited.
+#[test]
+fn the_key_menu_is_translated_and_cannot_edit_a_locked_layers_keys() {
+ use egui_kittest::Harness;
+ use egui_kittest::kittest::{NodeT, Queryable};
+ let mut s = effectcraft_engine::Session::default();
+ s.execute("comp.new", json!({"name": "C", "width": 64, "height": 64, "duration": 2})).unwrap();
+ let id = s.execute("layer.newSolid", json!({"name": "Box", "color": "#fff"})).unwrap()["layer"].as_u64().unwrap();
+ for (t, v) in [(0.0, 0), (1.0, 50)] {
+ s.execute("prop.addKey", json!({"layer": id, "path": "transform/opacity", "time": t, "value": v})).unwrap();
+ }
+ let app = EffectcraftApp::new(s);
+ let layer = app.session.active_comp().unwrap().layer(LayerId(id)).unwrap().clone();
+ let prop = layer.props.prop("transform/opacity").unwrap().clone();
+ let key = prop.keys[0].clone();
+ let enabled = |locked: bool, selected: bool, label: &str| {
+ let mut layer = layer.clone();
+ layer.switches.locked = locked;
+ let mut actions = vec![];
+ let mut h = Harness::new_ui(|ui| key_menu(ui, &app, &layer, &prop, &key, selected, &mut actions));
+ h.run();
+ !h.get_by_label(label).accesskit_node().is_disabled()
+ };
+ for label in
- ["Copy", "Select Equal Keyframes", "Select All Keyframes", "Delete", "Edit Value…", "Easy Ease", "Time-Reverse Keyframes", "Keyframe Velocity…"]
++ ["Copy", "Select Equal Keyframes", "Select All Keyframes", "Delete", "Edit Value…", "Easy Ease", "Time-Reverse Keyframes", "Keyframe Velocity…", "Mute Keyframes"]
+ {
+ assert!(enabled(false, true, label), "{label} on an unlocked layer");
+ }
+ for label in ["Copy", "Select Equal Keyframes", "Select All Keyframes"] {
+ assert!(enabled(true, true, label), "{label} is still available on a locked layer");
+ }
- for label in ["Delete", "Edit Value…", "Easy Ease", "Time-Reverse Keyframes", "Keyframe Velocity…", "Linear"] {
++ for label in ["Delete", "Edit Value…", "Easy Ease", "Time-Reverse Keyframes", "Keyframe Velocity…", "Mute Keyframes", "Linear"] {
+ assert!(!enabled(true, true, label), "{label} is off on a locked layer");
+ assert!(!enabled(true, false, label), "{label} is off on an unselected locked key");
+ }
+ for label in ["Copy", "Select Equal Keyframes", "Select Previous Keyframes", "Select Following Keyframes"] {
+ assert!(!enabled(true, false, label), "{label} requires selecting the clicked key");
+ }
+ assert!(enabled(true, false, "Select All Keyframes"));
+ // The labels follow the interface language.
+ crate::i18n::set_current("es");
+ let copy = crate::i18n::context_item("keys.copy", &json!({}), "Copy");
+ assert_ne!(copy, "Copy", "the catalog translates Copy");
+ assert!(enabled(false, true, &copy));
+ crate::i18n::set_current("en");
+}
+
+#[test]
+fn a_key_menu_edit_selects_the_clicked_key_before_applying_the_command() {
+ use egui_kittest::{Harness, kittest::Queryable};
+ let mut s = effectcraft_engine::Session::default();
+ s.execute("comp.new", json!({"width": 64, "height": 64, "duration": 2})).unwrap();
+ let id = s.execute("layer.newSolid", json!({"color": "#fff"})).unwrap()["layer"].as_u64().unwrap();
+ for (time, value) in [(0.0, 0), (1.0, 50)] {
+ s.execute("prop.addKey", json!({"layer": id, "path": "transform/opacity", "time": time, "value": value})).unwrap();
+ }
+ let layer = s.active_comp().unwrap().layer(LayerId(id)).unwrap().clone();
+ let prop = layer.props.prop("transform/opacity").unwrap().clone();
+ s.execute("keys.select", json!({"keys": [{"layer": id, "prop": prop.uid, "time": 1.0}]})).unwrap();
+ let mut app = EffectcraftApp::new(s);
+ let mut actions = vec![];
+ {
+ let mut h = Harness::new_ui(|ui| key_menu(ui, &app, &layer, &prop, &prop.keys[0], false, &mut actions));
+ h.run();
+ h.get_by_label("Easy Ease").click();
+ h.run();
+ }
+ assert_eq!(actions.iter().map(|(command, _)| command.as_str()).collect::<Vec<_>>(), ["keys.select", "keys.easyEase"]);
+ for (command, params) in actions {
+ app.session.execute(&command, params).unwrap();
+ }
+ let keys = &app.session.active_comp().unwrap().layer(LayerId(id)).unwrap().props.find(prop.uid).unwrap().keys;
+ assert_ne!(keys[0], prop.keys[0], "the clicked key was eased");
+ assert_eq!(keys[1], prop.keys[1], "the previously selected key was not edited");
+ assert_eq!(app.session.state.selected_keys.len(), 1);
+ assert_eq!(app.session.state.selected_keys[0].time, prop.keys[0].time);
+}
++
+ #[test]
+ fn layer_drop_target_skips_moving_layers_beyond_the_viewport() {
+ let mut rows: Vec<Row> = (1..=6).map(|id| Row { layer: LayerId(id), depth: 0, kind: RowKind::Layer }).collect();
+ rows.insert(4, Row { layer: LayerId(4), depth: 1, kind: RowKind::Prop { uid: 0 } });
+ let visible: Vec<_> = (2..=4).map(|id| (Rect::NOTHING, LayerId(id))).collect();
+ for at in [Some(2), None] {
+ assert_eq!(layer_drop_target(&rows, &visible, at, &[1, 4, 5]), Some(LayerId(6)), "skip moving headers and their properties across the viewport edge");
+ assert_eq!(layer_drop_target(&rows, &visible, at, &[1, 4, 5, 6]), None, "the stack ends when no stationary layer follows");
+ }
+ }