Skip to content

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

Merge remote-tracking branch 'origin/main' into enhance/pickwhip-index-refs

tylerjenningswdd50e4248682
diff --cc crates/ui-egui/tests/ui_inline_edit.rs
index 4b6c03a36,d7e532d76..003d5279e
--- a/crates/ui-egui/tests/ui_inline_edit.rs
+++ b/crates/ui-egui/tests/ui_inline_edit.rs
@@@ -540,70 -540,47 +540,115 @@@ fn arrow_keys_move_the_caret_in_rename_
assert_eq!(layer_name, "Pla-te");
}
+/// A primary-button drag from `from` to `to` with `modifiers` held from the press to the release.
+fn drag_with(h: &mut Harness<'_, EffectcraftApp>, from: Pos2, to: Pos2, modifiers: Modifiers) {
+ h.input_mut().events.push(Event::PointerMoved(from));
+ h.input_mut().events.push(Event::ModifiersChanged(modifiers));
+ h.step();
+ h.input_mut().events.push(Event::PointerButton { pos: from, button: PointerButton::Primary, pressed: true, modifiers });
+ h.step();
+ for k in 1..=8 {
+ h.input_mut().events.push(Event::PointerMoved(from + (to - from) * (k as f32 / 8.0)));
+ h.step();
+ }
+ h.input_mut().events.push(Event::PointerButton { pos: to, button: PointerButton::Primary, pressed: false, modifiers });
+ h.step();
+ h.input_mut().events.push(Event::ModifiersChanged(Modifiers::NONE));
+ h.run_steps(3);
+}
+
+/// #1072: with Alt held as it drops, a pick whip refers to an effect's property by its index,
+/// `effect("Slider Control")(1)`, as in After Effects; without Alt, by its name. Onto Effect
+/// Controls or the Timeline, and into the expression being edited (with a dimension).
+#[test]
+fn an_alt_pick_whip_refers_to_an_effect_property_by_index() {
+ let (mut h, _) = harness();
+ let (layer, opacity, transform, effects) = {
+ let s = &mut h.state_mut().session;
+ let l = s.execute("layer.newSolid", json!({"name": "Plate", "color": "#406080"})).unwrap()["layer"].as_u64().unwrap();
+ s.execute("layer.select", json!({"layers": [l]})).unwrap();
+ for fx in ["Slider Control", "Point Control"] {
+ s.execute("effect.apply", json!({"layers": [l], "effect": fx})).unwrap();
+ }
+ let props = s.active_comp().unwrap().layer(effectcraft_engine::project::LayerId(l)).unwrap().props.clone();
+ let effects: Vec<u64> = std::iter::once(props.sub("effects").unwrap().uid).chain(props.sub("effects").unwrap().groups().map(|g| g.uid)).collect();
+ (l, props.sub("transform").unwrap().get("opacity").unwrap().uid, props.sub("transform").unwrap().uid, effects)
+ };
+ h.state_mut().ui.timeline.open_layers.insert(layer);
+ h.state_mut().ui.timeline.open_groups.insert(transform);
+ h.state_mut().ui.timeline.open_groups.extend(effects);
+ h.state_mut().show_panel(effectcraft_ui_egui::dock::PanelKind::EffectControls);
+ h.run_steps(3);
+ let props =
+ |h: &Harness<'_, EffectcraftApp>| h.state().session.active_comp().unwrap().layer(effectcraft_engine::project::LayerId(layer)).unwrap().props.clone();
+ let (slider, point) = (props(&h).prop("effects/#1/slider").unwrap().uid, props(&h).prop("effects/#2/point").unwrap().uid);
+ let expr = |h: &Harness<'_, EffectcraftApp>| props(h).find(opacity).unwrap().expr.clone().map(|e| e.text);
+ let alt = Modifiers { alt: true, ..Modifiers::NONE };
+ let whip = |h: &mut Harness<'_, EffectcraftApp>, target: &str, modifiers: Modifiers| {
+ let (from, to) = (center(h, &format!("timeline.prop.{opacity}.propertyPickWhip")), center(h, target));
+ drag_with(h, from, to, modifiers);
+ };
+ whip(&mut h, &format!("effectControls.prop.{slider}.value"), alt);
+ assert_eq!(expr(&h).as_deref(), Some("effect(\"Slider Control\")(1)"), "Alt onto Effect Controls");
+ let undo = h.state().session.history.undo.len();
+ whip(&mut h, &format!("effectControls.prop.{slider}.value"), Modifiers::NONE);
+ assert_eq!(expr(&h).as_deref(), Some("effect(\"Slider Control\")(\"Slider\")"), "without Alt, by name");
+ assert_eq!(h.state().session.history.undo.len(), undo + 1, "one undo step");
+ whip(&mut h, &format!("timeline.prop.{slider}.name"), alt);
+ assert_eq!(expr(&h).as_deref(), Some("effect(\"Slider Control\")(1)"), "Alt onto the Timeline");
+ // Into the expression being edited, at the cursor, with the value it was dropped on.
+ let p = center(&h, &format!("timeline.prop.{opacity}.expression"));
+ click(&mut h, p, 1);
+ key(&mut h, Key::End);
+ type_text(&mut h, " + ");
+ let (from, to) = (center(&h, &format!("timeline.prop.{opacity}.pickWhip")), center(&h, &format!("effectControls.prop.{point}.value.1")));
+ drag_with(&mut h, from, to, alt);
+ assert_eq!(expr(&h).as_deref(), Some("effect(\"Slider Control\")(1) + effect(\"Point Control\")(1)[1]"));
+ h.state_mut().session.execute("edit.undo", json!({})).unwrap();
+ assert_eq!(expr(&h).as_deref(), Some("effect(\"Slider Control\")(1)"), "undone in one step");
+}
++
+ /// #1434: with several 3D layers selected, typing a Z Position sets Z on each of them; their X
+ /// and Y stay their own. Every selected layer used to take the typed layer's whole Position, so
+ /// they stacked on top of it and seemed to disappear.
+ #[test]
+ fn typing_one_component_with_several_layers_selected_keeps_their_other_components() {
+ let (mut h, _) = harness();
+ let (a, b, transform) = {
+ let s = &mut h.state_mut().session;
+ let mut ids = vec![];
+ for (name, xy) in [("A", [40.0, 50.0]), ("B", [200.0, 120.0])] {
+ let l = s.execute("layer.newSolid", json!({"name": name, "color": "#406080", "width": 40, "height": 40})).unwrap()["layer"].as_u64().unwrap();
+ s.execute("layer.setSwitch", json!({"layers": [l], "switch": "threeD", "value": true})).unwrap();
+ s.execute("prop.set", json!({"layer": l, "path": "transform/position", "value": [xy[0], xy[1], 0.0]})).unwrap();
+ ids.push(l);
+ }
+ s.execute("layer.select", json!({"layers": ids})).unwrap();
+ let tr = s.active_comp().unwrap().layer(effectcraft_engine::project::LayerId(ids[0])).unwrap().props.sub("transform").unwrap().uid;
+ (ids[0], ids[1], tr)
+ };
+ h.state_mut().ui.timeline.open_layers.insert(a);
+ h.state_mut().ui.timeline.open_groups.insert(transform);
+ h.run_steps(3);
+ let pos = |h: &Harness<'_, EffectcraftApp>, l: u64| {
+ h.state()
+ .session
+ .active_comp()
+ .unwrap()
+ .layer(effectcraft_engine::project::LayerId(l))
+ .unwrap()
+ .props
+ .prop("transform/position")
+ .unwrap()
+ .value
+ .components()
+ };
+ let position =
+ h.state().session.active_comp().unwrap().layer(effectcraft_engine::project::LayerId(a)).unwrap().props.prop("transform/position").unwrap().uid;
+ let p = center(&h, &format!("timeline.prop.{position}.value.2"));
+ click(&mut h, p, 1);
+ type_text(&mut h, "-300");
+ key(&mut h, Key::Enter);
+ assert_eq!(pos(&h, a), [40.0, 50.0, -300.0]);
+ assert_eq!(pos(&h, b), [200.0, 120.0, -300.0], "B keeps its own X and Y");
+ }