DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
Properties › Text Wrap: an offset or Invert edit keeps each object's wrap mode
moppeeera1bbf1c7a105
diff --git a/crates/engine/src/cmd/object.rs b/crates/engine/src/cmd/object.rsindex eb2144416..1543b6d5d 100644--- a/crates/engine/src/cmd/object.rs+++ b/crates/engine/src/cmd/object.rs@@ -616,7 +616,7 @@ pub fn specs() -> Vec<CommandSpec> {"Text Wrap",["Window"],Some("Cmd+Alt+W"),- "{mode?: none|boundingBox|contour|jumpObject|jumpToNextColumn (boundingBox when absent, unless side or contour is given: then unchanged), offset?: number|[t,l,b,r] (a null side keeps each object's own), invert?: bool, side?: bothSides|leftSide|rightSide|towardsSpine|awayFromSpine|largestArea, contour?: boundingBox|graphicFrame|sameAsClipping, content?: bool (the placed graphic instead of its frame; default: whether the selection is the frame's content), ids?}; offset or contour drops an imported custom wrap boundary",+ "{mode?: none|boundingBox|contour|jumpObject|jumpToNextColumn (boundingBox when absent, unless side or contour is given; null or those: each object's own, unchanged), offset?: number|[t,l,b,r] (a null side keeps each object's own), invert?: bool, side?: bothSides|leftSide|rightSide|towardsSpine|awayFromSpine|largestArea, contour?: boundingBox|graphicFrame|sameAsClipping, content?: bool (the placed graphic instead of its frame; default: whether the selection is the frame's content), ids?}; offset or contour drops an imported custom wrap boundary",has_selection,text_wrap),@@ -2100,6 +2100,8 @@ fn text_wrap(s: &mut Session, p: &Value) -> Result<Value> {None => None,};let mode: Option<WrapMode> = match p.get("mode") {+ // Null keeps each object's own mode (an edit of the offsets or Invert alone).+ Some(Value::Null) => None,Some(v) => Some(serde_json::from_value(v.clone()).map_err(|_| bad("object.textWrap", "unknown mode"))?),None if side.is_some() || contour.is_some() => None,None => Some(WrapMode::BoundingBox),diff --git a/crates/ui-egui/src/panels/properties.rs b/crates/ui-egui/src/panels/properties.rsindex 302855e06..08bb64c04 100644--- a/crates/ui-egui/src/panels/properties.rs+++ b/crates/ui-egui/src/panels/properties.rs@@ -1043,7 +1043,8 @@ fn wrap_section(app: &mut DesignApp, ui: &mut Ui, i: &SelInfo) {let enabled = i.wrap != "none";let r = ui.add_enabled_ui(enabled, |ui| widgets::checkbox(ui, &mut inv, crate::i18n::tr(&app.ui.language, "Invert"))).inner;if r.changed() {- let _ = app.run("object.textWrap", json!({"mode": i.wrap, "invert": inv}));+ // Each object keeps its own mode.+ let _ = app.run("object.textWrap", json!({"mode": null, "invert": inv}));}});wrap_offsets(app, ui, i);@@ -1106,7 +1107,8 @@ fn wrap_offsets(app: &mut DesignApp, ui: &mut Ui, i: &SelInfo) {}});if let Some(o) = set {- let _ = app.run("object.textWrap", json!({"mode": i.wrap, "offset": o}));+ // Each object keeps its own mode: only the offsets change.+ let _ = app.run("object.textWrap", json!({"mode": null, "offset": o}));}}@@ -3480,7 +3482,7 @@ mod tests {// Two objects with different offsets: a side typed in changes that side on each, and// each keeps its other three.let other = h.state_mut().run("frame.create", json!({"rect": [72, 300, 300, 400], "shape": "rectangle"})).unwrap()["id"].as_u64().unwrap();- h.state_mut().run("object.textWrap", json!({"mode": "boundingBox", "offset": [3, 4, 5, 6], "ids": [other]})).unwrap();+ h.state_mut().run("object.textWrap", json!({"mode": "contour", "offset": [3, 4, 5, 6], "ids": [other]})).unwrap();let of = |h: &Harness<'_, DesignApp>, id: u64| {h.state().session.active().unwrap().doc.item(designcraft_doc::ids::ItemId(id)).unwrap().wrap.offsets};@@ -3489,6 +3491,13 @@ mod tests {let f = fields(&h);type_in(&mut h, f[0], "9pt");assert_eq!((of(&h, id), of(&h, other)), ([9.0, 12.0, 6.0, 12.0], [9.0, 4.0, 5.0, 6.0]), "the top alone, on each");+ let mode =+ |h: &Harness<'_, DesignApp>, id: u64| h.state().session.active().unwrap().doc.item(designcraft_doc::ids::ItemId(id)).unwrap().wrap.mode;+ assert_eq!(+ (mode(&h, id), mode(&h, other)),+ (designcraft_doc::WrapMode::BoundingBox, designcraft_doc::WrapMode::Contour),+ "each keeps its mode"+ );// An object whose offsets are the same starts linked, though the link was off before.let third = h.state_mut().run("frame.create", json!({"rect": [320, 72, 500, 200], "shape": "rectangle"})).unwrap()["id"].as_u64().unwrap();h.state_mut().run("object.textWrap", json!({"mode": "boundingBox", "offset": 4, "ids": [third]})).unwrap();