Skip to content

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

#1284: fix the shape double-click's size and paint, focus after closing the queue, the Graph Editor key menu

Claudef9d514bb217b
diff --git a/crates/engine/src/cmd/anim.rs b/crates/engine/src/cmd/anim.rs
index 325845115..76bfb5a63 100644
--- a/crates/engine/src/cmd/anim.rs
+++ b/crates/engine/src/cmd/anim.rs
@@ -296,6 +296,9 @@ fn set_key(s: &mut Session, p: &Value) -> Result<Value> {
let base = KeyTimeBase::from_params(p, "keys.set")?;
let comp = s.project.comp(cid).ok_or(EngineError::NoComp)?;
let layer = comp.layer(lid).ok_or(EngineError::NoComp)?;
+ if layer.switches.locked {
+ return Err(bad("keys.set", "the layer is locked"));
+ }
let t = key_time(layer, comp.frame_rate, p, "time", base, "keys.set", false)?.ok_or_else(|| bad("keys.set", "missing `time` (layer time by default)"))?;
let new_t = key_time(layer, comp.frame_rate, p, "newTime", base, "keys.set", true)?;
let value = p.get("value").cloned();
diff --git a/crates/engine/src/cmd/prop.rs b/crates/engine/src/cmd/prop.rs
index 00232967e..36f76706f 100644
--- a/crates/engine/src/cmd/prop.rs
+++ b/crates/engine/src/cmd/prop.rs
@@ -1046,6 +1046,10 @@ fn delete_keys(s: &mut Session, _: &Value) -> Result<Value> {
let comp = proj.comp_mut(cid).ok_or(EngineError::NoComp)?;
let mut removed = 0usize;
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)
{
@@ -1056,7 +1060,7 @@ fn delete_keys(s: &mut Session, _: &Value) -> Result<Value> {
removed += 1;
}
}
- st.selected_keys.clear();
+ st.selected_keys.retain(|k| comp.layer(k.layer).is_some_and(|l| l.switches.locked));
// 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 --git a/crates/engine/src/cmd/shape_tool.rs b/crates/engine/src/cmd/shape_tool.rs
index e1f3607b1..3db347e60 100644
--- a/crates/engine/src/cmd/shape_tool.rs
+++ b/crates/engine/src/cmd/shape_tool.rs
@@ -318,7 +318,9 @@ fn new_shape(s: &mut Session, p: &Value) -> Result<Value> {
};
let pos = position_p(p, c)?.unwrap_or([comp.width as f64 / 2.0, comp.height as f64 / 2.0]);
let paint = paint_p(p, &s.state.shape_tool, c)?;
- let target = draw_target(s, &comp, p, c)?;
+ // `newLayer` makes a layer of its own even with a shape layer selected (a shape that fills the
+ // comp for a background or matte, whatever is selected).
+ let target = if b_p(p, "newLayer") == Some(true) { None } else { draw_target(s, &comp, p, c)? };
// In the target layer's space: the centre maps through the layer's transform, the size by
// its scale.
let (centre, size) = match target.and_then(|l| comp.layer(l)) {
@@ -374,7 +376,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Shape Tool",
[],
None,
- "{layer?, kind?: rect|rounded|ellipse|polygon|star, size? [w,h], position? [x,y] (the centre), space?: comp|layer, name? (a new layer's), fill?, fillType?, fillBlend?, fillOpacity?, stroke?, strokeType?, strokeBlend?, strokeOpacity?, strokeWidth? (default the Tools bar's, shape.toolOptions)} → {layer, group}",
+ "{layer?, newLayer? (a new shape layer even with a shape layer selected), kind?: rect|rounded|ellipse|polygon|star, size? [w,h], position? [x,y] (the centre), space?: comp|layer, name? (a new layer's), fill?, fillType?, fillBlend?, fillOpacity?, stroke?, strokeType?, strokeBlend?, strokeOpacity?, strokeWidth? (default the Tools bar's, shape.toolOptions)} → {layer, group}",
has_comp,
new_shape
),
diff --git a/crates/engine/src/tests/delete_keys.rs b/crates/engine/src/tests/delete_keys.rs
index b1b9af316..029104497 100644
--- a/crates/engine/src/tests/delete_keys.rs
+++ b/crates/engine/src/tests/delete_keys.rs
@@ -43,3 +43,24 @@ fn delete_keys_reports_zero_when_no_selected_key_exists() {
assert_eq!(removed, json!(0));
assert_eq!(keys_of(&s, layer, prop), keys);
}
+
+/// A layer locked after its keys were selected keeps them: Delete and Edit Value leave them alone.
+#[test]
+fn a_locked_layers_keys_cannot_be_deleted_or_edited() {
+ let (mut s, layer, prop) = setup();
+ let keys = keys_of(&s, layer, prop);
+ s.state.selected_keys = keys.clone();
+ s.execute_checked("layer.setSwitch", json!({"layers": [layer], "switch": "locked", "value": true})).unwrap();
+ let removed = s.execute_checked("keys.delete", json!({})).unwrap();
+ assert_eq!(removed, json!(0));
+ assert_eq!(keys_of(&s, layer, prop), keys);
+ assert_eq!(s.state.selected_keys, keys, "the selection stays");
+ let e = s.execute("keys.set", json!({"layer": layer, "prop": prop, "time": 0, "value": 90})).unwrap_err().to_string();
+ assert!(e.contains("locked"), "{e}");
+ let value = s.active_comp().unwrap().layer(LayerId(layer)).unwrap().props.find(prop).unwrap().keys[0].value.as_f64();
+ assert_eq!(value, 0.0);
+ // Unlocked again, both work.
+ s.execute_checked("layer.setSwitch", json!({"layers": [layer], "switch": "locked", "value": false})).unwrap();
+ s.execute_checked("keys.set", json!({"layer": layer, "prop": prop, "time": 0, "value": 90})).unwrap();
+ assert_eq!(s.execute_checked("keys.delete", json!({})).unwrap(), json!(3));
+}
diff --git a/crates/ui-egui/src/header.rs b/crates/ui-egui/src/header.rs
index 45caa86de..8a336fcbb 100644
--- a/crates/ui-egui/src/header.rs
+++ b/crates/ui-egui/src/header.rs
@@ -57,6 +57,22 @@ fn brand_and_home(app: &mut EffectcraftApp, ui: &mut egui::Ui, p: &egui::Painter
x + 6.0
}
+/// The `shape.newShape` parameters for a shape that fills a `w` × `h` composition with `tool`: a new
+/// layer, painted with the Tools bar's Fill and Stroke. A polygon or star is round, so it takes the
+/// shorter side; the other kinds take the whole frame.
+pub(crate) fn comp_sized_shape_params(tool: Tool, w: u32, h: u32) -> serde_json::Value {
+ let kind = crate::panels::viewer::shape_kind(tool);
+ let (w, h) = (f64::from(w), f64::from(h));
+ let size = if matches!(kind, "polygon" | "star") { [w.min(h); 2] } else { [w, h] };
+ json!({"kind": kind, "size": size, "position": [w / 2.0, h / 2.0], "newLayer": true})
+}
+
+/// Make the shape layer that fills the composition for a double-clicked shape `tool`.
+fn comp_sized_shape(app: &mut EffectcraftApp, ctx: &egui::Context, tool: Tool) -> Result<serde_json::Value, String> {
+ let (w, h) = app.session.active_comp().map(|c| (c.width, c.height)).ok_or("no composition is open")?;
+ crate::menus::invoke(app, ctx, "shape.newShape", comp_sized_shape_params(tool, w, h))
+}
+
/// The tool slots (with group separators after camera tools and pan-behind); returns the x after them.
fn tool_slots(app: &mut EffectcraftApp, ui: &mut egui::Ui, p: &egui::Painter, mut x: f32, cy: f32) -> f32 {
let t = app.tokens;
@@ -114,8 +130,7 @@ fn tool_slot(app: &mut EffectcraftApp, ui: &mut egui::Ui, p: &egui::Painter, si:
// backgrounds, mattes and overlays (as After Effects does).
if cur.is_shape()
&& resp.double_clicked()
- && let Some((w, h)) = app.session.active_comp().map(|c| (c.width, c.height))
- && let Err(e) = crate::menus::invoke(app, ui.ctx(), "layer.newShape", json!({"kind": crate::panels::viewer::shape_kind(cur), "size": [w, h]}))
+ && let Err(e) = comp_sized_shape(app, ui.ctx(), cur)
{
app.ui.status = e;
}
@@ -843,4 +858,46 @@ mod tests {
frame(&mut app, &ctx, 2.1, vec![]);
assert!(!app.auto.elements.iter().any(|w| w.id == "tools.select.TypeVertical"));
}
+
+ /// A polygon or star fills the shorter side; the other kinds fill the frame; all make a new layer.
+ #[test]
+ fn a_comp_sized_shape_fits_the_frame_for_every_kind() {
+ for (tool, size) in [
+ (Tool::Rectangle, [1920.0, 1080.0]),
+ (Tool::RoundedRect, [1920.0, 1080.0]),
+ (Tool::Ellipse, [1920.0, 1080.0]),
+ (Tool::Polygon, [1080.0, 1080.0]),
+ (Tool::Star, [1080.0, 1080.0]),
+ ] {
+ let p = comp_sized_shape_params(tool, 1920, 1080);
+ assert_eq!(p["size"], json!(size), "{tool:?}");
+ assert_eq!(p["position"], json!([960.0, 540.0]));
+ assert_eq!(p["newLayer"], json!(true));
+ }
+ }
+
+ /// The double-click shape takes the Tools bar's Fill, and is a new layer even with a shape layer
+ /// selected (not a group in that layer).
+ #[test]
+ fn the_double_clicked_shape_uses_the_toolbar_paint_on_a_new_layer() {
+ let mut s = effectcraft_engine::Session::default();
+ s.execute("comp.new", json!({"width": 400, "height": 300, "duration": 2})).unwrap();
+ let first = s.execute("layer.newShape", json!({"kind": "rect"})).unwrap()["layer"].as_u64().unwrap();
+ s.execute("shape.toolOptions", json!({"fill": "#00ff00", "stroke": false})).unwrap();
+ let mut app = EffectcraftApp::new(s);
+ let ctx = egui::Context::default();
+ assert_eq!(app.session.state.selected_layers.first().map(|l| l.0), Some(first), "a shape layer is selected");
+ comp_sized_shape(&mut app, &ctx, Tool::Star).unwrap();
+ let comp = app.session.active_comp().unwrap();
+ assert_eq!(comp.layers.len(), 2, "a new layer, not a group in the selected one");
+ let layer = comp.layers.iter().find(|l| l.id.0 != first).unwrap();
+ let mut fill = None;
+ layer.props.walk("", &mut |_, pr| {
+ if fill.is_none() && matches!(pr.value, effectcraft_engine::keyframe::Value::Color(_)) {
+ fill = Some(pr.value.clone());
+ }
+ });
+ let fill = fill.expect("a fill colour");
+ assert_eq!(fill, effectcraft_engine::keyframe::Value::Color([0.0, 1.0, 0.0, 1.0]), "the Tools bar's Fill, not the default blue");
+ }
}
diff --git a/crates/ui-egui/src/menus/invoke.rs b/crates/ui-egui/src/menus/invoke.rs
index 2c99274ed..f1958fb5e 100644
--- a/crates/ui-egui/src/menus/invoke.rs
+++ b/crates/ui-egui/src/menus/invoke.rs
@@ -218,6 +218,10 @@ pub fn invoke(app: &mut EffectcraftApp, ctx: &egui::Context, id: &str, params: V
// leaves the active composition open (it used to close the composition next to it).
if id == "file.close" && params.as_object().is_some_and(|p| p.is_empty()) && app.ui.focused == PanelKind::RenderQueue {
app.close_panel(PanelKind::RenderQueue);
+ // The focus goes to a panel that is still there, so the next Close acts on the composition
+ // instead of on the queue that is gone.
+ app.ui.focused =
+ [PanelKind::Timeline, PanelKind::Composition, PanelKind::Project].into_iter().find(|p| app.ui.dock.is_visible(*p)).unwrap_or(PanelKind::Project);
return Ok(Value::Null);
}
// Edit ▸ Paste with SVG markup on the system clipboard pastes it as a shape layer (After
diff --git a/crates/ui-egui/src/menus/tests.rs b/crates/ui-egui/src/menus/tests.rs
index ed35e727f..5af50f0fc 100644
--- a/crates/ui-egui/src/menus/tests.rs
+++ b/crates/ui-egui/src/menus/tests.rs
@@ -431,6 +431,10 @@ fn cmd_w_in_the_render_queue_closes_the_queue_not_the_comp() {
assert!(!app.ui.dock.is_visible(PanelKind::RenderQueue));
assert_eq!(app.session.state.active_comp.map(|c| c.0), a);
assert_eq!(app.session.state.open_comps.len(), 1);
+ // The focus left the closed queue: the next Close closes the composition.
+ assert_ne!(app.ui.focused, PanelKind::RenderQueue);
+ invoke(&mut app, &ctx, "file.close", json!({})).unwrap();
+ assert_eq!(app.session.state.open_comps.len(), 0, "a second Close acts on the composition");
}
#[test]
diff --git a/crates/ui-egui/src/panels/graph.rs b/crates/ui-egui/src/panels/graph.rs
index 3bd46738e..a87a909a0 100644
--- a/crates/ui-egui/src/panels/graph.rs
+++ b/crates/ui-egui/src/panels/graph.rs
@@ -573,48 +573,8 @@ pub(crate) fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, p: &egui::Painte
ctx.data_mut(|dd| dd.insert_temp(drag_id, false));
actions.push(("__endMerge".into(), json!({})));
}
- // Right-click: the Timeline's key menu, for the commands that apply from the Graph Editor.
- kresp.context_menu(|ui| {
- let editable_value = matches!(key.value, Value::Scalar(_) | Value::Vec2(_) | Value::Vec3(_));
- for (lbl, cmd, params) in [
- ("Edit Value…", "keys.set", kjson.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!({})),
- ("Toggle Hold Keyframe", "keys.toggleHold", json!({})),
- ("Rove Across Time", "keys.interpolation", json!({"roving": !key.roving})),
- ("-", "", json!({})),
- ("Easy Ease", "keys.easyEase", json!({})),
- ("Easy Ease In", "keys.easyEaseIn", json!({})),
- ("Easy Ease Out", "keys.easyEaseOut", json!({})),
- ("-", "", json!({})),
- ("Linear", "keys.interpolation", json!({"interpolation": "linear"})),
- ("Bezier", "keys.interpolation", json!({"interpolation": "bezier"})),
- ("Auto Bezier", "keys.interpolation", json!({"interpolation": "autoBezier"})),
- ("-", "", json!({})),
- ("Delete", "keys.delete", json!({})),
- ] {
- if lbl == "-" {
- ui.separator();
- continue;
- }
- if lbl == "Rove Across Time" && !c.prop.spatial {
- continue;
- }
- if lbl == "Edit Value…" && !editable_value {
- continue;
- }
- if ui.button(lbl).clicked() {
- actions.push((cmd.into(), params));
- ui.close();
- }
- }
- });
+ // Right-click: the Timeline's key menu, with the same commands.
+ crate::widgets::context_menu(&kresp, |ui| super::timeline::key_menu(ui, app, c.layer, c.prop, key, k.sel, actions));
}
}
diff --git a/crates/ui-egui/src/panels/timeline.rs b/crates/ui-egui/src/panels/timeline.rs
index a45d8e708..7fa5881a4 100644
--- a/crates/ui-egui/src/panels/timeline.rs
+++ b/crates/ui-egui/src/panels/timeline.rs
@@ -4006,71 +4006,88 @@ fn key_double_click(g: &mut Rw, rc: &RowCtx<'_>, prop: &Property, kh: &KeyHit<'_
/// 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!({})),
- ("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!({})),
+ ("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() {
- if !ks {
- actions.push(("keys.select".into(), json!({"keys": [{"layer": layer.id.0, "prop": uid, "time": k.time.seconds()}]})));
+ if !selected {
+ actions.push(("keys.select".into(), json!({"keys": [this_key.clone()]})));
}
actions.push(("keys.setLabel".into(), json!({"label": i})));
ui.close();
}
}
});
+ });
+ }
+ if lbl == "-" {
+ ui.separator();
+ continue;
+ }
+ if lbl == "Rove Across Time" && !prop.spatial {
+ continue;
+ }
+ if lbl == "Edit Value…" && !matches!(k.value, Value::Scalar(_) | Value::Vec2(_) | Value::Vec3(_)) {
+ continue;
+ }
+ let edits = !matches!(cmd, "keys.copy" | "keys.selectEqual" | "keys.selectPrevious" | "keys.selectFollowing" | "keys.selectAll");
+ if ui.add_enabled(!(locked && edits), egui::Button::new(crate::i18n::context_item(cmd, &params, lbl))).clicked() {
+ if !selected {
+ actions.push(("keys.select".into(), json!({"keys": [this_key.clone()]})));
}
- if lbl == "-" {
- ui.separator();
- continue;
- }
- if lbl == "Rove Across Time" && !prop.spatial {
- continue;
- }
- if lbl == "Edit Value…" && !matches!(k.value, Value::Scalar(_) | Value::Vec2(_) | Value::Vec3(_)) {
- continue;
- }
- if ui.button(lbl).clicked() {
- if !ks {
- actions.push(("keys.select".into(), json!({"keys": [{"layer": layer.id.0, "prop": uid, "time": k.time.seconds()}]})));
- }
- actions.push((cmd.into(), params));
- ui.close();
- }
+ actions.push((cmd.into(), params));
+ ui.close();
}
- });
+ }
}
/// Starts a key drag (or Alt-scale).
diff --git a/crates/ui-egui/src/panels/timeline/tests.rs b/crates/ui-egui/src/panels/timeline/tests.rs
index 0355ea5ed..ee0e39ca3 100644
--- a/crates/ui-egui/src/panels/timeline/tests.rs
+++ b/crates/ui-egui/src/panels/timeline/tests.rs
@@ -535,3 +535,46 @@ 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, 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, true, &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…"]
+ {
+ assert!(enabled(false, label), "{label} on an unlocked layer");
+ }
+ for label in ["Copy", "Select Equal Keyframes", "Select All Keyframes"] {
+ assert!(enabled(true, label), "{label} is still available on a locked layer");
+ }
+ for label in ["Delete", "Edit Value…", "Easy Ease", "Time-Reverse Keyframes", "Keyframe Velocity…", "Linear"] {
+ assert!(!enabled(true, label), "{label} is off on a locked layer");
+ }
+ // 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, &copy));
+ crate::i18n::set_current("en");
+}