diff --git a/Cargo.lock b/Cargo.lock index b5bf6e5..3aece86 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -602,7 +602,7 @@ dependencies = [ [[package]] name = "canvas-pilot" -version = "0.10.1" +version = "0.10.2" dependencies = [ "base64 0.22.1", "craft-dwg", diff --git a/Cargo.toml b/Cargo.toml index 0c4abdc..b049c8e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ default-members = ["crates/canvas-pilot"] resolver = "3" [workspace.package] -version = "0.10.1" +version = "0.10.2" edition = "2024" license = "MIT" repository = "https://proxy.dandaedre.com/gitea/idle-org/canvas-pilot" diff --git a/crates/canvas-pilot/src/format_ui.rs b/crates/canvas-pilot/src/format_ui.rs index 5686108..e0d2f9f 100644 --- a/crates/canvas-pilot/src/format_ui.rs +++ b/crates/canvas-pilot/src/format_ui.rs @@ -357,6 +357,7 @@ impl Editor { } if self.property_tab == PropertyTab::Layer { let before_size = d.size; + self.keep_aspect_ratio = self.layout.layer_info(i).keep_aspect_ratio; ui.heading(tr(ui.ctx(), "ui.layer-resolution-final-visible-box")); ui.label(tr(ui.ctx(), "ui.resizing-automatically-adjusts-the-layer-crop-to-fit-the-new-dimensions")); ui.horizontal(|ui| { @@ -373,7 +374,11 @@ impl Editor { match d.commit_ratio(self.keep_aspect_ratio) {Ok(())=>d.error.clear(),Err(error)=>d.error=error} } if !self.keep_aspect_ratio && d.ratio_edit.target.is_some() {ui.small(tr(ui.ctx(), "ui.ratio-ready-enable-the-lock-to-resize"));} - if lock_changed {self.settings.save(&self.application_settings(ui.ctx()));} + if lock_changed + && let Err(error) = self.layout.set_keep_aspect_ratio(i, self.keep_aspect_ratio) + { + d.error = error; + } let old=d.size; dimensions(ui,&mut d.size,"Visible pixels"); if self.keep_aspect_ratio { diff --git a/crates/canvas-pilot/src/gui.rs b/crates/canvas-pilot/src/gui.rs index 5619379..1c6b742 100644 --- a/crates/canvas-pilot/src/gui.rs +++ b/crates/canvas-pilot/src/gui.rs @@ -910,6 +910,7 @@ impl Editor { } self.fields_edited = false; if let Some(i) = self.layout.selected() { + self.keep_aspect_ratio = self.layout.layer_info(i).keep_aspect_ratio; let g = self.layout.layers()[i]; let [x, y] = self .position_reference() @@ -2277,6 +2278,10 @@ impl Editor { Ok(()) } fn resize_ratio_option(&mut self, ui: &mut egui::Ui) { + let Some(i) = self.layout.selected() else { + return; + }; + self.keep_aspect_ratio = self.layout.layer_info(i).keep_aspect_ratio; let changed = ui .checkbox( &mut self.keep_aspect_ratio, @@ -2302,9 +2307,9 @@ impl Editor { { self.ratio_edit.error = error; } - if changed { - let options = self.application_settings(ui.ctx()); - self.settings.save(&options); + if changed && let Err(error) = self.layout.set_keep_aspect_ratio(i, self.keep_aspect_ratio) + { + self.error = error; } } fn measurement_points_menu(&mut self, ui: &mut egui::Ui) { @@ -3500,7 +3505,7 @@ impl Editor { i, corner, point, - self.keep_aspect_ratio, + self.layout.layer_info(i).keep_aspect_ratio, self.active_resize_mode(), ) { self.layout.gesture_error = Some(e); @@ -7178,6 +7183,8 @@ mod tests { frame(&mut app, &ctx, vec![mouse(pos, false)]); } assert!(!app.keep_aspect_ratio); + assert!(!app.layout.layer_info(1).keep_aspect_ratio); + assert!(app.layout.layer_info(0).keep_aspect_ratio); assert!(app.show_pattern); assert!(app.show_toolbar_icon_names); assert_eq!(*app.layout.layers(), before); @@ -8068,6 +8075,7 @@ mod tests { keep_aspect_ratio: false, ..Default::default() }; + app.layout.set_keep_aspect_ratio(1, false).unwrap(); let ctx = egui::Context::default(); let output = frame(&mut app, &ctx, vec![]); let rect = layer_rects(&output)[1]; @@ -8117,6 +8125,9 @@ mod tests { keep_aspect_ratio, ..Default::default() }; + app.layout + .set_keep_aspect_ratio(1, keep_aspect_ratio) + .unwrap(); let ctx = egui::Context::default(); let output = frame(&mut app, &ctx, vec![]); let before = app.layout.layers().clone(); diff --git a/crates/canvas-pilot/src/lib.rs b/crates/canvas-pilot/src/lib.rs index 41f5823..8b98305 100644 --- a/crates/canvas-pilot/src/lib.rs +++ b/crates/canvas-pilot/src/lib.rs @@ -477,6 +477,7 @@ impl DeviceLink { #[serde(deny_unknown_fields)] pub struct LayerInfo { pub pivot: [f64; 2], + pub keep_aspect_ratio: bool, pub load_mapping: Option, pub send_mapping: SendMapping, pub id: usize, @@ -574,6 +575,7 @@ impl Default for Layout { info: vec![ LayerInfo { pivot: [0.5; 2], + keep_aspect_ratio: true, load_mapping: None, send_mapping: Default::default(), id: 2, @@ -582,6 +584,7 @@ impl Default for Layout { }, LayerInfo { pivot: [0.5; 2], + keep_aspect_ratio: true, load_mapping: None, send_mapping: Default::default(), id: 1, @@ -761,6 +764,7 @@ impl Layout { self.layers.push(g); self.info.push(LayerInfo { pivot: [0.5; 2], + keep_aspect_ratio: true, load_mapping: None, send_mapping: Default::default(), id: self.next_id, @@ -1292,6 +1296,22 @@ impl Layout { } self.remember(before); } + /// Change the resize lock for one layer as an undoable layer property. + pub fn set_keep_aspect_ratio(&mut self, index: usize, keep: bool) -> Result<(), String> { + let current = self + .info + .get(index) + .ok_or("Layer no longer exists.")? + .keep_aspect_ratio; + if current == keep { + return Ok(()); + } + self.finish_drag(); + let before = self.snapshot(); + self.info[index].keep_aspect_ratio = keep; + self.remember(before); + Ok(()) + } /// A single selected layer, or None for zero/multiple selections. pub fn selected(&self) -> Option { let indices = self.selected_indices(); diff --git a/crates/canvas-pilot/src/project.rs b/crates/canvas-pilot/src/project.rs index ede5db7..d15859d 100644 --- a/crates/canvas-pilot/src/project.rs +++ b/crates/canvas-pilot/src/project.rs @@ -35,6 +35,7 @@ pub struct Input { #[serde(deny_unknown_fields)] pub struct Layer { pub pivot: [f64; 2], + pub keep_aspect_ratio: bool, #[serde(deserialize_with = "deserialize_link")] pub load_mapping: Option, pub send_mapping: crate::SendMapping, @@ -103,7 +104,6 @@ pub struct EditorSettings { pub position_point: PositionPoint, #[serde(deserialize_with = "deserialize_layer_point")] pub position_layer_point: Option, - pub keep_aspect_ratio: bool, pub viewport_zoom: f32, pub viewport_pan: [f32; 2], pub show_source_pattern: bool, @@ -180,7 +180,7 @@ impl Project { folders: layout.folders.clone(), workspace: Workspace::default(), format: FORMAT.into(), - version: 20, + version: 21, next_layer_id: layout.next_id, output_resolution: layout.formats.output.into(), inputs: (0..layout.formats.sources.len()) @@ -196,6 +196,7 @@ impl Project { layers: (0..layout.layers.len()) .map(|i| Layer { pivot: layout.info[i].pivot, + keep_aspect_ratio: layout.info[i].keep_aspect_ratio, load_mapping: layout.info[i].load_mapping.clone(), send_mapping: layout.info[i].send_mapping.clone(), name: layout.info[i].name.clone(), @@ -220,7 +221,6 @@ impl Project { .collect(), position_point: PositionPoint::TopLeft, position_layer_point: None, - keep_aspect_ratio: true, viewport_zoom: 1.0, viewport_pan: [0.0; 2], show_source_pattern: false, @@ -231,9 +231,9 @@ impl Project { } /// Build a fresh document only after validating the entire file. No history is restored. pub fn layout(&self) -> Result { - if self.format != FORMAT || self.version != 20 { + if self.format != FORMAT || self.version != 21 { return Err( - "Unsupported project format/version; expected beffroi.midra-layout version 20." + "Unsupported project format/version; expected beffroi.midra-layout version 21." .into(), ); } @@ -323,6 +323,7 @@ impl Project { crate::validate_pivot(layer.pivot)?; layout.info.push(crate::LayerInfo { pivot: layer.pivot, + keep_aspect_ratio: layer.keep_aspect_ratio, load_mapping: layer.load_mapping.clone(), send_mapping: layer.send_mapping.clone(), id: layer.id, @@ -428,8 +429,8 @@ impl Project { } let header: Header = serde_json::from_str(text).map_err(|e| format!("Invalid project JSON: {e}"))?; - if !(1..=20).contains(&header.version) { - return Err("Unsupported project version; expected versions 1–20.".into()); + if !(1..=21).contains(&header.version) { + return Err("Unsupported project version; expected versions 1–21.".into()); } let mut migrated: serde_json::Value = if header.version == 1 || header.version == 2 { let mut value: serde_json::Value = @@ -728,6 +729,23 @@ impl Project { } migrated["version"] = 20.into(); } + if header.version <= 20 { + let keep = migrated["editor"] + .as_object_mut() + .ok_or("Missing editor settings")? + .remove("keep_aspect_ratio") + .ok_or("Missing aspect-ratio setting")?; + let keep: bool = serde_json::from_value(keep) + .map_err(|_| "Invalid aspect-ratio setting".to_string())?; + for layer in migrated["layers"].as_array_mut().ok_or("Missing layers")? { + let layer = layer.as_object_mut().ok_or("Invalid project layer")?; + if layer.contains_key("keep_aspect_ratio") { + return Err("Unexpected per-layer aspect-ratio setting in old project.".into()); + } + layer.insert("keep_aspect_ratio".into(), keep.into()); + } + migrated["version"] = 21.into(); + } let p: Self = serde_json::from_value(migrated).map_err(|e| format!("Invalid project JSON: {e}"))?; p.layout()?; diff --git a/crates/canvas-pilot/src/project_recovery.rs b/crates/canvas-pilot/src/project_recovery.rs index 5c61c4e..5b1d9c5 100644 --- a/crates/canvas-pilot/src/project_recovery.rs +++ b/crates/canvas-pilot/src/project_recovery.rs @@ -23,8 +23,8 @@ pub fn from_json(text: &str) -> Result { } let version = raw["version"] .as_u64() - .filter(|v| (1..=20).contains(v)) - .ok_or("Unsupported project version; expected versions 1–20.")?; + .filter(|v| (1..=21).contains(v)) + .ok_or("Unsupported project version; expected versions 1–21.")?; let mut warnings = Vec::new(); if let Some(proposals) = raw.as_object_mut().unwrap().remove("input_proposals") { if proposals != serde_json::json!([]) { @@ -183,6 +183,7 @@ pub fn from_json(text: &str) -> Result { "name", "folder", "pivot", + "keep_aspect_ratio", "visible", "locked", "load_mapping", diff --git a/crates/canvas-pilot/src/project_ui.rs b/crates/canvas-pilot/src/project_ui.rs index a87bca0..8f3ef5b 100644 --- a/crates/canvas-pilot/src/project_ui.rs +++ b/crates/canvas-pilot/src/project_ui.rs @@ -131,7 +131,6 @@ impl Editor { p.editor.position_point = self.corner; p.editor.position_layer_point = self.position_layer_point; p.editor.backdrop_title = self.backdrop_title.clone(); - p.editor.keep_aspect_ratio = self.keep_aspect_ratio; p.editor.viewport_zoom = self.zoom; p.editor.viewport_pan = [self.pan.x, self.pan.y]; p.editor.show_source_pattern = self.show_pattern; @@ -218,7 +217,7 @@ impl Editor { corner: e.position_point, position_layer_point: e.position_layer_point, backdrop_title: e.backdrop_title, - keep_aspect_ratio: e.keep_aspect_ratio, + keep_aspect_ratio: true, zoom: e.viewport_zoom, pan: Vec2::from(e.viewport_pan), show_pattern: e.show_source_pattern, @@ -1029,7 +1028,8 @@ mod tests { app.corner = PositionPoint::TopLeft; app.position_layer_point = Some(PositionPoint::Center); app.backdrop_title = "Conference 2027 · Main stage".into(); - app.keep_aspect_ratio = false; + app.layout.set_keep_aspect_ratio(1, false).unwrap(); + app.sync(); app.show_pattern = true; app.show_toolbar_icon_names = true; app.layout diff --git a/crates/canvas-pilot/tests/aquilon.rs b/crates/canvas-pilot/tests/aquilon.rs index 8d92d6d..f5efd7e 100644 --- a/crates/canvas-pilot/tests/aquilon.rs +++ b/crates/canvas-pilot/tests/aquilon.rs @@ -240,7 +240,7 @@ fn family_links_save_migrate_recover_and_validate() { let mut old: Value = serde_json::from_str(old).unwrap(); old["layers"][0]["midra_link"] = json!({"screen":"001","layer":"02"}); let p = Project::from_json(&old.to_string()).unwrap(); - assert_eq!(p.version, 20); + assert_eq!(p.version, 21); assert_eq!( p.layers[0].load_mapping.as_ref().unwrap().family, Family::Midra4k @@ -300,7 +300,7 @@ fn documented_v13_example_contains_native_aquilon_link() { "../../../docs/interfaces/canvas-pilot-v13.example.json" )) .unwrap(); - assert_eq!(p.version, 20); + assert_eq!(p.version, 21); let link = p.layers[0].load_mapping.as_ref().unwrap(); assert_eq!(link.family, Family::Aquilon); assert_eq!(link.screen, "S1"); diff --git a/crates/canvas-pilot/tests/device_mapping.rs b/crates/canvas-pilot/tests/device_mapping.rs index 6d1dc0a..3c08f1f 100644 --- a/crates/canvas-pilot/tests/device_mapping.rs +++ b/crates/canvas-pilot/tests/device_mapping.rs @@ -54,7 +54,7 @@ fn v18_migration_synchronizes_links_and_v19_requires_both_directions() { let project = canvas_pilot::project_recovery::from_json(old) .unwrap() .project; - assert_eq!(project.version, 20); + assert_eq!(project.version, 21); for layer in &project.layers { assert_eq!( layer.send_mapping, @@ -64,7 +64,7 @@ fn v18_migration_synchronizes_links_and_v19_requires_both_directions() { assert_eq!( project, Project::from_json(include_str!( - "../../../docs/interfaces/canvas-pilot-v20.example.json" + "../../../docs/interfaces/canvas-pilot-v21.example.json" )) .unwrap() ); diff --git a/crates/canvas-pilot/tests/exchange_metadata.rs b/crates/canvas-pilot/tests/exchange_metadata.rs index 559810b..967b673 100644 --- a/crates/canvas-pilot/tests/exchange_metadata.rs +++ b/crates/canvas-pilot/tests/exchange_metadata.rs @@ -418,7 +418,7 @@ fn every_snapshot_codec_roundtrips_all_fit_modes_masks_sources_links_and_workspa p.editor.show_source_pattern = true; p.editor.viewport_zoom = 1.75; p.editor.backdrop_title = "Round trip".into(); - p.editor.keep_aspect_ratio = false; + p.layers[0].keep_aspect_ratio = false; p.editor.outline_layers = true; p.editor.show_toolbar_icon_names = true; p.workspace.resize_mode = canvas_pilot::ResizeMode::Mirror; diff --git a/crates/canvas-pilot/tests/folders.rs b/crates/canvas-pilot/tests/folders.rs index 81893a0..13d3781 100644 --- a/crates/canvas-pilot/tests/folders.rs +++ b/crates/canvas-pilot/tests/folders.rs @@ -134,7 +134,7 @@ fn explicit_empty_folders_survive_history_save_rename_and_membership_changes() { fn version_12_explicit_folder_validation_and_v11_migration() { let old = include_str!("../../../docs/interfaces/canvas-pilot-v11.example.json"); let p = Project::from_json(old).unwrap(); - assert_eq!(p.version, 20); + assert_eq!(p.version, 21); assert!(p.folders.is_empty()); let example = include_str!("../../../docs/interfaces/canvas-pilot-v12.example.json"); assert_eq!( diff --git a/crates/canvas-pilot/tests/layer_fit.rs b/crates/canvas-pilot/tests/layer_fit.rs index d5e3ff2..17503b1 100644 --- a/crates/canvas-pilot/tests/layer_fit.rs +++ b/crates/canvas-pilot/tests/layer_fit.rs @@ -84,7 +84,7 @@ fn explicit_fit_survives_resize_undo_reordering_and_project_roundtrip() { layout.apply(0, box_geometry()).unwrap(); assert_eq!(layout.formats().advanced[0], crop); let before = Project::from_layout(&layout); - assert_eq!(before.version, 20); + assert_eq!(before.version, 21); let loaded = Project::from_json(&before.to_json().unwrap()).unwrap(); assert_eq!(loaded, before); assert_eq!( @@ -107,7 +107,7 @@ fn explicit_fit_survives_resize_undo_reordering_and_project_roundtrip() { fn v13_migration_defaults_to_normal_crop_and_v14_requires_valid_fit() { let text = include_str!("../../../docs/interfaces/canvas-pilot-v13.example.json"); let migrated = Project::from_json(text).unwrap(); - assert_eq!(migrated.version, 20); + assert_eq!(migrated.version, 21); assert!(migrated.layers.iter().all(|l| l.layer_fit.is_none())); let mut json = serde_json::to_value(&migrated).unwrap(); json["layers"][0] @@ -125,7 +125,7 @@ fn current_documented_example_is_valid() { "../../../docs/interfaces/canvas-pilot-v14.example.json" )) .unwrap(); - assert_eq!(p.version, 20); + assert_eq!(p.version, 21); p.layout().unwrap(); } diff --git a/crates/canvas-pilot/tests/masking.rs b/crates/canvas-pilot/tests/masking.rs index a3b0e83..72ba8fc 100644 --- a/crates/canvas-pilot/tests/masking.rs +++ b/crates/canvas-pilot/tests/masking.rs @@ -105,7 +105,7 @@ fn mask_schema_migration_validation_reorder_resize_and_atomic_import() { let migrated = canvas_pilot::project_recovery::from_json(old) .unwrap() .project; - assert_eq!(migrated.version, 20); + assert_eq!(migrated.version, 21); assert!(migrated.layers.iter().all(|l| l.mask == Mask::default())); let mut json = serde_json::to_value(&p).unwrap(); json["layers"][0].as_object_mut().unwrap().remove("mask"); diff --git a/crates/canvas-pilot/tests/project.rs b/crates/canvas-pilot/tests/project.rs index 8cb011e..dedfe72 100644 --- a/crates/canvas-pilot/tests/project.rs +++ b/crates/canvas-pilot/tests/project.rs @@ -227,7 +227,7 @@ fn persistent_device_links_roundtrip_migrate_and_undo() { include_str!("../../../docs/interfaces/canvas-pilot-v5.example.json"), ] { let p = Project::from_json(text).unwrap(); - assert_eq!(p.version, 20); + assert_eq!(p.version, 21); assert!(p.layers.iter().all(|l| l.load_mapping.is_none())); } let mut value = serde_json::to_value(&project).unwrap(); @@ -304,7 +304,7 @@ fn position_point_schema_migrates_corners_and_rejects_mislabeled_files() { .unwrap(); old["editor"]["position_corner"] = name.into(); let loaded = Project::from_json(&old.to_string()).unwrap(); - assert_eq!(loaded.version, 20); + assert_eq!(loaded.version, 21); assert_eq!(loaded.editor.position_point, expected); old["editor"]["position_corner"] = "center".into(); assert!(Project::from_json(&old.to_string()).is_err()); @@ -313,7 +313,7 @@ fn position_point_schema_migrates_corners_and_rejects_mislabeled_files() { assert!(Project::from_json(&old.to_string()).is_err()); } let value: serde_json::Value = serde_json::from_str(¤t.to_json().unwrap()).unwrap(); - for version in [0, 21] { + for version in [0, 22] { let mut invalid = value.clone(); invalid["version"] = version.into(); assert!( @@ -354,7 +354,7 @@ fn backdrop_title_roundtrips_and_older_projects_gain_the_default() { } let old = include_str!("../../../docs/interfaces/canvas-pilot-v6.example.json"); let migrated = Project::from_json(old).unwrap(); - assert_eq!(migrated.version, 20); + assert_eq!(migrated.version, 21); assert_eq!(migrated.editor.backdrop_title, DEFAULT_BACKDROP_TITLE); let mut invalid: serde_json::Value = serde_json::from_str(old).unwrap(); invalid["editor"]["backdrop_title"] = "Unexpected".into(); @@ -425,7 +425,7 @@ fn saved_pivots_roundtrip_and_old_projects_default_to_center() { assert_eq!(loaded.layer_info(0).pivot, custom); assert_eq!(loaded.layer_info(1).pivot, [0.5; 2]); let example = include_str!("../../../docs/interfaces/canvas-pilot-v9.example.json"); - assert_eq!(Project::from_json(example).unwrap().version, 20); + assert_eq!(Project::from_json(example).unwrap().version, 21); let old = include_str!("../../../docs/interfaces/canvas-pilot-v8.example.json"); let migrated = Project::from_json(old).unwrap(); assert!(migrated.layers.iter().all(|l| l.pivot == [0.5; 2])); @@ -447,6 +447,45 @@ fn saved_pivots_roundtrip_and_old_projects_default_to_center() { assert!(Project::from_json(&value.to_string()).is_err()); } +#[test] +fn aspect_ratio_lock_is_per_layer_undoable_and_migrates_from_v20() { + let mut layout = Layout::default(); + layout.set_keep_aspect_ratio(0, false).unwrap(); + assert!(!layout.layer_info(0).keep_aspect_ratio); + assert!(layout.layer_info(1).keep_aspect_ratio); + layout.undo(); + assert!(layout.layer_info(0).keep_aspect_ratio); + layout.redo(); + assert!(!layout.layer_info(0).keep_aspect_ratio); + + let project = Project::from_json(&Project::from_layout(&layout).to_json().unwrap()).unwrap(); + assert!(!project.layers[0].keep_aspect_ratio); + assert!(project.layers[1].keep_aspect_ratio); + assert_eq!( + Project::from_json(include_str!( + "../../../docs/interfaces/canvas-pilot-v21.example.json" + )) + .unwrap() + .version, + 21 + ); + + let mut old: serde_json::Value = serde_json::from_str(include_str!( + "../../../docs/interfaces/canvas-pilot-v20.example.json" + )) + .unwrap(); + old["editor"]["keep_aspect_ratio"] = false.into(); + let migrated = Project::from_json(&old.to_string()).unwrap(); + assert!(migrated.layers.iter().all(|layer| !layer.keep_aspect_ratio)); + + let mut missing = serde_json::to_value(project).unwrap(); + missing["layers"][0] + .as_object_mut() + .unwrap() + .remove("keep_aspect_ratio"); + assert!(Project::from_json(&missing.to_string()).is_err()); +} + #[test] fn reference_collection_migrates_single_images_and_rejects_mislabeled_or_oversized_collections() { use base64::{Engine, engine::general_purpose::STANDARD}; @@ -457,7 +496,7 @@ fn reference_collection_migrates_single_images_and_rejects_mislabeled_or_oversiz let reference = serde_json::json!({"name":"guide.png","image_base64":STANDARD.encode(b"image bytes"),"visible":false,"opacity":0.4,"preserve_ratio":true,"native_size":false,"offset":[0.0,0.0]}); old["reference"] = reference.clone(); let migrated = Project::from_json(&old.to_string()).unwrap(); - assert_eq!(migrated.version, 20); + assert_eq!(migrated.version, 21); assert_eq!(migrated.references.len(), 1); assert!(!migrated.references[0].visible); assert_eq!(migrated.references[0].opacity, 0.4); @@ -477,7 +516,7 @@ fn reference_collection_migrates_single_images_and_rejects_mislabeled_or_oversiz gallery.references = vec![migrated.references[0].clone(); 33]; assert!(gallery.to_json().unwrap_err().contains("32 reference")); let example = include_str!("../../../docs/interfaces/canvas-pilot-v10.example.json"); - assert_eq!(Project::from_json(example).unwrap().version, 20); + assert_eq!(Project::from_json(example).unwrap().version, 21); } #[test] diff --git a/crates/canvas-pilot/tests/project_recovery.rs b/crates/canvas-pilot/tests/project_recovery.rs index a28ab1d..7f55cb6 100644 --- a/crates/canvas-pilot/tests/project_recovery.rs +++ b/crates/canvas-pilot/tests/project_recovery.rs @@ -13,7 +13,7 @@ fn valid_project_round_trip_is_exact_without_warnings_or_retired_fields() { let loaded = from_json(&text).unwrap(); assert!(loaded.warnings.is_empty()); assert_eq!(loaded.project, project); - assert_eq!(loaded.project.version, 20); + assert_eq!(loaded.project.version, 21); } #[test] diff --git a/docs/canvas-pilot/changelog.md b/docs/canvas-pilot/changelog.md index 2df4700..6e0eefe 100644 --- a/docs/canvas-pilot/changelog.md +++ b/docs/canvas-pilot/changelog.md @@ -4,6 +4,12 @@ ## Unreleased +### v0.10.2 + +- Store **Keep aspect ratio when resizing** on each layer, so layers can use + different resize behavior. The choice is undoable, survives reordering and + project round trips, and old project-wide choices migrate to every layer. + ### v0.10.1 - Size the right inspector to its visible empty/reference message when no layer is diff --git a/docs/interfaces/canvas-pilot-recovery.md b/docs/interfaces/canvas-pilot-recovery.md index bf91f21..227b4a5 100644 --- a/docs/interfaces/canvas-pilot-recovery.md +++ b/docs/interfaces/canvas-pilot-recovery.md @@ -7,7 +7,7 @@ not a named project export. Headless/default editors never access this path. | Field | Meaning | | --- | --- | | `version` | Integer `1`; other versions rejected | -| `project` | Complete [project v20](canvas-pilot.md), including embedded reference bytes; its units, precision and validation apply without display rounding | +| `project` | Complete [project v21](canvas-pilot.md), including embedded reference bytes; its units, precision and validation apply without display rounding | | `project_path` | Last opened/successfully saved named JSON path, or null; geometry exports do not change it | | `manual_saved_at` | Unix UTC seconds of the last successful explicit project save, or null when unknown; recovery and measurement-point autosaves do not update it | @@ -34,7 +34,7 @@ last successful writer wins. Recovery retains applied values only: no undo history, pending text/format/import drafts, transient tools, or credentials. A normal exit cancels unfinished canvas gestures before the final checkpoint. The schema does not replace named project -JSON: Save continues to emit a bare project v20 document. Opening/New replaces the +JSON: Save continues to emit a bare project v21 document. Opening/New replaces the single recovery slot; New warns with the manual-save age and Save/Discard/Cancel. A failed or cancelled manual save never completes Save-and-create-new. diff --git a/docs/interfaces/canvas-pilot-settings.md b/docs/interfaces/canvas-pilot-settings.md index d56faa1..54daadb 100644 --- a/docs/interfaces/canvas-pilot-settings.md +++ b/docs/interfaces/canvas-pilot-settings.md @@ -36,7 +36,7 @@ unknown theme names are rejected. There are no numeric coordinates or units. | `theme` | Built-in theme ID below or `{"pack":"pack-id/theme-id"}`; default `"midra"` | | `recent_themes` | 1–3 unique built-in IDs or pack references, newest first; first must equal `theme`; default `["midra"]` | | `show_toolbar_icon_names` | Boolean; default false | -| `keep_aspect_ratio` | Boolean; default true | +| `keep_aspect_ratio` | Legacy compatibility value; current projects store the required resize lock on each layer and new layers default to true | | `show_source_pattern` | Boolean; default false. Shows source patterns on other layers only during crop editing; normal editing always hides patterns. | | `snapping` | Object with required boolean fields `enabled` (false), `pixels` (true), `screen_edges` (true; screen edges plus 25%, 50% and 75% guides on both axes), `layer_edges` (true), `mask_edges` (false), `grid` (false), `show_grid` (true), and `grid_divisions` ([8, 6]); unknown fields rejected | diff --git a/docs/interfaces/canvas-pilot-v21.example.json b/docs/interfaces/canvas-pilot-v21.example.json new file mode 100644 index 0000000..53a4723 --- /dev/null +++ b/docs/interfaces/canvas-pilot-v21.example.json @@ -0,0 +1,157 @@ +{ + "format": "beffroi.midra-layout", + "version": 21, + "output_resolution": { + "width": 1920, + "height": 1080 + }, + "inputs": [ + { + "id": 1, + "source_format": "sixteen_nine", + "native_resolution": { + "width": 1920, + "height": 1080 + } + }, + { + "id": 2, + "source_format": "sixteen_nine", + "native_resolution": { + "width": 1920, + "height": 1080 + } + } + ], + "layers": [ + { + "id": 2, + "source_id": 1, + "bounds": { + "x": 120.0, + "y": 180.0, + "width": 640.0, + "height": 360.0 + }, + "advanced_crop": { + "left": 0.0, + "right": 0.0, + "top": 0.0, + "bottom": 0.0 + }, + "visible": true, + "locked": false, + "name": "Slides", + "folder": "", + "pivot": [ + 0.5, + 0.5 + ], + "layer_fit": null, + "mask": { + "left": 0.0, + "right": 0.0, + "top": 0.0, + "bottom": 0.0, + "origin": "source" + }, + "load_mapping": { + "family": "midra4k", + "screen": "1", + "layer": "1" + }, + "send_mapping": { + "destinations": [ + { + "connection": "current", + "layer": { + "family": "midra4k", + "screen": "1", + "layer": "1" + } + } + ] + }, + "keep_aspect_ratio": true + }, + { + "id": 1, + "source_id": 2, + "bounds": { + "x": 1160.0, + "y": 180.0, + "width": 640.0, + "height": 360.0 + }, + "advanced_crop": { + "left": 0.0, + "right": 0.0, + "top": 0.0, + "bottom": 0.0 + }, + "visible": true, + "locked": false, + "name": "Presenter", + "folder": "", + "pivot": [ + 0.5, + 0.5 + ], + "layer_fit": "fullscreen", + "mask": { + "left": 0.1, + "right": 0.0, + "top": 0.0, + "bottom": 0.0, + "origin": "layer" + }, + "load_mapping": null, + "send_mapping": { + "destinations": [] + }, + "keep_aspect_ratio": true + } + ], + "editor": { + "backdrop_title": "Example Conference Name", + "selected_layer_ids": [ + 1 + ], + "position_point": "top_left", + "viewport_zoom": 1.0, + "viewport_pan": [ + 0.0, + 0.0 + ], + "show_source_pattern": false, + "show_toolbar_icon_names": false, + "outline_layers": false, + "position_layer_point": null + }, + "next_layer_id": 3, + "references": [], + "workspace": { + "snapping": { + "enabled": false, + "pixels": true, + "screen_edges": true, + "layer_edges": true, + "grid": false, + "show_grid": true, + "grid_divisions": [ + 8, + 6 + ], + "mask_edges": false + }, + "resize_mode": "individual", + "grid_spacing": null, + "collapsed_folders": [], + "capture_interval_seconds": 10, + "show_empty_inputs": false, + "previews": [] + }, + "folders": [ + "Memory A" + ] +} diff --git a/docs/interfaces/canvas-pilot.md b/docs/interfaces/canvas-pilot.md index a5a8bf0..0b2fc95 100644 --- a/docs/interfaces/canvas-pilot.md +++ b/docs/interfaces/canvas-pilot.md @@ -7,7 +7,7 @@ These are offline editor formats, not Analog Way REST payloads. Implementation: [`project.rs`](../../crates/canvas-pilot/tests/project.rs). Update this contract, examples and tests in the same change as any save/export schema change. -## Project JSON, version 20 +## Project JSON, version 21 Suggested filename: `layout.pilot.json`. **Open project** accepts any `.json` filename, including legacy `.midra.json` projects, and validates the project @@ -27,7 +27,7 @@ and `next_layer_id: 3`; other values are preserved. The [version 1 example](canvas-pilot-v1.example.json) remains a migration fixture. Version 4 adds `editor.outline_layers: false`, and reference `native_size: false` and `offset: [0, 0]` when migrating versions 1–3. Old fitting behavior is preserved. -Version 5 adds required `midra_link` to every layer. Versions 1–4 migrate with null links; links cannot be supplied under an older version. Version 6 renames `editor.position_corner` to `editor.position_point` and adds `center`. Versions 1–5 retain their original corner; center and the new field are rejected in those older schemas. Version 7 adds `editor.backdrop_title`; versions 1–6 gain `"Example Conference Name"` and cannot supply this field under the old schema. Version 8 adds required `editor.position_layer_point`: null keeps matched points; a point enables independent measurement. Versions 1–7 migrate to null and cannot supply this field. Version 9 adds required `layers[].pivot`; versions 1–8 migrate to `[0.5, 0.5]` and cannot supply this field. Version 10 replaces `reference` with the required ordered `references` array. Versions 1–9 migrate null to `[]` and a single image to a one-element array, preserving all image settings. Version 11 adds required `workspace` settings and embedded layer previews. Versions 1–10 gain the documented workspace defaults, with no captures or collapsed folders; supplying `workspace` in an older schema is rejected. Version 12 adds required `folders`, the explicit folder names that survive without members. Versions 1–11 gain `folders: []`, preserving their existing implicit layer grouping; supplying this field under an older version is rejected. Version 13 replaces `midra_link` with required `device_link`, adding the explicit device family. Versions 1–12 migrate numeric links to `family: "midra4k"`; null remains null, and legacy decimal IDs with leading zeros are canonicalized. Unknown legacy fields are rejected. Version 14 adds required `layers[].layer_fit`: versions 1–13 migrate to null, preserving normal crop/zoom behavior; supplying this field under an older schema is rejected. Version 15 adds required `layers[].mask`; versions 1–14 migrate with four zero edges and reject masks supplied under an older version. Version 16 adds required root `input_proposals`; versions 1–15 migrate to an empty array and reject this field if supplied under an older version. Version 17 adds required `mask.origin` (`layer` or `source`). Versions 1–16 migrate to `layer`; older versions containing `origin` are rejected. See the [version 17 example](canvas-pilot-v17.example.json); v16 remains a migration fixture. Version 18 adds required `workspace.snapping.mask_edges` (default false). Versions 1–17 migrate with this option disabled; supplying it under an older schema is rejected. See the [version 18 example](canvas-pilot-v18.example.json). Version 19 replaces each layer’s `device_link` with required `load_mapping` and `send_mapping`. Versions 1–18 migrate the old link to the load source and a single send destination on the current connection (or null and an empty destination list when unlinked). Older schemas containing the new fields are rejected. Saving now writes version 20; older applications reject it. +Version 5 adds required `midra_link` to every layer. Versions 1–4 migrate with null links; links cannot be supplied under an older version. Version 6 renames `editor.position_corner` to `editor.position_point` and adds `center`. Versions 1–5 retain their original corner; center and the new field are rejected in those older schemas. Version 7 adds `editor.backdrop_title`; versions 1–6 gain `"Example Conference Name"` and cannot supply this field under the old schema. Version 8 adds required `editor.position_layer_point`: null keeps matched points; a point enables independent measurement. Versions 1–7 migrate to null and cannot supply this field. Version 9 adds required `layers[].pivot`; versions 1–8 migrate to `[0.5, 0.5]` and cannot supply this field. Version 10 replaces `reference` with the required ordered `references` array. Versions 1–9 migrate null to `[]` and a single image to a one-element array, preserving all image settings. Version 11 adds required `workspace` settings and embedded layer previews. Versions 1–10 gain the documented workspace defaults, with no captures or collapsed folders; supplying `workspace` in an older schema is rejected. Version 12 adds required `folders`, the explicit folder names that survive without members. Versions 1–11 gain `folders: []`, preserving their existing implicit layer grouping; supplying this field under an older version is rejected. Version 13 replaces `midra_link` with required `device_link`, adding the explicit device family. Versions 1–12 migrate numeric links to `family: "midra4k"`; null remains null, and legacy decimal IDs with leading zeros are canonicalized. Unknown legacy fields are rejected. Version 14 adds required `layers[].layer_fit`: versions 1–13 migrate to null, preserving normal crop/zoom behavior; supplying this field under an older schema is rejected. Version 15 adds required `layers[].mask`; versions 1–14 migrate with four zero edges and reject masks supplied under an older version. Version 16 adds required root `input_proposals`; versions 1–15 migrate to an empty array and reject this field if supplied under an older version. Version 17 adds required `mask.origin` (`layer` or `source`). Versions 1–16 migrate to `layer`; older versions containing `origin` are rejected. See the [version 17 example](canvas-pilot-v17.example.json); v16 remains a migration fixture. Version 18 adds required `workspace.snapping.mask_edges` (default false). Versions 1–17 migrate with this option disabled; supplying it under an older schema is rejected. See the [version 18 example](canvas-pilot-v18.example.json). Version 19 replaces each layer’s `device_link` with required `load_mapping` and `send_mapping`. Versions 1–18 migrate the old link to the load source and a single send destination on the current connection (or null and an empty destination list when unlinked). Older schemas containing the new fields are rejected. Saving version 19 migrates into version 20 before the version 21 migration below. Version 20 removes root `input_proposals` and `inputs[].input_crop`. Source dimensions now describe the processed image used by layers. No second local pre-crop is stored, rendered or added to device layer crops. Shared device Input settings drafts remain @@ -35,11 +35,13 @@ session-only and are not project data. Strict migration accepts older projects o when the retired proposal list is empty and all retired input crop edges are zero; otherwise it directs the caller to explicit best-effort Open project. +Version 21 moves `editor.keep_aspect_ratio` to required `layers[].keep_aspect_ratio`. Versions 1–20 copy the former project-wide value to every layer, preserving their resize behavior. Saving now writes version 21; older applications reject it. + ### Best-effort Open project The native-project opening path uses `project_recovery::from_json`. It first tries known migrations and strict validation, then recovers supported fields independently. -Only valid UTF-8 JSON with the Canvas Pilot format and a known version (1–20) is +Only valid UTF-8 JSON with the Canvas Pilot format and a known version (1–21) is accepted, within the 96 MiB limit. Invalid JSON and unknown future versions are errors. Retired proposals and local input crops are discarded with a report; old appearance is not guaranteed. Reload affected layers from the device after input preprocessing. @@ -55,7 +57,7 @@ projects open as unsaved copies, with no automatic overwrite target. Loading nev writes to the source or sends device commands. Strict exchange imports and automatic recovery envelopes retain their separate validation rules. -[Complete example](canvas-pilot-v20.example.json) is a valid project with an empty `Memory A` folder and a Midra link, +[Complete example](canvas-pilot-v21.example.json) is a valid project with an empty `Memory A` folder and a Midra link, with an unlinked Fullscreen example layer and no reference image. New projects label the lower layer `02 / Slides` and the upper layer `01 / Presenter`; existing projects retain their saved IDs/names. It is loaded by the regression tests. @@ -63,7 +65,7 @@ It is loaded by the regression tests. | Root field | Representation / meaning | | --- | --- | | `format` | Exactly `"beffroi.midra-layout"` | -| `version` | Integer `20` | +| `version` | Integer `21` | | `folders` | Required array of 0–256 unique explicit folder names, each trimmed and 1–128 characters. Explicit folders remain even with no members; layer folder labels also form implicit groups. | | `next_layer_id` | Positive integer strictly greater than every layer ID; not rewound by undo | | `output_resolution` | `{ "width": integer, "height": integer }`, screen pixels | @@ -95,6 +97,7 @@ Layer objects: | `send_mapping` | Required `{ "destinations": [...] }`; each destination has exactly `{ "connection": "current", "layer": }`, where the link uses the same family/screen/layer representation as `load_mapping`. Empty means no send destination; exact duplicate destinations within a layer are rejected. Only the current connection is supported; unknown connection kinds are rejected. | | `load_mapping` | Required: null (unlinked) or `{ "family": "midra4k", "screen": "2", "layer": "1" }` / `{ "family": "aquilon", "screen": "S1", "layer": "1" }`. Family is required; unknown fields/families rejected. Layer IDs and Midra screen IDs are canonical positive decimal strings, at most 16 digits; Aquilon screens require `S` (screen) or `A` (auxiliary) plus that numeric ID. This is the load source. No host, bank, credentials or unit identity: linked Aquilon systems are unsupported. | | `pivot` | Required `[x, y]` gravity point relative to the layer top-left, in fractions of width/height. Center is `[0.5, 0.5]`; outside points are allowed. Finite doubles within ±1,000,000, preserved without rounding. Placement/reset is undoable; follows layer movement/reordering. Omitted from SVG and device writes. | +| `keep_aspect_ratio` | Required Boolean. Controls proportional handle and numeric resizing for this layer; changing it is undoable and follows the layer through reorder/save/load. | | `folder` | Local folder name, at most 128 characters; empty means ungrouped | | `source_id` | Existing input slot ID; multiple layers may share an input | | `bounds` | `{ "x": number, "y": number, "width": number, "height": number }`, visible box for normal crop/zoom, container for explicit `layer_fit`, in screen pixels; x/y are its top-left position | @@ -153,7 +156,6 @@ Editor object: | `backdrop_title` | Required string, 0–128 Unicode characters, no control characters. Example backdrop title; empty hides the text. Preserved exactly, including spaces; omitted from SVG/device output. | | `position_point` | Screen measurement origin: `"top_left"`, `"top_right"`, `"bottom_left"`, `"bottom_right"`, `"center"` | | `position_layer_point` | Required: null for the matching layer point (advanced toggle off), or one of the same five point strings for an independent layer endpoint (toggle on) | -| `keep_aspect_ratio` | Boolean for layer resizing | | `viewport_zoom` | Positive fit-relative scale, 0.0001–256 | | `viewport_pan` | `[x, y]`, viewport pan in screen-coordinate pixels; finite, absolute value at most 1e9 | | `show_source_pattern` | Boolean: show source patterns on other layers during crop editing; normal editing always hides patterns | @@ -260,7 +262,7 @@ and `viewBox="0 0 W H"` equal to the output screen. The root carries ## Compatibility changes -Project version 20 and the versioned geometry exchanges are strict contracts. A breaking project field/meaning change must bump +Project version 21 and the versioned geometry exchanges are strict contracts. A breaking project field/meaning change must bump `version` and either implement a tested migration or clearly reject older/newer files. Changing rectangle/marker semantics requires a corresponding documented exchange-interface revision and importer tests. Update this document and its example @@ -278,7 +280,7 @@ retarget existing links; choosing a destination there explicitly replaces that layer's saved link. Direct send/load actions use each layer's saved screen, independently of the screen currently displayed in the configuration window. -Automatic session recovery wraps this project representation in a separate [recovery file](canvas-pilot-recovery.md); named project JSON is version 20. +Automatic session recovery wraps this project representation in a separate [recovery file](canvas-pilot-recovery.md); named project JSON is version 21. ## Folder-scoped Midra transfers @@ -349,7 +351,7 @@ background export behavior. For the complete persistence audit and the reasons for keeping other controls out of project files, see [Project persistence audit](canvas-pilot-persistence-audit.md). -Device links distinguish family, screen/auxiliary and layer. A link from another family cannot be used on the current device without explicit remapping. Multiple editor layers may share one destination; a send scope containing duplicates is rejected with the conflicting layer names. Device state and physical bank roles are never saved in the project. Geometry-only exports omit these links; embedded editor snapshots retain version 20 and use the same migration on import. +Device links distinguish family, screen/auxiliary and layer. A link from another family cannot be used on the current device without explicit remapping. Multiple editor layers may share one destination; a send scope containing duplicates is rejected with the conflicting layer names. Device state and physical bank roles are never saved in the project. Geometry-only exports omit these links; embedded editor snapshots retain version 21 and use the same migration on import. ### Explicit layer fit (v14)