Merge pull request #3254 from vangel76/effect-controls-alt-expression-1460

Alt-click on a stopwatch in Effect Controls adds or removes an expression, as in After Effects, instead of toggling keyframes
This commit is contained in:
FredApps authored and GitHub committed 2026-11-16 10:28:40 +01:00
commit 2bfb8bad3b
3 files changed
+93 -21

No files matched your search

@@ -128,6 +128,18 @@ impl PropCx<'_> {
}
}
/// Shows property `uid` of layer `layer` in the Timeline: its layer and groups twirled open, the
/// property scrolled to and the Timeline brought forward (After Effects' Reveal in Timeline,
/// which a double-click on the property's name does; #1497).
fn reveal_in_timeline(app: &mut EffectcraftApp, ctx: &egui::Context, layer: u64, uid: u64) {
app.ui.timeline.search.clear();
app.ui.timeline.scroll_to = Some(crate::state::ScrollTo::Property(uid));
if let Err(e) = crate::menus::frontend(app, ctx, "timeline.revealProps", json!({"props": [{"layer": layer, "prop": uid}]})) {
app.ui.status = e;
}
app.show_panel(crate::dock::PanelKind::Timeline);
}
/// One property row: stopwatch, name, value control (and the keyframe navigator). Returns the
/// value fields of a vector, one per dimension, for the pick whip.
#[allow(clippy::too_many_arguments)]
@@ -167,7 +179,16 @@ fn prop_row(
},
);
app.auto.add(&format!("effectControls.prop.{uid}.stopwatch"), swr, &prop.name);
if resp.clicked() {
if resp.clicked() && ui.input(|i| i.modifiers.alt) {
// Alt+click adds an expression (or removes it), as in the Timeline. Effect Controls
// has no expression field: the property shows in the Timeline with its new
// expression's editor taking the keyboard, as After Effects does (#1460).
actions.push(("prop.setExpression".into(), json!({"layer": layer.id.0, "prop": uid})));
if prop.expr.is_none() {
reveal_in_timeline(app, ui.ctx(), layer.id.0, uid);
}
crate::panels::timeline::expression_toggled(app, ui.ctx(), prop);
} else if resp.clicked() {
actions.push(("prop.toggleAnimation".into(), json!({"layer": layer.id.0, "prop": uid, "selected": true})));
}
}
@@ -201,12 +222,7 @@ fn prop_row(
p.with_clip_rect(name_clip.intersect(p.clip_rect())).text(pos2(swr.max.x + 6.0, cy), Align2::LEFT_CENTER, &prop.name, Tokens::ui(12.0), t.text);
let name_response = ui.interact(name_clip, egui::Id::unique(("ec-prop-name", uid)), Sense::click());
if name_response.double_clicked() {
app.ui.timeline.search.clear();
app.ui.timeline.scroll_to = Some(crate::state::ScrollTo::Property(uid));
if let Err(e) = crate::menus::frontend(app, ui.ctx(), "timeline.revealProps", json!({"props": [{"layer": layer.id.0, "prop": uid}]})) {
app.ui.status = e;
}
app.show_panel(crate::dock::PanelKind::Timeline);
reveal_in_timeline(app, ui.ctx(), layer.id.0, uid);
}
app.auto.add(&format!("effectControls.prop.{uid}.name"), name_clip, &prop.name);
// With several layers selected the edit applies to the same effect property of each (#491).
+22 -14
View File
@@ -325,9 +325,27 @@ fn expr_focus_id() -> egui::Id {
egui::Id::unique("tl-expr-focus")
}
/// Asks the expression editor of property `prop` to take the keyboard when the Timeline next
/// draws it, selecting `select` (counts of characters before the end).
fn focus_expression(ctx: &egui::Context, prop: u64, select: [usize; 2]) {
let pass = ctx.cumulative_pass_nr();
ctx.data_mut(|d| d.insert_temp(expr_focus_id(), ExprFocus { prop, select, pass }));
// The editor takes it in a later pass: make sure one comes without waiting for input.
ctx.request_repaint();
}
/// After a `prop.setExpression` toggle of `prop` was queued (an Alt-click on its stopwatch, in the
/// Timeline or in Effect Controls): adding one, its editor opens, comes into view and takes the
/// keyboard with the new expression selected (#1072, #1460); removing it, a pending request for
/// its editor goes, as nothing is left to take the keyboard.
pub(crate) fn expression_toggled(app: &mut EffectcraftApp, ctx: &egui::Context, prop: &Property) {
let uid = prop.uid;
if prop.expr.is_none() {
app.ui.timeline.expr_closed.remove(&uid);
focus_expression(ctx, uid, [usize::MAX, 0]);
} else if ctx.data(|d| d.get_temp::<ExprFocus>(expr_focus_id())).is_some_and(|f| f.prop == uid) {
ctx.data_mut(|d| d.remove::<ExprFocus>(expr_focus_id()));
}
}
#[derive(Clone, Debug, PartialEq)]
@@ -4054,7 +4072,10 @@ fn expr_editor_cell(app: &mut EffectcraftApp, ui: &mut egui::Ui, g: &mut Rw, rc:
gp.rect_filled(Rect::from_min_max(pos2(graph_x0, r.min.y), r.max), 0.0, t.expr_bg);
let er = Rect::from_min_max(pos2(graph_x0 + 8.0, r.min.y + 3.0), pos2(rect.max.x - 14.0, r.max.y - 3.0));
let mut buf: String = ctx.data(|d| d.get_temp(buf_id)).unwrap_or_else(|| ex.text.clone());
if let Some(f) = ctx.data(|d| d.get_temp::<ExprFocus>(expr_focus_id())).filter(|f| f.prop == *uid) {
// Not in the pass it was asked for in: a click that asked for it from another panel (an
// Alt-click on a stopwatch in Effect Controls, drawn before the Timeline) would take the
// keyboard straight back as a click elsewhere (#1460).
if let Some(f) = ctx.data(|d| d.get_temp::<ExprFocus>(expr_focus_id())).filter(|f| f.prop == *uid && ctx.cumulative_pass_nr() > f.pass) {
// Asked for once (a pick whip put a reference in, or an Alt-click added the
// expression): editing starts in the expression as it is now.
ctx.data_mut(|d| d.remove::<ExprFocus>(expr_focus_id()));
@@ -4277,19 +4298,6 @@ fn prop_context_menu(
}
}
/// An expression was just added to `prop` (it had none) or removed: adding one opens its
/// editor, which comes into view and takes the keyboard with the new expression selected
/// (#1072); removing it leaves nothing to take the keyboard.
fn expression_toggled(app: &mut EffectcraftApp, ctx: &egui::Context, prop: &Property) {
let uid = prop.uid;
if prop.expr.is_none() {
app.ui.timeline.expr_closed.remove(&uid);
focus_expression(ctx, uid, [usize::MAX, 0]);
} else if ctx.data(|d| d.get_temp::<ExprFocus>(expr_focus_id())).is_some_and(|f| f.prop == uid) {
ctx.data_mut(|d| d.remove::<ExprFocus>(expr_focus_id()));
}
}
/// The value editors and the property pick whip.
fn prop_value_cell(app: &mut EffectcraftApp, ui: &mut egui::Ui, g: &mut Rw, rc: &RowCtx<'_>, ectx: &EvalCtx<'_>, prop: &Property, name_x: f32) {
let vis = g.tl.vis;
+48
View File
@@ -725,6 +725,54 @@ fn an_expression_added_at_the_bottom_of_the_timeline_comes_into_view() {
assert_eq!(expression(&h, layer, opacity).as_deref(), Some("25"));
}
/// #1460: Alt-clicking an effect property's stopwatch in Effect Controls adds an expression, as in
/// the Timeline (it toggled the animation instead). Effect Controls has no expression field, so,
/// as in After Effects, the property shows in the Timeline (its layer and effect twirled open,
/// scrolled into view) with the new expression's editor taking the keyboard: typing replaces
/// it. Another Alt-click removes it and leaves nothing holding the keyboard.
#[test]
fn alt_clicking_a_stopwatch_in_effect_controls_edits_the_expression_in_the_timeline() {
let (mut h, _) = harness();
let (layer, slider) = {
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("effect.apply", json!({"layers": [l], "effect": "Slider Control"})).unwrap();
// Layers above push it below the bottom of the Timeline.
for i in 0..40 {
s.execute("layer.newSolid", json!({"name": format!("Layer {i}"), "color": "#204060"})).unwrap();
}
s.execute("layer.select", json!({"layers": [l]})).unwrap();
let slider = s.active_comp().unwrap().layer(effectcraft_engine::project::LayerId(l)).unwrap().props.prop("effects/#1/slider").unwrap().uid;
(l, slider)
};
h.state_mut().show_panel(effectcraft_ui_egui::dock::PanelKind::EffectControls);
h.run_steps(3);
let editor = format!("timeline.prop.{slider}.expression");
assert!(h.state().auto.find(&format!("timeline.prop.{slider}.row")).is_none(), "the property is not in the Timeline yet");
let alt = Modifiers { alt: true, ..Modifiers::NONE };
let at = center(&h, &format!("effectControls.prop.{slider}.stopwatch"));
click_with(&mut h, at, alt);
assert!(expression(&h, layer, slider).is_some(), "an expression was added");
let key = h.state().session.active_comp().unwrap().layer(effectcraft_engine::project::LayerId(layer)).unwrap().props.find(slider).unwrap().is_animated();
assert!(!key, "Alt-click doesn't turn on keyframing");
assert!(h.state().ui.timeline.reveal_props.contains(&slider), "the property is revealed in the Timeline");
let rows = h.state().auto.find("timeline.scroll").expect("the Timeline is shown").rect;
let e = h.state().auto.find(&editor).expect("the Timeline draws the expression editor").rect;
assert!(e[1] >= rows[1] - 0.5 && e[1] + e[3] <= rows[1] + rows[3] + 0.5, "the editor is in view: {e:?} in {rows:?}");
type_text(&mut h, "42");
commit_expression(&mut h);
assert_eq!(expression(&h, layer, slider).as_deref(), Some("42"), "typing replaced the new expression");
// Alt-click again removes the expression and its editor with it (the keyboard stays free;
// the editor's focus request was taken when it was added, so this doesn't exercise the
// cancel path).
let at = center(&h, &format!("effectControls.prop.{slider}.stopwatch"));
click_with(&mut h, at, alt);
h.run_steps(5);
assert_eq!(expression(&h, layer, slider), None);
assert!(h.state().auto.find(&editor).is_none(), "the expression editor is gone");
assert!(!h.ctx.egui_wants_keyboard_input(), "nothing has the keyboard");
}
fn right_click(h: &mut Harness<'_, EffectcraftApp>, p: Pos2) {
h.input_mut().events.push(Event::PointerMoved(p));
h.step();