PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Merge PR #7241: Layer Export As: the dialog opens with the layer's size, not the document's
aionggf1fda6389543
diff --cc crates/ui-egui/src/export_dialog.rsindex 62677292c,05ed0d38f..494e4b802--- a/crates/ui-egui/src/export_dialog.rs+++ b/crates/ui-egui/src/export_dialog.rs@@@ -1085,34 -994,33 +1094,61 @@@ mod testsassert_eq!(f["metadata"], "none");}+ /// A recorded Export As step replays only with a destination and a format Export As writes+ /// (#7207); anything else is an error, not a guess.+ #[test]+ fn a_replayed_export_needs_a_path_and_a_known_format() {+ let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());+ assert!(replay(&mut app, &json!({"path": "/x.png"})).unwrap_err().contains("document"));+ app.run("file.new", json!({"width": 4, "height": 4})).unwrap();+ for bad in [json!({}), json!({"path": ""}), json!("nope"), json!({"path": 3})] {+ assert!(replay(&mut app, &bad).unwrap_err().contains("path"), "{bad}");+ }+ for format in [json!("bmp"), json!(7)] {+ assert!(replay(&mut app, &json!({"path": "/x.bmp", "format": format})).unwrap_err().contains("format"), "{format}");+ }+ // A setting of the wrong type or out of the dialog's range is an error, not its default.+ for (key, v) in [+ ("scale", json!("50")),+ ("scale", json!(5000)),+ ("quality", json!(0)),+ ("transparency", json!("yes")),+ ("metadata", json!("some")),+ ("width", json!(-3)),+ ] {+ let mut step = json!({"path": "/x.png", "format": "png"});+ step[key] = v.clone();+ assert!(replay(&mut app, &step).unwrap_err().contains(key), "{key}: {v}");+ }+ }++ /// Layer › Export As opens with the layer's trimmed size, not the document's: `open` seeds the+ /// size fields from the document, and the layer replaces them in scale mode. A remembered+ /// percent scales the layer; remembered exact pixels stay the size the user asked for.+ #[test]+ fn layer_export_as_opens_with_the_layer_size() {+ let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());+ app.run("file.new", json!({"width": 40, "height": 30})).unwrap();+ app.run("layer.new.layer", json!({})).unwrap();+ app.run("select.rect", json!({"x": 4, "y": 2, "width": 10, "height": 6})).unwrap();+ app.run("edit.fill", json!({"color": "#ff0000"})).unwrap();+ let layer = app.session.active().unwrap().active_layer.unwrap();+ let id = open_layer(&mut app, layer).unwrap();+ let f = &app.ui.dialog_mut(id).unwrap().fields;+ assert_eq!((f["__w"].as_f64(), f["__h"].as_f64()), (Some(10.0), Some(6.0)));+ assert_eq!((f["width"].as_f64(), f["height"].as_f64()), (Some(10.0), Some(6.0)));++ app.session.prefs.edit(|p| p.dialogs.insert(COMMAND.into(), json!({"scale": 50})));+ let id = open_layer(&mut app, layer).unwrap();+ let f = &app.ui.dialog_mut(id).unwrap().fields;+ assert_eq!((f["width"].as_f64(), f["height"].as_f64()), (Some(5.0), Some(3.0)));++ app.session.prefs.edit(|p| p.dialogs.insert(COMMAND.into(), json!({"sizing": "pixels", "width": 120, "height": 80})));+ let id = open_layer(&mut app, layer).unwrap();+ let f = &app.ui.dialog_mut(id).unwrap().fields;+ assert_eq!((f["width"].as_f64(), f["height"].as_f64()), (Some(120.0), Some(80.0)));+ }+/// Only the dialog's own settings are remembered: not the destination, the document size or/// the layer the dialog was opened with.#[test]