Merge branch 'main' into pr72-land

# Conflicts:
#	docs/gaps.md
This commit is contained in:
bflatastic
2026-10-06 10:55:43 +07:00
15 changed files with 647 additions and 92 deletions
+4 -1
View File
@@ -123,6 +123,7 @@ fn gaps_of(h: &mut Harness<'_, EffectcraftApp>, p: PanelKind) -> Vec<String> {
}
#[test]
#[cfg_attr(not(debug_assertions), ignore = "egui records widget types only in debug builds")]
fn every_panel_registers_automation_ids_for_its_widgets() {
let mut s = session();
// Content for the selection-driven panels: the title (text with effects), a Render Queue
@@ -133,7 +134,9 @@ fn every_panel_registers_automation_ids_for_its_widgets() {
let title = s.active_comp().unwrap().layers.iter().find(|l| l.name == "EFFECTCRAFT").map(|l| l.id.0).unwrap();
let mut h = harness(s);
h.state_mut().ui.layer_panel = Some(title);
// egui records widget types (to tell labels from controls) with this debug option.
// egui records widget types (to tell labels from controls) with this debug option, which
// only debug builds have.
#[cfg(debug_assertions)]
h.ctx.all_styles_mut(|st| st.debug.show_interactive_widgets = true);
let mut gaps = vec![];
for p in PanelKind::ALL {
+44
View File
@@ -51,3 +51,47 @@ fn an_edit_in_another_comp_keeps_the_cached_frames_and_undo_finds_them_again() {
// B's frame is still there too.
assert!(h.state().frames.is_cached(&effectcraft_ui_egui::frames::FrameKey { frame: 0, ..b_frame }));
}
/// Issue #65: while edits keep coming (a layer dragged in the viewer), only the viewer's frame
/// renders; prefetching the frames around it waits until the edits pause (they would be stale at
/// the next step, and would hold the CPU and GPU the next viewer frame needs), then resumes.
#[test]
fn prefetch_waits_while_edits_keep_coming() {
let mut s = Session::default();
let c = s.execute("comp.new", json!({"name": "Drag", "width": 64, "height": 36, "duration": 2})).unwrap()["comp"].as_u64().unwrap();
let solid = s.execute("layer.newSolid", json!({"color": "#3080ff", "width": 16, "height": 16})).unwrap()["layer"].as_u64().unwrap();
// Short steps: input time advances 50 ms per frame.
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).with_step_dt(0.05).build_eframe(|_| EffectcraftApp::new(s));
settle(&mut h);
let frame = |h: &Harness<'_, EffectcraftApp>| {
let app = h.state();
let comp = app.session.project.comp(ItemId(c)).unwrap();
comp.frame_rate.frame_at(app.session.time())
};
for i in 1..=8 {
let v = json!([20.0 + 2.0 * i as f64, 18.0, 0.0]);
h.state_mut().session.execute("prop.set", json!({"layer": solid, "path": "transform/position", "value": v, "merge": "drag"})).unwrap();
h.step();
// The viewer's frame renders...
for _ in 0..500 {
if !h.state().frames.urgent_pending() {
break;
}
std::thread::sleep(std::time::Duration::from_millis(2));
}
h.step();
// ...and nothing else is queued or cached for this state of the comp.
let series = h.state().shown_series(ItemId(c));
assert_eq!(h.state().frames.cached_frames(&series), vec![frame(&h)], "edit {i}");
assert_eq!(h.state().frames.inflight(), 0, "edit {i}");
}
// The edits pause: the frames around the current one fill in.
settle(&mut h);
for _ in 0..20 {
h.step();
std::thread::sleep(std::time::Duration::from_millis(10));
}
settle(&mut h);
let series = h.state().shown_series(ItemId(c));
assert!(h.state().frames.cached_frames(&series).len() > 1, "prefetch resumed");
}
+97
View File
@@ -166,3 +166,100 @@ fn nested_comp_markers_show_on_the_precomp_bar() {
// (29.97 fps: the marker's frame is at 1.001 s)
assert!((h.state().session.time().seconds() - 1.0).abs() < 0.034, "{}", h.state().session.time().seconds());
}
/// Issue #46: a panel dragged by its panel-menu (hamburger) button onto the left edge of another
/// group docks there as its own group; dragging the gap between panels resizes them.
#[test]
fn panels_dock_beside_others_and_gutters_resize_them() {
let (mut h, _, _) = harness();
let dock = |h: &Harness<'_, EffectcraftApp>| h.state().ui.dock.clone();
// Show Effect Controls in its group so its menu button is on screen, then drag by it.
let tab = rect(&h, "panel.tab.EffectControls");
click_n(&mut h, tab.center(), 1);
let grip = rect(&h, "panel.menu.EffectControls").center();
let tl = rect(&h, "panel.Timeline");
drag(&mut h, grip, pos2(tl.min.x + tl.width() * 0.08, tl.center().y));
assert_eq!(group_of(&dock(&h), PanelKind::EffectControls), Some(vec![PanelKind::EffectControls]));
assert!(!group_of(&dock(&h), PanelKind::Timeline).unwrap().contains(&PanelKind::EffectControls));
let (fx, tl) = (rect(&h, "panel.EffectControls"), rect(&h, "panel.Timeline"));
assert!(fx.max.x <= tl.min.x + 1.0 && (fx.center().y - tl.center().y).abs() < tl.height(), "{fx:?} {tl:?}");
// The gutter on the Project panel's right edge: dragging it 60 px widens the panel by 60.
let project = rect(&h, "panel.Project");
let gutter = h
.state()
.auto
.previous
.iter()
.filter(|e| e.id.starts_with("dock.gutter.") && e.rect[3] > e.rect[2])
.map(|e| egui::Rect::from_min_size(pos2(e.rect[0], e.rect[1]), egui::vec2(e.rect[2], e.rect[3])))
.filter(|g| g.y_range().contains(project.center().y))
.min_by(|a, b| (a.center().x - project.max.x).abs().total_cmp(&(b.center().x - project.max.x).abs()))
.expect("a gutter beside the Project panel");
drag(&mut h, gutter.center(), gutter.center() + egui::vec2(60.0, 0.0));
let wider = rect(&h, "panel.Project");
assert!((wider.width() - project.width() - 60.0).abs() < 2.0, "{} → {}", project.width(), wider.width());
}
/// Issue #45: the Project panel's details (name, size, duration) stay inside the panel with a
/// margin, cut short with "…" when they don't fit; so does the hint shown with nothing selected.
#[test]
fn project_details_stay_inside_the_panel() {
let (mut h, pre, _) = harness();
let long = "A composition with a very long name that could never fit beside the thumbnail".to_string();
h.state_mut().session.execute("project.rename", json!({"item": pre, "name": long})).unwrap();
h.state_mut().session.state.project_selection = vec![ItemId(pre)];
h.run_steps(3);
let panel = rect(&h, "panel.Project");
for id in ["project.details.name", "project.details.0", "project.details.1"] {
let r = rect(&h, id);
assert!(r.max.x <= panel.max.x - 9.0 && r.width() > 10.0, "{id}: {r:?} in {panel:?}");
}
h.state_mut().session.state.project_selection.clear();
h.run_steps(3);
let r = rect(&h, "project.details.hint");
assert!(r.min.x >= panel.min.x + 9.0 && r.max.x <= panel.max.x - 9.0, "{r:?} in {panel:?}");
}
/// A file dropped on the window (what the windowing layer hands egui).
#[derive(Debug)]
struct Dropped(std::path::PathBuf);
impl egui::DroppedFile for Dropped {
fn path(&self) -> &std::path::Path {
&self.0
}
fn bytes(&self) -> Result<Vec<u8>, String> {
std::fs::read(&self.0).map_err(|e| e.to_string())
}
}
/// Issue #44: double-clicking the Project panel's empty area asks for files to import (as After
/// Effects' File ▸ Import ▸ File... does), and files dropped on the window are imported. (Tests
/// have no media decoders: what is checked is that the import runs with those files.)
#[test]
fn project_empty_area_double_click_and_dropped_files_import() {
let (mut h, _, _) = harness();
let png = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("../../assets/app-icon/hicolor/16x16/apps/ai.storyteller.effectcraft.png");
let png = std::fs::canonicalize(png).unwrap().to_string_lossy().to_string();
let asked = std::sync::Arc::new(std::sync::atomic::AtomicUsize::new(0));
let (a, p) = (asked.clone(), png.clone());
h.state_mut().hooks.pick_files = Some(Box::new(move |_| {
a.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
vec![p.clone()]
}));
let imports = |h: &Harness<'_, EffectcraftApp>| h.state().session.journal.iter().filter(|(c, p)| c == "file.import" && p["paths"] == json!([png])).count();
// Below the last row.
let last = rect(&h, "project.item.2");
let empty = rect(&h, "project.empty");
click_n(&mut h, pos2(empty.center().x, (last.max.y + empty.max.y) / 2.0), 2);
assert_eq!(asked.load(std::sync::atomic::Ordering::Relaxed), 1, "the file dialog opened");
assert_eq!(imports(&h), 1, "the picked file was imported");
// A double-click on a row opens that item instead.
let row = rect(&h, "project.item.2.name");
click_n(&mut h, row.center(), 2);
assert_eq!(asked.load(std::sync::atomic::Ordering::Relaxed), 1);
// Dropping a file on the window imports it.
h.input_mut().dropped_files.push(std::sync::Arc::new(Dropped(png.clone().into())));
h.run_steps(2);
assert_eq!(imports(&h), 2, "the dropped file was imported");
}
+25
View File
@@ -46,6 +46,31 @@ fn edited(h: &Harness<'_, EffectcraftApp>) -> (u64, String, usize, usize) {
(e.layer.0, layer_doc(s, e.layer).unwrap().text, e.anchor, e.caret)
}
#[test]
fn type_tool_skips_hidden_and_unsoloed_text_layers() {
for switch in ["video", "solo"] {
let mut s = Session::default();
s.execute("comp.new", json!({"name": "Type", "width": 640, "height": 360, "duration": 2})).unwrap();
let mut ids = vec![];
for _ in 0..2 {
let lid = s.execute("layer.newText", json!({"text": "alpha beta", "size": 80, "position": [100, 200], "justify": "left"})).unwrap()["layer"]
.as_u64()
.unwrap();
ids.push(lid);
}
let (target, value) = if switch == "video" { (ids[1], false) } else { (ids[0], true) };
s.execute("layer.setSwitch", json!({"layers": [target], "switch": switch, "value": value})).unwrap();
s.execute("edit.deselectAll", json!({})).unwrap();
let mut h = Harness::builder().with_size(egui::vec2(1600.0, 1000.0)).build_eframe(move |_| EffectcraftApp::new(s));
h.state_mut().ui.tool = effectcraft_ui_egui::state::Tool::Type;
h.run_steps(3);
let comp = rect(&h, "viewer.comp");
let k = comp.width() / 640.0;
click(&mut h, comp.min + egui::vec2(330.0 * k, 180.0 * k), Modifiers::NONE);
assert_eq!(edited(&h).0, ids[0], "{switch}");
}
}
#[test]
fn type_tool_click_type_edit_and_commit() {
let mut h = Harness::builder().with_size(egui::vec2(1600.0, 1000.0)).with_step_dt(1.0 / 60.0).build_eframe(|_| app());
+154
View File
@@ -58,6 +58,82 @@ fn screen(h: &Harness<'_, EffectcraftApp>, p: [f32; 2]) -> Pos2 {
c.min + vec2(p[0] * z, p[1] * z)
}
fn selection_harness() -> Harness<'static, EffectcraftApp> {
let mut s = Session::default();
s.execute("comp.new", json!({"name": "Selection", "width": 640, "height": 360, "duration": 4})).unwrap();
for name in ["Back", "Front"] {
s.execute("layer.newSolid", json!({"name": name, "color": "#406080", "width": 80, "height": 80})).unwrap();
}
s.execute("edit.deselectAll", json!({})).unwrap();
let mut h = Harness::builder().with_size(egui::vec2(1600.0, 1000.0)).build_eframe(move |_| EffectcraftApp::new(s));
h.run_steps(3);
h
}
#[test]
fn viewer_click_skips_hidden_and_unsoloed_layers() {
for switch in ["video", "solo"] {
let mut h = selection_harness();
let comp = h.state().session.active_comp().unwrap();
let (front, back) = (comp.layers[0].id, comp.layers[1].id);
let at = screen(&h, [320.0, 180.0]);
click(&mut h, at);
assert_eq!(h.state().session.state.selected_layers, vec![front]);
let s = &mut h.state_mut().session;
let (target, value) = if switch == "video" { (front, false) } else { (back, true) };
s.execute("layer.setSwitch", json!({"layers": [target.0], "switch": switch, "value": value})).unwrap();
s.execute("edit.deselectAll", json!({})).unwrap();
h.run_steps(40); // Start a new click rather than a double-click.
click(&mut h, at);
assert_eq!(h.state().session.state.selected_layers, vec![back], "{switch}");
}
}
#[test]
fn viewer_marquee_skips_hidden_and_unsoloed_layers() {
for switch in ["video", "solo"] {
let mut h = selection_harness();
let comp = h.state().session.active_comp().unwrap();
let (front, back) = (comp.layers[0].id, comp.layers[1].id);
let (target, value) = if switch == "video" { (front, false) } else { (back, true) };
h.state_mut().session.execute("layer.setSwitch", json!({"layers": [target.0], "switch": switch, "value": value})).unwrap();
h.run_steps(3);
let (from, to) = (screen(&h, [250.0, 110.0]), screen(&h, [390.0, 250.0]));
drag(&mut h, from, to);
assert_eq!(h.state().session.state.selected_layers, vec![back], "{switch}");
}
}
#[test]
fn viewer_click_does_not_pick_through_hidden_or_locked_solo_layers() {
for switch in ["video", "lock"] {
let mut h = selection_harness();
let front = h.state().session.active_comp().unwrap().layers[0].id;
let s = &mut h.state_mut().session;
s.execute("layer.setSwitch", json!({"layers": [front.0], "switch": "solo", "value": true})).unwrap();
s.execute("layer.setSwitch", json!({"layers": [front.0], "switch": switch, "value": switch == "lock"})).unwrap();
h.run_steps(3);
let at = screen(&h, [320.0, 180.0]);
click(&mut h, at);
assert!(h.state().session.state.selected_layers.is_empty(), "{switch}");
}
}
#[test]
fn viewer_click_ignores_inactive_solo_layers() {
let mut h = selection_harness();
let comp = h.state().session.active_comp().unwrap();
let (front, back) = (comp.layers[0].id, comp.layers[1].id);
let s = &mut h.state_mut().session;
s.execute("layer.setSwitch", json!({"layers": [front.0], "switch": "solo", "value": true})).unwrap();
let cid = s.active_comp_id().unwrap();
std::sync::Arc::make_mut(&mut s.project).comp_mut(cid).unwrap().layer_mut(front).unwrap().in_point = effectcraft_engine::time::Tick::from_seconds_f64(1.0);
h.run_steps(3);
let at = screen(&h, [320.0, 180.0]);
click(&mut h, at);
assert_eq!(h.state().session.state.selected_layers, vec![back]);
}
#[test]
fn bottom_bar_in_after_effects_order() {
let h = harness();
@@ -391,6 +467,8 @@ fn reference_axes_toggle_from_the_grid_menu() {
h.state_mut().session.execute("layer.setSwitch", json!({"layers": [box_id.0], "switch": "threeD", "value": true})).unwrap();
h.run_steps(3);
assert!(h.state().auto.find("viewer.referenceAxes").is_some(), "on by default (Settings ▸ 3D)");
// Issue #64: one compass, not two.
assert_eq!(h.state().auto.query("viewer.referenceAxes").len(), 1);
let g = rect(&h, "viewer.grid").center();
click(&mut h, g);
h.run_steps(2);
@@ -743,3 +821,79 @@ fn double_press_shortcuts_reveal_their_second_set() {
h.run_steps(40);
}
}
/// Drag through `path` with `modifiers` held (press at the first point, release at the last).
fn drag_path(h: &mut Harness<'_, EffectcraftApp>, path: &[Pos2], modifiers: egui::Modifiers) {
h.input_mut().events.push(Event::ModifiersChanged(modifiers));
h.input_mut().events.push(Event::PointerMoved(path[0]));
h.input_mut().events.push(Event::PointerButton { pos: path[0], button: egui::PointerButton::Primary, pressed: true, modifiers });
h.step();
for w in path.windows(2) {
for i in 1..=6 {
h.input_mut().events.push(Event::PointerMoved(w[0] + (w[1] - w[0]) * (i as f32 / 6.0)));
h.step();
}
}
let end = *path.last().unwrap();
h.input_mut().events.push(Event::PointerButton { pos: end, button: egui::PointerButton::Primary, pressed: false, modifiers });
h.run_steps(2);
// The keys come up after the button, as a hand does.
h.input_mut().events.push(Event::ModifiersChanged(Default::default()));
h.step();
}
/// Issue #63: a bounding-box handle scales about the anchor point so the grabbed corner follows
/// the pointer, relative to the scale the drag began with: dragging through the anchor and back
/// out recovers (it used to stick at 0), edges scale one axis, Shift keeps the proportions.
#[test]
fn handle_drags_scale_about_the_anchor_and_follow_the_pointer() {
let mut h = harness();
let box_id = h.state().session.active_comp().unwrap().layers[0].id;
let set = |h: &mut Harness<'_, EffectcraftApp>, path: &str, v: serde_json::Value| {
h.state_mut().session.execute("prop.set", json!({"layer": box_id.0, "path": path, "value": v})).unwrap();
};
let scale = |h: &Harness<'_, EffectcraftApp>| {
let l = h.state().session.active_comp().unwrap().layer(box_id).unwrap().clone();
l.props.prop("transform/scale").unwrap().value.as_vec3()
};
let close = |a: [f64; 3], b: [f64; 2]| (a[0] - b[0]).abs() < 1.0 && (a[1] - b[1]).abs() < 1.0;
h.state_mut().session.execute("layer.select", json!({"layers": [box_id.0]})).unwrap();
// The 80×80 box is centred at (320, 180) with its anchor in the middle.
h.state_mut().session.execute("view.snapping", json!({"value": false})).unwrap();
h.run_steps(2);
let undo0 = h.state().session.history.undo.len();
// Bottom-right corner (360, 220) to (400, 260): twice as far from the anchor.
let corner = rect(&h, &format!("viewer.handle.{}.2", box_id.0)).center();
let path = [corner, screen(&h, [400.0, 260.0])];
drag_path(&mut h, &path, Default::default());
assert!(close(scale(&h), [200.0, 200.0]), "{:?}", scale(&h));
assert_eq!(h.state().session.history.undo.len(), undo0 + 1, "one undo step per drag");
// Through the anchor (scale ≈ 0) and back out to 1.5×: the layer follows, nothing sticks.
set(&mut h, "transform/scale", json!([100, 100, 100]));
h.run_steps(2);
let corner = rect(&h, &format!("viewer.handle.{}.2", box_id.0)).center();
let path = [corner, screen(&h, [320.0, 180.0]), screen(&h, [300.0, 170.0]), screen(&h, [380.0, 240.0])];
drag_path(&mut h, &path, Default::default());
assert!(close(scale(&h), [150.0, 150.0]), "{:?}", scale(&h));
// Past the anchor the layer flips, as in After Effects.
set(&mut h, "transform/scale", json!([100, 100, 100]));
h.run_steps(2);
let corner = rect(&h, &format!("viewer.handle.{}.2", box_id.0)).center();
let path = [corner, screen(&h, [280.0, 140.0])];
drag_path(&mut h, &path, Default::default());
assert!(close(scale(&h), [-100.0, -100.0]), "{:?}", scale(&h));
// The right edge (handle 5) scales x only.
set(&mut h, "transform/scale", json!([100, 100, 100]));
h.run_steps(2);
let edge = rect(&h, &format!("viewer.handle.{}.5", box_id.0)).center();
let path = [edge, screen(&h, [380.0, 200.0])];
drag_path(&mut h, &path, Default::default());
assert!(close(scale(&h), [150.0, 100.0]), "{:?}", scale(&h));
// Shift on a corner keeps the proportions: the pointer's place along the diagonal.
set(&mut h, "transform/scale", json!([100, 100, 100]));
h.run_steps(2);
let corner = rect(&h, &format!("viewer.handle.{}.2", box_id.0)).center();
let path = [corner, screen(&h, [400.0, 230.0])];
drag_path(&mut h, &path, egui::Modifiers::SHIFT);
assert!(close(scale(&h), [162.5, 162.5]), "{:?}", scale(&h));
}