From 1dcb8273a45ac0bd9a4a3d05f78f53522e00d585 Mon Sep 17 00:00:00 2001 From: arnav-hiwarkar Date: Wed, 21 Oct 2026 21:47:06 +0530 Subject: [PATCH 1/5] Fast Previews: Adaptive Resolution applies while dragging in the Timeline `timeline::show` keeps a per-frame `dragging` flag. While the primary button is down, it sets the existing `property_interacting` for: - dragging the playhead or the timecode; - moving layer bars, or their in and out points; - dragging keys, and the key alt-scale. A click without movement doesn't set it. The existing clear at the start of each frame handles the release, so the first frame after it is sharp. With Fast Previews off (the default) or a fixed resolution, nothing changes. 9 lines of production code. --- crates/ui-egui/src/panels/timeline.rs | 9 +- crates/ui-egui/src/state.rs | 1 + .../ui-egui/tests/ui_timeline_interacting.rs | 115 ++++++++++++++++++ 3 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 crates/ui-egui/tests/ui_timeline_interacting.rs diff --git a/crates/ui-egui/src/panels/timeline.rs b/crates/ui-egui/src/panels/timeline.rs index b34fbd9d3..1d9703ddb 100644 --- a/crates/ui-egui/src/panels/timeline.rs +++ b/crates/ui-egui/src/panels/timeline.rs @@ -1468,6 +1468,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) { p.line_segment([pos2(graph_x0 - 1.0, top), pos2(graph_x0 - 1.0, rect.max.y)], Stroke::new(1.0, t.app_bg)); let mut actions: Vec<(String, serde_json::Value)> = Vec::new(); + let mut dragging = false; // A drag that moves the frame on screen (Fast Previews). if !ui.input(|i| i.pointer.primary_down()) { ctx.data_mut(|d| d.remove::(switch_drag_id())); } @@ -1495,6 +1496,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) { app.auto.add("timeline.timecode", tc_rect, &tc); super::toggle_time_display(app, &tc_resp); if tc_resp.dragged() { + dragging = true; let d = tc_resp.drag_delta().x as f64; let f = fr.frame_at(time) + (d * 0.5).round() as i64; let _ = app.session.execute("time.set", json!({"frame": f.max(0)})); @@ -1730,6 +1732,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) { if ((rresp.is_pointer_button_down_on() && ui.input(|i| i.pointer.primary_down())) || rresp.clicked()) && let Some(pt) = rresp.interact_pointer_pos() { + dragging |= rresp.dragged(); let mut x = pt.x; // Zoomed in, a scrub held past either end of the ruler scrolls the timeline that way // (faster the further), with the CTI at the edge (After Effects). @@ -2360,6 +2363,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) { continue; } if resp.dragged() { + dragging = true; let acc_id = egui::Id::new(("bar-acc", layer.id.0, kind)); let mut acc: f32 = ctx.data(|d| d.get_temp(acc_id).unwrap_or(0.0)); acc += resp.drag_delta().x; @@ -3149,6 +3153,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) { let (down, ptr) = ctx.input(|i| (i.pointer.primary_down(), i.pointer.latest_pos())); match ptr.filter(|_| down) { Some(ptr) => { + dragging = true; let frames = (((ptr.x - q.origin_x) as f64 / pps) / fd).round() as i64; if frames != q.applied { q.applied = frames; @@ -3171,6 +3176,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) { let (down, ptr, shift) = ctx.input(|i| (i.pointer.primary_down(), i.pointer.latest_pos(), i.modifiers.shift)); match ptr.filter(|_| down) { Some(ptr) => { + dragging = true; let mut target = kd.anchor + (ptr.x - kd.origin_x) as f64 / pps; if shift { // The current time and whatever it snaps to (keys, layer ends, markers), but @@ -3474,7 +3480,8 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) { } } } - if ui.input(|i| i.pointer.primary_down()) && actions.iter().any(|(id, _)| id == "prop.set") { + dragging |= super::graph_tools::alt_scale_active(&ctx); + if ui.input(|i| i.pointer.primary_down()) && (dragging || actions.iter().any(|(id, _)| id == "prop.set")) { app.ui.viewer.property_interacting = true; ctx.request_repaint(); } diff --git a/crates/ui-egui/src/state.rs b/crates/ui-egui/src/state.rs index 1e2f57204..206c70cf3 100644 --- a/crates/ui-egui/src/state.rs +++ b/crates/ui-egui/src/state.rs @@ -264,6 +264,7 @@ pub struct ViewerState { /// The pointer is dragging in the viewer this frame (Adaptive Resolution). #[serde(skip)] pub interacting: bool, + /// A property scrub (Effect Controls, Timeline) or a Timeline drag of the playhead, keys or layer bars is in progress (Adaptive Resolution); cleared once the primary button is up. #[serde(skip)] pub property_interacting: bool, /// Extended Viewer: the comp-space region the viewer renders this frame (comp frame plus diff --git a/crates/ui-egui/tests/ui_timeline_interacting.rs b/crates/ui-egui/tests/ui_timeline_interacting.rs new file mode 100644 index 000000000..29f86b6ff --- /dev/null +++ b/crates/ui-egui/tests/ui_timeline_interacting.rs @@ -0,0 +1,115 @@ +use effectcraft_engine::Session; +use effectcraft_engine::project::LayerId; +use effectcraft_ui_egui::EffectcraftApp; +use egui::{Event, Pos2, pos2, vec2}; +use egui_kittest::Harness; +use serde_json::json; + +fn harness() -> (Harness<'static, EffectcraftApp>, LayerId, u64) { + let mut session = Session::default(); + session.execute("comp.new", json!({"name": "Keys", "width": 320, "height": 180, "frameRate": 30, "duration": 4})).unwrap(); + session.execute("layer.newSolid", json!({"name": "Box", "color": "#e04020", "width": 80, "height": 80})).unwrap(); + let id = session.active_comp().unwrap().layers[0].id; + for (time, value) in [(0.0, 0.0), (1.0, 100.0)] { + session.execute("prop.addKey", json!({"layer": id.0, "path": "transform/opacity", "time": time, "value": value})).unwrap(); + } + let uid = session.active_comp().unwrap().layer(id).unwrap().props.prop("transform/opacity").unwrap().uid; + session.execute("layer.select", json!({"layers": [id.0]})).unwrap(); + session.execute("view.fastPreviewMode", json!({"mode": "adaptive"})).unwrap(); + let mut harness = Harness::builder().with_size(vec2(1600.0, 1000.0)).build_eframe(|_| EffectcraftApp::new(session)); + harness.run_steps(3); + let context = harness.ctx.clone(); + effectcraft_ui_egui::menus::invoke(harness.state_mut(), &context, "timeline.reveal.opacity", json!({})).unwrap(); + harness.run_steps(4); + (harness, id, uid) +} + +fn rect(harness: &Harness<'_, EffectcraftApp>, id: &str) -> egui::Rect { + let entry = harness.state().auto.find(id).expect("timeline element"); + egui::Rect::from_min_size(pos2(entry.rect[0], entry.rect[1]), vec2(entry.rect[2], entry.rect[3])) +} + +fn keys(harness: &Harness<'_, EffectcraftApp>, uid: u64) -> Vec { + let mut positions: Vec = harness + .state() + .auto + .query(&format!("timeline.key.{uid}.")) + .iter() + .map(|entry| pos2(entry.rect[0] + entry.rect[2] / 2.0, entry.rect[1] + entry.rect[3] / 2.0)) + .collect(); + positions.sort_by(|left, right| left.x.total_cmp(&right.x)); + positions +} + +fn hold(harness: &mut Harness<'_, EffectcraftApp>, from: Pos2, to: Pos2) { + harness.input_mut().events.push(Event::PointerMoved(from)); + harness.step(); + harness.input_mut().events.push(Event::PointerButton { pos: from, button: egui::PointerButton::Primary, pressed: true, modifiers: Default::default() }); + harness.step(); + for step in 1..=10 { + harness.input_mut().events.push(Event::PointerMoved(from + (to - from) * (step as f32 / 10.0))); + harness.step(); + } +} + +fn release(harness: &mut Harness<'_, EffectcraftApp>, at: Pos2) { + harness.input_mut().events.push(Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed: false, modifiers: Default::default() }); + harness.run_steps(2); +} + +fn assert_adaptive_during_drag(harness: &Harness<'_, EffectcraftApp>) { + assert!(harness.state().ui.viewer.property_interacting); + assert!(harness.state().viewer_scale(1.0, 1.0) < 1.0); +} + +fn assert_full_resolution_after_release(harness: &Harness<'_, EffectcraftApp>) { + assert!(!harness.state().ui.viewer.property_interacting); + assert_eq!(harness.state().viewer_scale(1.0, 1.0), 1.0); +} + +#[test] +fn playhead_drag_uses_adaptive_resolution() { + let (mut harness, _, _) = harness(); + let ruler = rect(&harness, "timeline.ruler"); + let from = pos2(ruler.min.x + 40.0, ruler.max.y - 3.0); + let to = from + vec2(200.0, 0.0); + hold(&mut harness, from, to); + assert_adaptive_during_drag(&harness); + release(&mut harness, to); + assert_full_resolution_after_release(&harness); +} + +#[test] +fn layer_bar_drag_uses_adaptive_resolution() { + let (mut harness, layer, _) = harness(); + let from = rect(&harness, &format!("timeline.layer.{}.bar", layer.0)).center(); + let to = from + vec2(60.0, 0.0); + hold(&mut harness, from, to); + assert_adaptive_during_drag(&harness); + release(&mut harness, to); + assert_full_resolution_after_release(&harness); +} + +#[test] +fn key_drag_uses_adaptive_resolution() { + let (mut harness, _, uid) = harness(); + let from = keys(&harness, uid)[0]; + let to = from + vec2(60.0, 0.0); + hold(&mut harness, from, to); + assert_adaptive_during_drag(&harness); + release(&mut harness, to); + assert_full_resolution_after_release(&harness); +} + +#[test] +fn timeline_click_keeps_full_resolution() { + let (mut harness, _, _) = harness(); + let point = rect(&harness, "timeline.ruler").center(); + harness.input_mut().events.push(Event::PointerMoved(point)); + harness.step(); + harness.input_mut().events.push(Event::PointerButton { pos: point, button: egui::PointerButton::Primary, pressed: true, modifiers: Default::default() }); + harness.step(); + assert!(!harness.state().ui.viewer.property_interacting); + assert_eq!(harness.state().viewer_scale(1.0, 1.0), 1.0); + release(&mut harness, point); +} From 550aeb0ac9f6d36416109d6b3ccc330b3a8b7028 Mon Sep 17 00:00:00 2001 From: arnav-hiwarkar Date: Thu, 12 Nov 2026 19:00:04 +0530 Subject: [PATCH 2/5] #2047: tests for Adaptive Resolution during Timeline and Properties drags Drag/release tests for the playhead, timecode, layer bar, In trim, source slip, key drag, the In/Out/Duration cells and a Properties scrub: a draft while held, Full on the first frame after release. A click, a work-area drag (same pixels) and Fast Previews off keep Full. --- .../tests/it/ui_timeline_interacting.rs | 224 ++++++++++++------ 1 file changed, 145 insertions(+), 79 deletions(-) diff --git a/crates/ui-egui/tests/it/ui_timeline_interacting.rs b/crates/ui-egui/tests/it/ui_timeline_interacting.rs index 29f86b6ff..6ed4c719a 100644 --- a/crates/ui-egui/tests/it/ui_timeline_interacting.rs +++ b/crates/ui-egui/tests/it/ui_timeline_interacting.rs @@ -1,115 +1,181 @@ +//! Fast Previews ▸ Adaptive Resolution while dragging outside the viewer (After Effects): any +//! Timeline drag that changes the frame on screen (the time, or the comp's pixels) draws a draft +//! until release, and the first frame after the release is full resolution again. A plain click, +//! or a drag that changes nothing on screen, keeps Full. use effectcraft_engine::Session; -use effectcraft_engine::project::LayerId; use effectcraft_ui_egui::EffectcraftApp; use egui::{Event, Pos2, pos2, vec2}; use egui_kittest::Harness; use serde_json::json; -fn harness() -> (Harness<'static, EffectcraftApp>, LayerId, u64) { - let mut session = Session::default(); - session.execute("comp.new", json!({"name": "Keys", "width": 320, "height": 180, "frameRate": 30, "duration": 4})).unwrap(); - session.execute("layer.newSolid", json!({"name": "Box", "color": "#e04020", "width": 80, "height": 80})).unwrap(); - let id = session.active_comp().unwrap().layers[0].id; +/// The Timeline of a 10 s comp at 30 fps with a solid (opacity keys at 0 s and 1 s, revealed) +/// and a 20 s precomp trimmed to 3–7 s (its source runs past both ends, so it can slip), in +/// Adaptive Resolution. +struct Fixture { + h: Harness<'static, EffectcraftApp>, + solid: u64, + pre: u64, + opacity: u64, +} + +fn fixture(mode: &str) -> Fixture { + let mut s = Session::default(); + s.execute("comp.new", json!({"name": "Inner", "width": 320, "height": 180, "frameRate": 30, "duration": 20})).unwrap(); + s.execute("comp.new", json!({"name": "Main", "width": 320, "height": 180, "frameRate": 30, "duration": 10})).unwrap(); + let solid = s.execute("layer.newSolid", json!({"name": "Box", "color": "#e04020", "width": 80, "height": 80})).unwrap()["layer"].as_u64().unwrap(); for (time, value) in [(0.0, 0.0), (1.0, 100.0)] { - session.execute("prop.addKey", json!({"layer": id.0, "path": "transform/opacity", "time": time, "value": value})).unwrap(); + s.execute("prop.addKey", json!({"layer": solid, "path": "transform/opacity", "time": time, "value": value})).unwrap(); } - let uid = session.active_comp().unwrap().layer(id).unwrap().props.prop("transform/opacity").unwrap().uid; - session.execute("layer.select", json!({"layers": [id.0]})).unwrap(); - session.execute("view.fastPreviewMode", json!({"mode": "adaptive"})).unwrap(); - let mut harness = Harness::builder().with_size(vec2(1600.0, 1000.0)).build_eframe(|_| EffectcraftApp::new(session)); - harness.run_steps(3); - let context = harness.ctx.clone(); - effectcraft_ui_egui::menus::invoke(harness.state_mut(), &context, "timeline.reveal.opacity", json!({})).unwrap(); - harness.run_steps(4); - (harness, id, uid) + let pre = s.execute("layer.addItem", json!({"item": "Inner"})).unwrap()["layer"].as_u64().unwrap(); + s.execute("layer.timing", json!({"layers": [pre], "in": 3.0, "out": 7.0})).unwrap(); + let comp = s.active_comp().unwrap(); + let opacity = comp.layers.iter().find(|l| l.id.0 == solid).unwrap().props.prop("transform/opacity").unwrap().uid; + s.execute("layer.select", json!({"layers": [solid]})).unwrap(); + s.execute("view.fastPreviewMode", json!({"mode": mode})).unwrap(); + let mut h = Harness::builder().with_size(vec2(1600.0, 1000.0)).build_eframe(|_| EffectcraftApp::new(s)); + h.run_steps(3); + let ctx = h.ctx.clone(); + effectcraft_ui_egui::menus::invoke(h.state_mut(), &ctx, "timeline.reveal.opacity", json!({})).unwrap(); + h.run_steps(4); + Fixture { h, solid, pre, opacity } } -fn rect(harness: &Harness<'_, EffectcraftApp>, id: &str) -> egui::Rect { - let entry = harness.state().auto.find(id).expect("timeline element"); - egui::Rect::from_min_size(pos2(entry.rect[0], entry.rect[1]), vec2(entry.rect[2], entry.rect[3])) +fn rect(h: &Harness<'_, EffectcraftApp>, id: &str) -> egui::Rect { + let e = h.state().auto.find(id).unwrap_or_else(|| panic!("no {id}")); + egui::Rect::from_min_size(pos2(e.rect[0], e.rect[1]), vec2(e.rect[2], e.rect[3])) } -fn keys(harness: &Harness<'_, EffectcraftApp>, uid: u64) -> Vec { - let mut positions: Vec = harness - .state() - .auto - .query(&format!("timeline.key.{uid}.")) - .iter() - .map(|entry| pos2(entry.rect[0] + entry.rect[2] / 2.0, entry.rect[1] + entry.rect[3] / 2.0)) - .collect(); - positions.sort_by(|left, right| left.x.total_cmp(&right.x)); - positions +/// What a frame-changing drag must change: the project or the current time. +fn on_screen(h: &Harness<'_, EffectcraftApp>) -> (u64, effectcraft_time::Tick) { + (h.state().session.revision, h.state().session.time()) } -fn hold(harness: &mut Harness<'_, EffectcraftApp>, from: Pos2, to: Pos2) { - harness.input_mut().events.push(Event::PointerMoved(from)); - harness.step(); - harness.input_mut().events.push(Event::PointerButton { pos: from, button: egui::PointerButton::Primary, pressed: true, modifiers: Default::default() }); - harness.step(); +/// Presses at `from` and moves to `to` in ten steps, leaving the button down. +fn hold(h: &mut Harness<'_, EffectcraftApp>, from: Pos2, to: Pos2) { + h.input_mut().events.push(Event::PointerMoved(from)); + h.step(); + h.input_mut().events.push(Event::PointerButton { pos: from, button: egui::PointerButton::Primary, pressed: true, modifiers: Default::default() }); + h.step(); for step in 1..=10 { - harness.input_mut().events.push(Event::PointerMoved(from + (to - from) * (step as f32 / 10.0))); - harness.step(); + h.input_mut().events.push(Event::PointerMoved(from + (to - from) * (step as f32 / 10.0))); + h.step(); } } -fn release(harness: &mut Harness<'_, EffectcraftApp>, at: Pos2) { - harness.input_mut().events.push(Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed: false, modifiers: Default::default() }); - harness.run_steps(2); +/// Releases at `at` and runs exactly one frame: that frame must already be sharp. +fn release(h: &mut Harness<'_, EffectcraftApp>, at: Pos2) { + h.input_mut().events.push(Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed: false, modifiers: Default::default() }); + h.step(); } -fn assert_adaptive_during_drag(harness: &Harness<'_, EffectcraftApp>) { - assert!(harness.state().ui.viewer.property_interacting); - assert!(harness.state().viewer_scale(1.0, 1.0) < 1.0); +fn draft(h: &Harness<'_, EffectcraftApp>) -> bool { + h.state().viewer_scale(1.0, 1.0) < 1.0 } -fn assert_full_resolution_after_release(harness: &Harness<'_, EffectcraftApp>) { - assert!(!harness.state().ui.viewer.property_interacting); - assert_eq!(harness.state().viewer_scale(1.0, 1.0), 1.0); +/// Drags from `from` by `by`: a draft while held, Full on the first frame after release. +fn assert_draft_while_dragging(f: &mut Fixture, from: Pos2, by: egui::Vec2) { + let before = on_screen(&f.h); + hold(&mut f.h, from, from + by); + assert_ne!(on_screen(&f.h), before, "the drag changed nothing on screen"); + assert!(f.h.state().ui.viewer.property_interacting, "not interacting while dragging"); + assert!(draft(&f.h), "full resolution while dragging"); + release(&mut f.h, from + by); + assert!(!f.h.state().ui.viewer.property_interacting, "still interacting after release"); + assert!(!draft(&f.h), "the first frame after release is a draft"); } #[test] -fn playhead_drag_uses_adaptive_resolution() { - let (mut harness, _, _) = harness(); - let ruler = rect(&harness, "timeline.ruler"); - let from = pos2(ruler.min.x + 40.0, ruler.max.y - 3.0); - let to = from + vec2(200.0, 0.0); - hold(&mut harness, from, to); - assert_adaptive_during_drag(&harness); - release(&mut harness, to); - assert_full_resolution_after_release(&harness); +fn playhead_drag_draws_a_draft() { + let mut f = fixture("adaptive"); + let ruler = rect(&f.h, "timeline.ruler"); + assert_draft_while_dragging(&mut f, pos2(ruler.min.x + 40.0, ruler.max.y - 3.0), vec2(200.0, 0.0)); } #[test] -fn layer_bar_drag_uses_adaptive_resolution() { - let (mut harness, layer, _) = harness(); - let from = rect(&harness, &format!("timeline.layer.{}.bar", layer.0)).center(); - let to = from + vec2(60.0, 0.0); - hold(&mut harness, from, to); - assert_adaptive_during_drag(&harness); - release(&mut harness, to); - assert_full_resolution_after_release(&harness); +fn timecode_drag_draws_a_draft() { + let mut f = fixture("adaptive"); + let from = rect(&f.h, "timeline.timecode").center(); + assert_draft_while_dragging(&mut f, from, vec2(60.0, 0.0)); } #[test] -fn key_drag_uses_adaptive_resolution() { - let (mut harness, _, uid) = harness(); - let from = keys(&harness, uid)[0]; - let to = from + vec2(60.0, 0.0); - hold(&mut harness, from, to); - assert_adaptive_during_drag(&harness); - release(&mut harness, to); - assert_full_resolution_after_release(&harness); +fn layer_bar_drag_draws_a_draft() { + let mut f = fixture("adaptive"); + let from = rect(&f.h, &format!("timeline.layer.{}.bar", f.solid)).center(); + assert_draft_while_dragging(&mut f, from, vec2(60.0, 0.0)); +} + +#[test] +fn in_point_trim_draws_a_draft() { + let mut f = fixture("adaptive"); + let from = rect(&f.h, &format!("timeline.layer.{}.bar.in", f.pre)).center(); + assert_draft_while_dragging(&mut f, from, vec2(60.0, 0.0)); +} + +#[test] +fn source_slip_draws_a_draft() { + let mut f = fixture("adaptive"); + let from = rect(&f.h, &format!("timeline.layer.{}.sourcel", f.pre)).center(); + assert_draft_while_dragging(&mut f, from, vec2(60.0, 0.0)); +} + +#[test] +fn key_drag_draws_a_draft() { + let mut f = fixture("adaptive"); + let from = rect(&f.h, &format!("timeline.key.{}.0", f.opacity)).center(); + assert_draft_while_dragging(&mut f, from, vec2(60.0, 0.0)); +} + +#[test] +fn in_out_and_duration_cell_drags_draw_a_draft() { + for kind in ["in", "out", "duration"] { + let mut f = fixture("adaptive"); + effectcraft_ui_egui::panels::timeline::set_column(&mut f.h.state_mut().ui.timeline, kind, true).unwrap(); + f.h.run_steps(3); + let from = rect(&f.h, &format!("timeline.layer.{}.{kind}", f.pre)).center(); + assert_draft_while_dragging(&mut f, from, vec2(60.0, 0.0)); + } +} + +#[test] +fn properties_scrub_draws_a_draft() { + let mut f = fixture("adaptive"); + let ctx = f.h.ctx.clone(); + effectcraft_ui_egui::menus::invoke(f.h.state_mut(), &ctx, "window.panel", json!({"panel": "properties"})).unwrap(); + f.h.run_steps(3); + let from = rect(&f.h, &format!("properties.prop.{}.value", f.opacity)).center(); + assert_draft_while_dragging(&mut f, from, vec2(40.0, 0.0)); +} + +#[test] +fn work_area_drag_keeps_full_resolution() { + let mut f = fixture("adaptive"); + let from = rect(&f.h, "timeline.workArea.end").center(); + let before = f.h.state().session.active_comp().unwrap().work_area; + hold(&mut f.h, from, from + vec2(-80.0, 0.0)); + assert_ne!(f.h.state().session.active_comp().unwrap().work_area, before, "the work area moved"); + assert!(!draft(&f.h), "a work-area drag changes no pixels"); + release(&mut f.h, from); } #[test] fn timeline_click_keeps_full_resolution() { - let (mut harness, _, _) = harness(); - let point = rect(&harness, "timeline.ruler").center(); - harness.input_mut().events.push(Event::PointerMoved(point)); - harness.step(); - harness.input_mut().events.push(Event::PointerButton { pos: point, button: egui::PointerButton::Primary, pressed: true, modifiers: Default::default() }); - harness.step(); - assert!(!harness.state().ui.viewer.property_interacting); - assert_eq!(harness.state().viewer_scale(1.0, 1.0), 1.0); - release(&mut harness, point); + let mut f = fixture("adaptive"); + let point = rect(&f.h, "timeline.ruler").center(); + f.h.input_mut().events.push(Event::PointerMoved(point)); + f.h.step(); + f.h.input_mut().events.push(Event::PointerButton { pos: point, button: egui::PointerButton::Primary, pressed: true, modifiers: Default::default() }); + f.h.run_steps(3); + assert!(!draft(&f.h)); + release(&mut f.h, point); +} + +#[test] +fn fast_previews_off_keeps_full_resolution() { + let mut f = fixture("off"); + let ruler = rect(&f.h, "timeline.ruler"); + let from = pos2(ruler.min.x + 40.0, ruler.max.y - 3.0); + hold(&mut f.h, from, from + vec2(200.0, 0.0)); + assert!(!draft(&f.h)); + release(&mut f.h, from); } From 724865e3405233eef2db75b9e09bfade30a6c11e Mon Sep 17 00:00:00 2001 From: arnav-hiwarkar Date: Thu, 12 Nov 2026 19:00:04 +0530 Subject: [PATCH 3/5] #2047: Fast Previews: any frame-changing Timeline drag draws a draft One rule instead of a flag per gesture: DragWatch snapshots the active comp and its current frame when the Timeline (and the Properties panel) starts its pass, and after the pass, while the primary button drags past a click, a new frame or a comp that no longer draws the same pixels sets property_interacting until release. This covers the playhead and timecode, layer moves and trims, slips, key drags and alt-scale, Quick Offset, the In/Out/Duration cells, property scrubs and the Graph Editor, and any gesture added later. Clicks, scrolling, zooming, the work area and selection keep Full. It replaces the prop.set-only check in apply_actions. --- crates/ui-egui/src/panels.rs | 1 + crates/ui-egui/src/panels/drag_preview.rs | 47 +++++++++++++++++++++++ crates/ui-egui/src/panels/properties.rs | 2 + crates/ui-egui/src/panels/timeline.rs | 10 ++--- crates/ui-egui/src/state.rs | 4 +- 5 files changed, 57 insertions(+), 7 deletions(-) create mode 100644 crates/ui-egui/src/panels/drag_preview.rs diff --git a/crates/ui-egui/src/panels.rs b/crates/ui-egui/src/panels.rs index ccff0fdcd..8feb8c8c5 100644 --- a/crates/ui-egui/src/panels.rs +++ b/crates/ui-egui/src/panels.rs @@ -9,6 +9,7 @@ pub mod crypto_pick; pub mod delete_items; pub mod dialogs; pub mod dialogs_3d; +pub(crate) mod drag_preview; pub mod effect_controls; pub mod effects_presets; pub mod essential; diff --git a/crates/ui-egui/src/panels/drag_preview.rs b/crates/ui-egui/src/panels/drag_preview.rs new file mode 100644 index 000000000..9d0d42f7b --- /dev/null +++ b/crates/ui-egui/src/panels/drag_preview.rs @@ -0,0 +1,47 @@ +//! Fast Previews ▸ Adaptive Resolution for drags outside the viewer: as in After Effects, a drag +//! that changes the frame on screen (scrubbing the time, moving or trimming layers, slipping, +//! dragging keys, scrubbing values) draws a draft until the button is released. + +use std::sync::Arc; + +use effectcraft_engine::project::{Comp, ItemId}; + +use crate::EffectcraftApp; + +/// The frame on screen when a panel starts its pass: the active comp and its current frame. +/// [`DragWatch::end`] compares it with the frame after the panel ran its gestures, so every drag +/// the panel handles is covered without a flag per gesture. +pub(crate) struct DragWatch { + before: Option<(ItemId, Arc, i64)>, +} + +impl DragWatch { + pub(crate) fn begin(app: &EffectcraftApp) -> Self { + let before = app.session.active_comp_id().and_then(|id| { + let comp = app.session.project.comp_arc(id)?; + let frame = comp.frame_rate.frame_at(app.session.time()); + Some((id, comp, frame)) + }); + Self { before } + } + + /// While the primary button drags (moved past a click), a change of the current frame or of + /// the active comp's pixels since [`Self::begin`] sets `property_interacting`, which stays + /// set until the button is up (`App::frame`). A click, a held button, or a drag that draws + /// the same pixels (scrolling, zooming, the work area, selecting) keeps Full. + pub(crate) fn end(self, app: &mut EffectcraftApp, ctx: &egui::Context) { + let Some((id, comp, frame)) = self.before else { return }; + if app.ui.viewer.property_interacting || !ctx.input(|i| i.pointer.primary_down() && i.pointer.is_decidedly_dragging()) { + return; + } + if app.session.active_comp_id() != Some(id) { + return; + } + let Some(now) = app.session.project.comp_arc(id) else { return }; + let moved = comp.frame_rate.frame_at(app.session.time()) != frame; + if moved || (!Arc::ptr_eq(&comp, &now) && !now.same_pixels(&comp)) { + app.ui.viewer.property_interacting = true; + ctx.request_repaint(); + } + } +} diff --git a/crates/ui-egui/src/panels/properties.rs b/crates/ui-egui/src/panels/properties.rs index 4edcbb31a..74ae4daec 100644 --- a/crates/ui-egui/src/panels/properties.rs +++ b/crates/ui-egui/src/panels/properties.rs @@ -67,6 +67,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) { p.text(rect.center(), Align2::CENTER_CENTER, crate::i18n::tr("Select a layer to see its properties"), Tokens::ui(12.0), t.text_faint); return; }; + let watch = super::drag_preview::DragWatch::begin(app); let project = app.session.project.clone(); let expr = app.session.expr.clone(); let now = app.session.time(); @@ -190,6 +191,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) { app.ui.status = e; } } + watch.end(app, &ctx); } fn section_header(app: &mut EffectcraftApp, p: &egui::Painter, x0: f32, w: f32, y: f32, title: &str, auto: &str) { diff --git a/crates/ui-egui/src/panels/timeline.rs b/crates/ui-egui/src/panels/timeline.rs index 4de3233e8..4d35de005 100644 --- a/crates/ui-egui/src/panels/timeline.rs +++ b/crates/ui-egui/src/panels/timeline.rs @@ -1963,6 +1963,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) { return; }; let Some(comp) = app.session.project.comp_arc(cid) else { return }; + let watch = super::drag_preview::DragWatch::begin(app); let mut tl = layout(app, ui, rect, cid, &comp); let g = &mut tl; if !ui.input(|i| i.pointer.primary_down()) { @@ -2022,7 +2023,8 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) { drop_targets(app, ui, g); let Rw { tl, ui_actions, .. } = rw; apply_ui_acts(app, &tl.comp, ui_actions); - apply_actions(app, ui, &tl.ctx, tl.actions); + apply_actions(app, &tl.ctx, tl.actions); + watch.end(app, &tl.ctx); } /// Applies the UI-only changes the frame collected (twirls, time, ending an undo merge). @@ -2081,11 +2083,7 @@ fn apply_ui_acts(app: &mut EffectcraftApp, comp: &Comp, ui_actions: Vec) } /// Runs the commands the frame collected through [`crate::menus::invoke`]. -fn apply_actions(app: &mut EffectcraftApp, ui: &mut egui::Ui, ctx: &egui::Context, actions: Vec<(String, serde_json::Value)>) { - if ui.input(|i| i.pointer.primary_down()) && actions.iter().any(|(id, _)| id == "prop.set") { - app.ui.viewer.property_interacting = true; - ctx.request_repaint(); - } +fn apply_actions(app: &mut EffectcraftApp, ctx: &egui::Context, actions: Vec<(String, serde_json::Value)>) { for (id, params) in actions { if id == "__endMerge" { app.session.history.merge_key = None; diff --git a/crates/ui-egui/src/state.rs b/crates/ui-egui/src/state.rs index ee415e36c..d71114b4d 100644 --- a/crates/ui-egui/src/state.rs +++ b/crates/ui-egui/src/state.rs @@ -265,7 +265,9 @@ pub struct ViewerState { /// The pointer is dragging in the viewer this frame (Adaptive Resolution). #[serde(skip)] pub interacting: bool, - /// A property scrub (Effect Controls, Timeline) or a Timeline drag of the playhead, keys or layer bars is in progress (Adaptive Resolution); cleared once the primary button is up. + /// A drag outside the viewer changed the frame on screen: a property scrub in Effect Controls, + /// or any Timeline or Properties drag ([`crate::panels::drag_preview`]). Adaptive Resolution + /// draws a draft until the primary button is up, which clears it. #[serde(skip)] pub property_interacting: bool, /// Extended Viewer: the comp-space region the viewer renders this frame (comp frame plus From 9ed7954a9742104e8d3a6ff6bffbb23562845637 Mon Sep 17 00:00:00 2001 From: arnav-hiwarkar Date: Thu, 12 Nov 2026 19:08:18 +0530 Subject: [PATCH 4/5] #2047: markers no expression reads don't drop the resolution Compare the comp the way the frame cache does (#1083): markers count as pixels only when an expression reads them, so dragging a marker keeps Full. Tighten the click and Fast Previews Off tests so they prove the gesture reached the app. --- crates/ui-egui/src/panels/drag_preview.rs | 17 +++++++++-------- .../tests/it/ui_timeline_interacting.rs | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/crates/ui-egui/src/panels/drag_preview.rs b/crates/ui-egui/src/panels/drag_preview.rs index 9d0d42f7b..4384095c7 100644 --- a/crates/ui-egui/src/panels/drag_preview.rs +++ b/crates/ui-egui/src/panels/drag_preview.rs @@ -8,9 +8,9 @@ use effectcraft_engine::project::{Comp, ItemId}; use crate::EffectcraftApp; -/// The frame on screen when a panel starts its pass: the active comp and its current frame. -/// [`DragWatch::end`] compares it with the frame after the panel ran its gestures, so every drag -/// the panel handles is covered without a flag per gesture. +/// The active comp and its current frame index when a panel starts its pass. [`DragWatch::end`] +/// compares them with the comp and frame after the panel ran its gestures, so every drag the +/// panel handles is covered without a flag per gesture. pub(crate) struct DragWatch { before: Option<(ItemId, Arc, i64)>, } @@ -25,10 +25,11 @@ impl DragWatch { Self { before } } - /// While the primary button drags (moved past a click), a change of the current frame or of - /// the active comp's pixels since [`Self::begin`] sets `property_interacting`, which stays - /// set until the button is up (`App::frame`). A click, a held button, or a drag that draws - /// the same pixels (scrolling, zooming, the work area, selecting) keeps Full. + /// While the primary button drags (moved past a click, or held past one), a change of the + /// current frame or of the active comp's pixels since [`Self::begin`] sets + /// `property_interacting`, which stays set until the button is up (`App::frame`). A click, + /// or a drag that draws the same pixels (scrolling, zooming, the work area, selecting, markers + /// no expression reads, as for the frame cache) keeps Full. pub(crate) fn end(self, app: &mut EffectcraftApp, ctx: &egui::Context) { let Some((id, comp, frame)) = self.before else { return }; if app.ui.viewer.property_interacting || !ctx.input(|i| i.pointer.primary_down() && i.pointer.is_decidedly_dragging()) { @@ -39,7 +40,7 @@ impl DragWatch { } let Some(now) = app.session.project.comp_arc(id) else { return }; let moved = comp.frame_rate.frame_at(app.session.time()) != frame; - if moved || (!Arc::ptr_eq(&comp, &now) && !now.same_pixels(&comp)) { + if moved || (!Arc::ptr_eq(&comp, &now) && !now.same_pixels_with(&comp, app.session.project.reads_markers(), &|_| false)) { app.ui.viewer.property_interacting = true; ctx.request_repaint(); } diff --git a/crates/ui-egui/tests/it/ui_timeline_interacting.rs b/crates/ui-egui/tests/it/ui_timeline_interacting.rs index 6ed4c719a..e2cb2112a 100644 --- a/crates/ui-egui/tests/it/ui_timeline_interacting.rs +++ b/crates/ui-egui/tests/it/ui_timeline_interacting.rs @@ -158,24 +158,42 @@ fn work_area_drag_keeps_full_resolution() { release(&mut f.h, from); } +/// Markers are pixels only to the expressions that read them (#1083): moving one keeps Full. +#[test] +fn marker_drag_keeps_full_resolution() { + let mut f = fixture("adaptive"); + f.h.state_mut().session.execute("comp.addMarker", json!({"time": 2.0})).unwrap(); + f.h.run_steps(3); + let from = rect(&f.h, "timeline.marker.0").center(); + let before = f.h.state().session.active_comp().unwrap().markers[0].time; + hold(&mut f.h, from, from + vec2(80.0, 0.0)); + assert_ne!(f.h.state().session.active_comp().unwrap().markers[0].time, before, "the marker moved"); + assert!(!draft(&f.h), "a marker no expression reads changes no pixels"); + release(&mut f.h, from); +} + #[test] fn timeline_click_keeps_full_resolution() { let mut f = fixture("adaptive"); let point = rect(&f.h, "timeline.ruler").center(); + let before = f.h.state().session.time(); f.h.input_mut().events.push(Event::PointerMoved(point)); f.h.step(); f.h.input_mut().events.push(Event::PointerButton { pos: point, button: egui::PointerButton::Primary, pressed: true, modifiers: Default::default() }); f.h.run_steps(3); + assert_ne!(f.h.state().session.time(), before, "the click moved the playhead"); assert!(!draft(&f.h)); release(&mut f.h, point); } +/// The drag is still noted, but Fast Previews Off never lowers the resolution. #[test] fn fast_previews_off_keeps_full_resolution() { let mut f = fixture("off"); let ruler = rect(&f.h, "timeline.ruler"); let from = pos2(ruler.min.x + 40.0, ruler.max.y - 3.0); hold(&mut f.h, from, from + vec2(200.0, 0.0)); + assert!(f.h.state().ui.viewer.property_interacting); assert!(!draft(&f.h)); release(&mut f.h, from); } From 8b481f3811ab3d276c78d331ef80d6a76dc2f676 Mon Sep 17 00:00:00 2001 From: arnav-hiwarkar Date: Thu, 12 Nov 2026 19:18:24 +0530 Subject: [PATCH 5/5] #2047: a layer's audio counts when something draws it Compare the comp exactly as the frame cache does: a layer's Audio switch, Audio group and audio effects are pixels when a layer picks its audio or an expression reads audio, before or after the edit. Scrubbing Audio Levels read by an expression now draws a draft; with nothing drawing the audio it keeps Full. --- crates/ui-egui/src/panels/drag_preview.rs | 36 +++++++++++-------- .../tests/it/ui_timeline_interacting.rs | 30 ++++++++++++++++ 2 files changed, 51 insertions(+), 15 deletions(-) diff --git a/crates/ui-egui/src/panels/drag_preview.rs b/crates/ui-egui/src/panels/drag_preview.rs index 4384095c7..e0f53fb12 100644 --- a/crates/ui-egui/src/panels/drag_preview.rs +++ b/crates/ui-egui/src/panels/drag_preview.rs @@ -4,43 +4,49 @@ use std::sync::Arc; -use effectcraft_engine::project::{Comp, ItemId}; +use effectcraft_engine::project::{ItemId, Project}; use crate::EffectcraftApp; -/// The active comp and its current frame index when a panel starts its pass. [`DragWatch::end`] -/// compares them with the comp and frame after the panel ran its gestures, so every drag the -/// panel handles is covered without a flag per gesture. +/// The project, the active comp and its current frame index when a panel starts its pass. +/// [`DragWatch::end`] compares them with the comp and frame after the panel ran its gestures, so +/// every drag the panel handles is covered without a flag per gesture. pub(crate) struct DragWatch { - before: Option<(ItemId, Arc, i64)>, + before: Option<(ItemId, Arc, i64)>, } impl DragWatch { pub(crate) fn begin(app: &EffectcraftApp) -> Self { + let project = app.session.project.clone(); let before = app.session.active_comp_id().and_then(|id| { - let comp = app.session.project.comp_arc(id)?; - let frame = comp.frame_rate.frame_at(app.session.time()); - Some((id, comp, frame)) + let frame = project.comp_arc(id)?.frame_rate.frame_at(app.session.time()); + Some((id, project, frame)) }); Self { before } } /// While the primary button drags (moved past a click, or held past one), a change of the /// current frame or of the active comp's pixels since [`Self::begin`] sets - /// `property_interacting`, which stays set until the button is up (`App::frame`). A click, - /// or a drag that draws the same pixels (scrolling, zooming, the work area, selecting, markers - /// no expression reads, as for the frame cache) keeps Full. + /// `property_interacting`, which stays set until the button is up (`App::frame`). Pixels are + /// compared as the frame cache does: markers count when an expression reads them, a layer's + /// audio when something draws it, before or after the edit. A click, or a drag that draws + /// the same pixels (scrolling, zooming, the work area, selecting) keeps Full. pub(crate) fn end(self, app: &mut EffectcraftApp, ctx: &egui::Context) { - let Some((id, comp, frame)) = self.before else { return }; + let Some((id, project, frame)) = self.before else { return }; if app.ui.viewer.property_interacting || !ctx.input(|i| i.pointer.primary_down() && i.pointer.is_decidedly_dragging()) { return; } if app.session.active_comp_id() != Some(id) { return; } - let Some(now) = app.session.project.comp_arc(id) else { return }; - let moved = comp.frame_rate.frame_at(app.session.time()) != frame; - if moved || (!Arc::ptr_eq(&comp, &now) && !now.same_pixels_with(&comp, app.session.project.reads_markers(), &|_| false)) { + let (Some(was), Some(now)) = (project.comp_arc(id), app.session.project.comp_arc(id)) else { return }; + let moved = was.frame_rate.frame_at(app.session.time()) != frame; + let edited = || { + let current = &app.session.project; + let heard = current.heard_layers().union(&project.heard_layers()); + !now.same_pixels_with(&was, current.reads_markers(), &|l| heard.contains(id, l)) + }; + if moved || (!Arc::ptr_eq(&was, &now) && edited()) { app.ui.viewer.property_interacting = true; ctx.request_repaint(); } diff --git a/crates/ui-egui/tests/it/ui_timeline_interacting.rs b/crates/ui-egui/tests/it/ui_timeline_interacting.rs index e2cb2112a..5cf11ad0e 100644 --- a/crates/ui-egui/tests/it/ui_timeline_interacting.rs +++ b/crates/ui-egui/tests/it/ui_timeline_interacting.rs @@ -158,6 +158,36 @@ fn work_area_drag_keeps_full_resolution() { release(&mut f.h, from); } +/// Scrubs the precomp's Audio Levels in the Timeline; `reads_audio` adds an expression that +/// reads audio. Returns whether the viewer drew a draft while held. +fn audio_levels_scrub(reads_audio: bool) -> bool { + let mut f = fixture("adaptive"); + if reads_audio { + let rotation = json!({"layer": f.solid, "path": "transform/rotation", "expression": "thisComp.layer(1).audioLevels; value"}); + f.h.state_mut().session.execute("prop.setExpression", rotation).unwrap(); + } + let uid = f.h.state().session.active_comp().unwrap().layers.iter().find(|l| l.id.0 == f.pre).unwrap().props.prop("audio/levels").unwrap().uid; + let tl = &mut f.h.state_mut().ui.timeline; + tl.open_layers.insert(f.pre); + tl.layer_reveal.insert(f.pre, vec!["props".into()]); + tl.reveal_props.insert(uid); + f.h.run_steps(3); + let from = rect(&f.h, &format!("timeline.prop.{uid}.value.0")).center(); + let before = on_screen(&f.h); + hold(&mut f.h, from, from + vec2(40.0, 0.0)); + assert_ne!(on_screen(&f.h), before, "the scrub changed the levels"); + let draft = draft(&f.h); + release(&mut f.h, from); + draft +} + +/// A layer's audio is pixels only when something draws it (an expression reading audio here). +#[test] +fn audio_levels_scrub_draws_a_draft_only_when_audio_is_drawn() { + assert!(audio_levels_scrub(true), "an expression reads the audio"); + assert!(!audio_levels_scrub(false), "nothing draws the audio"); +} + /// Markers are pixels only to the expressions that read them (#1083): moving one keeps Full. #[test] fn marker_drag_keeps_full_resolution() {