Viewer: each composition keeps its Resolution in the project, as in After Effects (#417)

What: the Composition panel's Resolution (Auto, Full, Half, Third, Quarter, Custom) is now a
property of the composition (`Comp::resolution`, moved with its `Resolution` type from the UI
into the project crate) instead of one global viewer setting. Switching to another comp shows
that comp's resolution, switching back shows the first one's again, and saving and reopening the
project keeps them. `view.res.full|half|third|quarter|custom` and the new engine command
`view.res.auto` set it (headless too, with an optional `comp`); `ui.set {viewer: {res}}` sets
the active comp's and `ui.inspect` still reports `ui.viewer.res`; `comp.info` reports
`resolution` and `resolutionFactor`; View ▸ Resolution's check marks come from the engine.

Why: After Effects saves each composition's Resolution with the project (CompItem.resolutionFactor
is a per-comp attribute). As there, changing it marks the project modified but adds no undo step:
undo, redo and History jumps carry the current values over to the restored state. It is not part
of the comp's pixels (`Comp::same_pixels` ignores it and `Comp::pixel_form` normalises it), so
changing it keeps the comp's RAM and disk cache keys. Auto is not written (serde default and
skip_serializing_if), so projects saved before open with Auto and older versions read new files.
The magnification is not saved per comp: Adobe's documentation doesn't say it is.

