Timeline: the pick whip scrolls the layers at their edges (#362)
A pick whip dragged to the top or bottom of the Timeline's layers left them where they were, so a property out of view couldn't be picked. While a pick whip (expression or parent) is held within a row of the top or bottom edge of the layers, or past it, the layers scroll that way, faster the deeper, as in After Effects. Tests: the_pick_whip_scrolls_the_timeline_at_its_edges (ui_inline_edit). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
0b2ef8e584
commit
639342a5e7
@@ -132,6 +132,20 @@ fn pick_whip_id() -> egui::Id {
|
||||
egui::Id::new("tl-pickwhip")
|
||||
}
|
||||
|
||||
/// Autoscroll speed (points per second, up negative) of a drag held at height `y` within
|
||||
/// `zone` of the top or bottom edge of `rows`, or past it: faster the deeper.
|
||||
fn edge_scroll_speed(rows: Rect, y: f32, zone: f32) -> f32 {
|
||||
let zone = zone.min(rows.height() / 2.0).max(1.0);
|
||||
let depth = if y < rows.min.y + zone {
|
||||
y - (rows.min.y + zone)
|
||||
} else if y > rows.max.y - zone {
|
||||
y - (rows.max.y - zone)
|
||||
} else {
|
||||
return 0.0;
|
||||
};
|
||||
(depth / zone).clamp(-3.0, 3.0) * 400.0
|
||||
}
|
||||
|
||||
/// The text of an expression being edited when its pick whip was pressed, and the selection in
|
||||
/// it (characters): the pick whip's reference goes in there.
|
||||
type WhipInto = (String, [usize; 2]);
|
||||
@@ -1552,7 +1566,18 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
}
|
||||
}
|
||||
}
|
||||
app.ui.timeline.scroll_y = app.ui.timeline.scroll_y.min(max_scroll);
|
||||
// A pick whip held near the top or bottom of the layers (or past it) scrolls them, as in
|
||||
// After Effects.
|
||||
if ctx.data(|d| d.get_temp::<PickWhip>(pick_whip_id())).is_some()
|
||||
&& let Some(ptr) = ctx.input(|i| i.pointer.latest_pos()).filter(|p| rect.x_range().contains(p.x))
|
||||
{
|
||||
let speed = edge_scroll_speed(rows_rect, ptr.y, rh);
|
||||
if speed != 0.0 {
|
||||
app.ui.timeline.scroll_y += speed * ctx.input(|i| i.stable_dt).min(0.1);
|
||||
ctx.request_repaint();
|
||||
}
|
||||
}
|
||||
app.ui.timeline.scroll_y = app.ui.timeline.scroll_y.clamp(0.0, max_scroll);
|
||||
let snap_project = app.session.project.clone();
|
||||
let snap_expr = app.session.expr.clone();
|
||||
let ectx = EvalCtx { project: &snap_project, comp_id: cid, comp: &comp, time, expr: snap_expr.as_deref(), footage: None };
|
||||
|
||||
@@ -128,6 +128,51 @@ fn the_expression_pick_whip_inserts_at_the_cursor_while_editing() {
|
||||
assert_eq!(expr(&h), "transform.rotation");
|
||||
}
|
||||
|
||||
/// #362: an expression pick whip held near the bottom or top of the Timeline's layers scrolls
|
||||
/// them (After Effects), so a property out of view can be picked.
|
||||
#[test]
|
||||
fn the_pick_whip_scrolls_the_timeline_at_its_edges() {
|
||||
let (mut h, _) = harness();
|
||||
let (top, opacity, transform) = {
|
||||
let s = &mut h.state_mut().session;
|
||||
for i in 0..40 {
|
||||
s.execute("layer.newSolid", json!({"name": format!("Layer {i}"), "color": "#406080"})).unwrap();
|
||||
}
|
||||
let l = s.execute("layer.newSolid", json!({"name": "Top", "color": "#406080"})).unwrap()["layer"].as_u64().unwrap();
|
||||
s.execute("prop.setExpression", json!({"layer": l, "path": "transform/opacity", "expression": "50"})).unwrap();
|
||||
let tr = s.active_comp().unwrap().layer(effectcraft_engine::project::LayerId(l)).unwrap().props.sub("transform").unwrap().clone();
|
||||
(l, tr.get("opacity").unwrap().uid, tr.uid)
|
||||
};
|
||||
h.state_mut().ui.timeline.open_layers.insert(top);
|
||||
h.state_mut().ui.timeline.open_groups.insert(transform);
|
||||
h.run_steps(3);
|
||||
let scroll = |h: &Harness<'_, EffectcraftApp>| h.state().ui.timeline.scroll_y;
|
||||
let rows = h.state().auto.find("timeline.scroll").unwrap().rect;
|
||||
let from = center(&h, &format!("timeline.prop.{opacity}.pickWhip"));
|
||||
let (bottom, upper) = (pos2(from.x, rows[1] + rows[3] - 2.0), pos2(from.x, rows[1] + 2.0));
|
||||
h.input_mut().events.push(Event::PointerMoved(from));
|
||||
h.step();
|
||||
h.input_mut().events.push(Event::PointerButton { pos: from, button: PointerButton::Primary, pressed: true, modifiers: Modifiers::NONE });
|
||||
h.step();
|
||||
for k in 1..=8 {
|
||||
h.input_mut().events.push(Event::PointerMoved(from + (bottom - from) * (k as f32 / 8.0)));
|
||||
h.step();
|
||||
}
|
||||
h.run_steps(20);
|
||||
let down = scroll(&h);
|
||||
assert!(down > 50.0, "held at the bottom edge the layers scroll up: {down}");
|
||||
h.input_mut().events.push(Event::PointerMoved(upper));
|
||||
h.run_steps(10);
|
||||
assert!(scroll(&h) < down, "and at the top edge back down: {} after {down}", scroll(&h));
|
||||
h.input_mut().events.push(Event::PointerMoved(pos2(from.x, rows[1] + rows[3] / 2.0)));
|
||||
h.run_steps(2);
|
||||
let still = scroll(&h);
|
||||
h.run_steps(10);
|
||||
assert_eq!(scroll(&h), still, "away from the edges it stays");
|
||||
h.input_mut().events.push(Event::PointerButton { pos: upper, button: PointerButton::Primary, pressed: false, modifiers: Modifiers::NONE });
|
||||
h.run_steps(3);
|
||||
}
|
||||
|
||||
/// A click at `p` with `modifiers` held.
|
||||
fn click_with(h: &mut Harness<'_, EffectcraftApp>, p: Pos2, modifiers: Modifiers) {
|
||||
h.input_mut().events.push(Event::PointerMoved(p));
|
||||
|
||||
Reference in New Issue
Block a user