Skip to content

DesignCraft: An open-source page and layout design editor written by scratch in pure Rust

Place: an image placed into a frame fills it once and leaves Auto-Fit off

aiongg1da2bb90829f
diff --git a/crates/engine/src/cmd/file.rs b/crates/engine/src/cmd/file.rs
index f871a43e8..0e46ad033 100644
--- a/crates/engine/src/cmd/file.rs
+++ b/crates/engine/src/cmd/file.rs
@@ -350,14 +350,14 @@ fn file_place(s: &mut Session, p: &Value) -> Result<Value> {
let id = if let Some(fid) = target_frame {
let it = d.item_mut(fid).ok_or(designcraft_doc::DocError::NoItem(fid))?;
let r = it.inner_bounds();
- // Fill frame proportionally.
+ // Fill the frame proportionally once. Auto-Fit stays off, so resizing the frame crops.
let k = (r.width() / nw).max(r.height() / nh);
let (gw, gh) = (nw * k, nh * k);
it.content = Content::Graphic(Graphic {
asset: aid,
size: (nw, nh),
xf: Affine::translate((r.x0 + (r.width() - gw) / 2.0, r.y0 + (r.height() - gh) / 2.0)) * Affine::scale(k),
- auto_fit: designcraft_doc::Fitting::FillProportionally,
+ auto_fit: Default::default(),
fit_align: 4,
crop: [0.0; 4],
});
@@ -471,7 +471,7 @@ fn place_drop(s: &mut Session, p: &Value) -> Result<Value> {
asset: aid,
size: (nw, nh),
xf: Affine::translate((r.x0 + (r.width() - nw * k) / 2.0, r.y0 + (r.height() - nh * k) / 2.0)) * Affine::scale(k),
- auto_fit: designcraft_doc::Fitting::FillProportionally,
+ auto_fit: Default::default(),
fit_align: 4,
crop: [0.0; 4],
});
diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs
index c1032bccf..17d1ed098 100644
--- a/crates/engine/src/tests.rs
+++ b/crates/engine/src/tests.rs
@@ -284,7 +284,15 @@ fn place_gun_click_drag_and_into_frame() {
let f = s.execute("frame.create", &json!({"rect": [300, 300, 400, 400], "content": "graphic"})).unwrap()["id"].as_u64().unwrap();
s.execute("place.load", &json!({"base64": b64})).unwrap();
s.execute("place.drop", &json!({"frame": f})).unwrap();
- assert!(matches!(s.doc().unwrap().doc.item(designcraft_doc::ItemId(f)).unwrap().content, designcraft_doc::Content::Graphic(_)));
+ let graphic_xf = |s: &Session| match &s.doc().unwrap().doc.item(designcraft_doc::ItemId(f)).unwrap().content {
+ designcraft_doc::Content::Graphic(g) => g.xf,
+ _ => panic!("not a graphic"),
+ };
+ let placed = graphic_xf(&s);
+ // Dragging the top edge down crops the top only: the image stays where it is.
+ s.execute("selection.set", &json!({"ids": [f]})).unwrap();
+ s.execute("transform.resize", &json!({"from": [300, 300, 400, 400], "to": [300, 340, 400, 400]})).unwrap();
+ assert_eq!(graphic_xf(&s), placed);
}
#[test]