Tests: project `comp_resolution_is_saved_and_old_projects_load_with_auto`,
`resolution_factors_and_scales`; engine
`each_comp_keeps_its_resolution_outside_the_undo_history_and_in_the_file` (switching comps,
no undo step, undo/redo keep it, save/open round trip, menu check marks, Custom dialog);
ui-egui `each_comp_keeps_its_viewer_resolution` (the viewer popup on comp A, comp B through
`ui.set`, back to A, unchanged frame cache identity, save/open). They don't build before the
change (no `Comp::resolution`, no `view.res.auto` engine command).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
bflatastic
2026-10-10 00:57:00 +07:00
co-authored by Claude Opus 5.5
parent 176cddcdad
commit 67305fbcd1
21 changed files with 377 additions and 118 deletions
+52 -2
View File
@@ -162,6 +162,56 @@ fn viewer_press_prefers_a_selected_layer_under_the_pointer() {
assert_eq!(h.state().session.state.selected_layers, vec![front], "nothing selected: the topmost layer");
}
/// Each composition keeps its Resolution, saved with the project as in After Effects: chosen for
/// comp A in the viewer's popup, it is still A's after showing comp B, costs no undo step, keeps
/// A's cached frames and is read back from the saved file (#417).
#[test]
fn each_comp_keeps_its_viewer_resolution() {
use effectcraft_ui_egui::state::Resolution;
let mut h = harness();
let a = h.state().session.active_comp_id().unwrap();
let content = |h: &Harness<'_, EffectcraftApp>, c| {
let s = h.state();
s.frames.content_of(&s.session.project, s.session.revision, c)
};
let (before, steps) = (content(&h, a), h.state().session.history.undo.len());
for id in ["viewer.resolution", "viewer.resolutionItem.1"] {
let at = rect(&h, id).center();
click(&mut h, at);
}
assert_eq!(h.state().viewer_res(), Resolution::Half);
assert_eq!(h.state().session.project.comp(a).unwrap().resolution, Resolution::Half);
assert_eq!(h.state().session.history.undo.len(), steps, "no undo step");
assert_eq!(content(&h, a), before, "the comp's cached frames stay valid");
// Comp B starts at Auto and gets its own (here through the control channel's `ui.set`).
h.state_mut().session.execute("comp.new", json!({"name": "Other", "width": 320, "height": 180, "duration": 2})).unwrap();
h.run_steps(3);
let b = h.state().session.active_comp_id().unwrap();
assert_ne!(a, b);
assert_eq!(h.state().viewer_res(), Resolution::Auto);
let (req, _reply) = effectcraft_ui_egui::control::ControlRequest::new("ui.set", json!({"viewer": {"res": "quarter"}}));
let ctx = h.ctx.clone();
let _ = effectcraft_ui_egui::control::handle(h.state_mut(), &ctx, &req);
assert_eq!(h.state().viewer_res(), Resolution::Quarter);
let ctx = h.ctx.clone();
assert_eq!(effectcraft_ui_egui::control::inspect(h.state(), &ctx)["ui"]["viewer"]["res"], json!("Quarter"));
// Back to comp A: its resolution again.
h.state_mut().session.open_comp(a);
h.run_steps(3);
assert_eq!(h.state().viewer_res(), Resolution::Half);
assert!(h.state().viewer_scale(1.0, 1.0) == 0.5);
// Saved and opened again.
let path = std::env::temp_dir().join(format!("ec-viewer-res-{}.ecproj", std::process::id()));
h.state_mut().session.execute("file.saveAs", json!({"path": path.to_string_lossy()})).unwrap();
let mut s = Session::default();
s.execute("file.open", json!({"path": path.to_string_lossy()})).unwrap();
let _ = std::fs::remove_file(&path);
s.open_comp(b);
let app = EffectcraftApp::new(s);
assert_eq!(app.viewer_res(), Resolution::Quarter);
assert_eq!(app.session.project.comp(a).unwrap().resolution, Resolution::Half);
}
#[test]
fn bottom_bar_in_after_effects_order() {
let h = harness();
@@ -1610,7 +1660,7 @@ fn full_resolution_frames_wider_than_the_texture_limit_fit() {
let mut h = Harness::builder().with_size(egui::vec2(1600.0, 1000.0)).build_eframe(|_| EffectcraftApp::new(s));
// (egui's font atlas needs 1024.)
h.input_mut().max_texture_side = Some(1024);
h.state_mut().ui.viewer.res = effectcraft_ui_egui::state::Resolution::Full;
h.state_mut().session.execute("view.res.full", json!({})).unwrap();
let full = |h: &mut Harness<'_, EffectcraftApp>| h.state_mut().viewer_pixels().is_some_and(|px| px.size == [2400, 400]);
for _ in 0..400 {
h.step();
@@ -1619,6 +1669,6 @@ fn full_resolution_frames_wider_than_the_texture_limit_fit() {
}
std::thread::sleep(std::time::Duration::from_millis(5));
}
assert!(full(&mut h), "the full-size frame is shown (and stays readable): {:?}", h.state().ui.viewer.res);
assert!(full(&mut h), "the full-size frame is shown (and stays readable): {:?}", h.state().viewer_res());
assert_eq!(h.state().viewer_texture_size(), Some([800, 134]), "2400×400 averaged by 3");
}
@@ -177,7 +177,6 @@ fn effect_scrubbing_uses_adaptive_resolution_and_settles_on_release() {
h.state_mut().session.execute("layer.select", json!({"layers":[id.0]})).unwrap();
h.state_mut().session.execute("effect.apply", json!({"effect":"Gaussian Blur"})).unwrap();
h.state_mut().session.execute("view.fastPreviewMode", json!({"mode":"adaptive"})).unwrap();
h.state_mut().ui.viewer.res = effectcraft_ui_egui::state::Resolution::Auto;
let ctx = h.ctx.clone();
effectcraft_ui_egui::menus::invoke(h.state_mut(), &ctx, "window.panel", json!({"panel":"effectControls"})).unwrap();
h.run_steps(3);
@@ -188,12 +187,12 @@ fn effect_scrubbing_uses_adaptive_resolution_and_settles_on_release() {
h.run_steps(2);
assert!(h.state().ui.viewer.property_interacting);
assert!(h.state().viewer_scale(1.0, 1.0) < 1.0);
h.state_mut().ui.viewer.res = effectcraft_ui_egui::state::Resolution::Full;
h.state_mut().session.execute("view.res.full", json!({})).unwrap();
assert_eq!(h.state().viewer_scale(1.0, 1.0), 1.0);
pointer(&mut h, a + vec2(30.0, 0.0), false, Modifiers::NONE);
h.run_steps(2);
assert!(!h.state().ui.viewer.property_interacting);
h.state_mut().ui.viewer.res = effectcraft_ui_egui::state::Resolution::Auto;
h.state_mut().session.execute("view.res.auto", json!({})).unwrap();
assert_eq!(h.state().viewer_scale(1.0, 1.0), 1.0);
}