Skip to content

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

Merge remote-tracking branch 'origin/main' into zydvc26s67-web-paragraph-styles-save-delete

zydvc26s67-web117429085b10
diff --cc crates/engine/src/tests.rs
index e331b30a6,712dc06bc..e47542518
--- a/crates/engine/src/tests.rs
+++ b/crates/engine/src/tests.rs
@@@ -570,117 -570,186 +570,297 @@@ fn commands_take_non_object_params_with
}
}
+#[test]
+fn paragraph_style_edit_persists_attrs_and_rename() {
+ let mut s = session();
+ let name =
+ s.execute("style.paragraph.create", &json!({"name": "Body Copy", "para": {"align": "left"}})).unwrap()["name"].as_str().unwrap().to_string();
+ s.execute("style.paragraph.edit", &json!({"name": name, "para": {"align": "center"}})).unwrap();
+ {
+ let st = s.doc().unwrap();
+ let style = st.doc.styles.para(&name).expect("style still exists");
+ assert_eq!(style.para.align, Some(designcraft_doc::Align::Center), "edited attribute persisted");
+ }
+ // Renaming updates the style definition itself, and every place it's referenced.
+ s.execute("style.paragraph.edit", &json!({"name": name, "rename": "Body Text"})).unwrap();
+ let st = s.doc().unwrap();
+ assert!(st.doc.styles.para("Body Text").is_some(), "renamed style exists under the new name");
+ assert!(st.doc.styles.para(&name).is_none(), "old name is gone");
+}
+
+#[test]
+fn paragraph_style_edit_rejects_based_on_cycle() {
+ let mut s = session();
+ let a = s.execute("style.paragraph.create", &json!({"name": "A"})).unwrap()["name"].as_str().unwrap().to_string();
+ let b = s.execute("style.paragraph.create", &json!({"name": "B", "basedOn": a})).unwrap()["name"].as_str().unwrap().to_string();
+ let r = s.execute("style.paragraph.edit", &json!({"name": a, "basedOn": b}));
+ assert!(r.is_err(), "A based on B based on A must be rejected");
+}
+
+#[test]
+fn paragraph_style_delete_reassigns_affected_text() {
+ let mut s = session();
+ let name = s.execute("style.paragraph.create", &json!({"name": "Caption"})).unwrap()["name"].as_str().unwrap().to_string();
+ let sid = s.execute("frame.create", &json!({"rect": [36, 36, 300, 200], "content": "text"})).unwrap()["story"].as_u64().unwrap();
+ s.execute("text.insert", &json!({"text": "Hello, world"})).unwrap();
+ s.execute("text.select", &json!({"story": sid, "anchor": 0, "focus": 0})).unwrap();
+ s.execute("style.paragraph.apply", &json!({"name": name})).unwrap();
+ {
+ let st = s.doc().unwrap();
+ let story = st.doc.stories.get(&designcraft_doc::StoryId(sid)).expect("story exists");
+ assert_eq!(story.paras[0].style, name, "style applied before delete");
+ }
+ s.execute("style.paragraph.delete", &json!({"name": name, "replaceWith": designcraft_doc::BASIC_PARAGRAPH})).unwrap();
+ let st = s.doc().unwrap();
+ assert!(st.doc.styles.para(&name).is_none(), "deleted style is gone");
+ let story = st.doc.stories.get(&designcraft_doc::StoryId(sid)).expect("story exists");
+ assert_eq!(story.paras[0].style, designcraft_doc::BASIC_PARAGRAPH, "affected paragraph reassigned to the replacement style");
+}
+
+#[test]
+fn paragraph_style_delete_rejects_builtin_styles() {
+ let mut s = session();
+ let r = s.execute("style.paragraph.delete", &json!({"name": designcraft_doc::BASIC_PARAGRAPH}));
+ assert!(r.is_err(), "built-in styles can't be deleted");
+}
+
+#[test]
+fn character_style_edit_persists_attrs_and_rename() {
+ let mut s = session();
+ let name = s.execute("style.character.create", &json!({"name": "Key Term", "chars": {"fontStyle": "Bold"}})).unwrap()["name"]
+ .as_str()
+ .unwrap()
+ .to_string();
+ s.execute("style.character.edit", &json!({"name": name, "chars": {"tracking": 20.0}})).unwrap();
+ {
+ let st = s.doc().unwrap();
+ let style = st.doc.styles.char_style(&name).expect("style still exists");
+ assert_eq!(style.chars.tracking, Some(20.0), "edited attribute persisted");
+ }
+ // Renaming updates the style definition itself, and every place it's referenced.
+ s.execute("style.character.edit", &json!({"name": name, "rename": "Emphasis"})).unwrap();
+ let st = s.doc().unwrap();
+ assert!(st.doc.styles.char_style("Emphasis").is_some(), "renamed style exists under the new name");
+ assert!(st.doc.styles.char_style(&name).is_none(), "old name is gone");
+}
+
+#[test]
+fn character_style_edit_rejects_based_on_cycle() {
+ let mut s = session();
+ let a = s.execute("style.character.create", &json!({"name": "A"})).unwrap()["name"].as_str().unwrap().to_string();
+ let b = s.execute("style.character.create", &json!({"name": "B", "basedOn": a})).unwrap()["name"].as_str().unwrap().to_string();
+ let r = s.execute("style.character.edit", &json!({"name": a, "basedOn": b}));
+ assert!(r.is_err(), "A based on B based on A must be rejected");
+}
+
+#[test]
+fn character_style_delete_reassigns_affected_text() {
+ let mut s = session();
+ let name = s.execute("style.character.create", &json!({"name": "Key Term"})).unwrap()["name"].as_str().unwrap().to_string();
+ let r = s.execute("frame.create", &json!({"rect": [36, 36, 300, 200], "content": "text"})).unwrap();
+ let sid = r["story"].as_u64().unwrap();
+ s.execute("text.insert", &json!({"text": "Hello, world"})).unwrap();
+ s.execute("text.select", &json!({"story": sid, "anchor": 0, "focus": 5})).unwrap();
+ s.execute("style.character.apply", &json!({"name": name})).unwrap();
+ {
+ let st = s.doc().unwrap();
+ let story = st.doc.stories.get(&designcraft_doc::StoryId(sid)).expect("story exists");
+ assert_eq!(story.chars[0].format.style, name, "style applied before delete");
+ }
+ s.execute("style.character.delete", &json!({"name": name, "replaceWith": designcraft_doc::NO_CHAR_STYLE})).unwrap();
+ let st = s.doc().unwrap();
+ assert!(st.doc.styles.char_style(&name).is_none(), "deleted style is gone");
+ let story = st.doc.stories.get(&designcraft_doc::StoryId(sid)).expect("story exists");
+ assert_eq!(story.chars[0].format.style, designcraft_doc::NO_CHAR_STYLE, "affected run reassigned to the replacement style");
+}
+
+#[test]
+fn character_style_delete_rejects_builtin_styles() {
+ let mut s = session();
+ let r = s.execute("style.character.delete", &json!({"name": designcraft_doc::NO_CHAR_STYLE}));
+ assert!(r.is_err(), "built-in styles can't be deleted");
+}
+
+ #[test]
+ fn page_tool_selects_a_page_and_its_handles_preview_or_resize_it() {
+ use designcraft_tools::{CanvasLayout, Mods, PointerEvent, PointerKind};
+ let mut s = Session::new();
+ s.execute("file.new", &json!({"width": 612, "height": 792, "facingPages": false})).unwrap();
+ let id = s.execute("frame.create", &json!({"rect": [400, 100, 500, 200]})).unwrap()["id"].as_u64().unwrap();
+ let frame = |s: &Session| s.doc().unwrap().doc.item(designcraft_doc::ItemId(id)).unwrap().bounds();
+ let width = |s: &Session| s.doc().unwrap().doc.spreads[0].pages[0].width;
+ // The page on the canvas (a single page is centred on the spine).
+ let page = |s: &Session| {
+ let d = &s.doc().unwrap().doc;
+ CanvasLayout::new(d, false).page_rect(d, 0).unwrap()
+ };
+ s.set_tool("page");
+ let v = ViewInfo::at_zoom(1.0);
+ let ev = |kind, x: f64, y: f64, alt: bool| PointerEvent { mods: Mods { alt, ..Default::default() }, ..PointerEvent::new(kind, x, y) };
+ let drag = |s: &mut Session, from: (f64, f64), by: f64, alt: bool, check: &dyn Fn(&Session)| {
+ s.pointer(&ev(PointerKind::Down, from.0, from.1, alt), v).unwrap();
+ s.pointer(&ev(PointerKind::Drag, from.0 + by, from.1, alt), v).unwrap();
+ check(s);
+ s.pointer(&ev(PointerKind::Up, from.0 + by, from.1, alt), v).unwrap();
+ };
+ // A click selects the page.
+ let c = page(&s).center();
+ s.pointer(&ev(PointerKind::Down, c.x, c.y, false), v).unwrap();
+ s.pointer(&ev(PointerKind::Up, c.x, c.y, false), v).unwrap();
+ assert_eq!(s.doc().unwrap().selection.page, Some(0));
+ // A plain drag of the right handle previews the page's liquid rule and springs back.
+ s.execute("liquid.pageRule", &json!({"rule": "scale"})).unwrap();
+ let undo = s.doc().unwrap().history.undo.len();
+ let r = page(&s);
+ drag(&mut s, (r.x1, r.center().y), 612.0, false, &|s| {
+ assert_eq!(width(s), 1224.0, "previewed");
+ // Scale keeps proportions: only wider, so the frame is centred on the wider page.
+ assert_eq!(frame(s).x0, 706.0, "the Scale rule in the preview: {:?}", frame(s));
+ });
+ assert_eq!((width(&s), frame(&s)), (612.0, designcraft_geom::Rect::new(400.0, 100.0, 500.0, 200.0)), "sprung back");
+ assert_eq!(s.doc().unwrap().history.undo.len(), undo, "nothing to undo");
+ // Alt-drag resizes; with the rule off the frame stays where it is.
+ s.execute("liquid.pageRule", &json!({"rule": "off"})).unwrap();
+ let r = page(&s);
+ drag(&mut s, (r.x1, r.center().y), 100.0, true, &|_| {});
+ assert_eq!(width(&s), 712.0);
+ assert_eq!(frame(&s).x0, 400.0);
+ // The left handle grows the page to the left: the frame keeps its place by the right edge.
+ let r = page(&s);
+ drag(&mut s, (r.x0, r.center().y), -100.0, true, &|_| {});
+ let pg = s.doc().unwrap().doc.spreads[0].pages[0].clone();
+ assert_eq!(pg.width, 812.0);
+ assert_eq!(frame(&s).x0 - pg.x, 500.0, "100 pt further from the page's left edge");
+ // A click on the pasteboard deselects the page.
+ let r = page(&s);
+ s.pointer(&ev(PointerKind::Down, r.x0 - 200.0, r.center().y, false), v).unwrap();
+ assert_eq!(s.doc().unwrap().selection.page, None);
+ }
+
+ #[test]
+ fn page_size_keeps_objects_by_its_anchor() {
+ let mut s = Session::new();
+ s.execute("file.new", &json!({"width": 400, "height": 400, "facingPages": false})).unwrap();
+ let id = s.execute("frame.create", &json!({"rect": [100, 100, 200, 200]})).unwrap()["id"].as_u64().unwrap();
+ let frame = |s: &Session| s.doc().unwrap().doc.item(designcraft_doc::ItemId(id)).unwrap().bounds();
+ // Bottom-right stays put: 100 wider and 50 taller moves the frame 100 right and 50 down.
+ s.execute("layout.pageSize", &json!({"pages": [1], "width": 500, "height": 450, "anchor": 8})).unwrap();
+ assert_eq!(frame(&s), designcraft_geom::Rect::new(200.0, 150.0, 300.0, 250.0));
+ // The centre: half of it.
+ s.execute("layout.pageSize", &json!({"pages": [1], "width": 700, "height": 450, "anchor": 4})).unwrap();
+ assert_eq!(frame(&s).x0, 300.0);
+ assert!(s.execute("layout.pageSize", &json!({"pages": [1], "width": 700, "anchor": 9})).is_err());
+ assert!(s.execute("layout.selectPage", &json!({"page": 2})).is_err());
+ assert_eq!(s.execute("layout.selectPage", &json!({"page": 1})).unwrap()["page"], 1);
+ }
+
+ #[test]
+ fn controlled_by_parent_takes_the_parent_pages_rule() {
+ let mut s = Session::new();
+ s.execute("file.new", &json!({"width": 400, "height": 400, "facingPages": false})).unwrap();
+ let id = s.execute("frame.create", &json!({"rect": [100, 100, 200, 200]})).unwrap()["id"].as_u64().unwrap();
+ let frame = |s: &Session| s.doc().unwrap().doc.item(designcraft_doc::ItemId(id)).unwrap().bounds();
+ // The page follows its parent; the parent page re-centres.
+ s.execute("liquid.pageRule", &json!({"rule": "controlledByParent", "pages": [1]})).unwrap();
+ s.edit(|d, _| {
+ std::sync::Arc::make_mut(&mut d.parents[0]).pages[0].liquid = designcraft_doc::LiquidRule::ReCenter;
+ Ok(())
+ })
+ .unwrap();
+ s.execute("layout.pageSize", &json!({"pages": [1], "width": 600})).unwrap();
+ assert_eq!(frame(&s).x0, 200.0, "re-centred: {:?}", frame(&s));
+ // Without a parent (or a parent that's also controlled by its parent) nothing moves.
+ s.execute("layout.pages.applyParent", &json!({"pages": [0], "parent": null})).unwrap();
+ s.execute("layout.pageSize", &json!({"pages": [1], "width": 800})).unwrap();
+ assert_eq!(frame(&s).x0, 200.0);
+ // Show Parent Page Overlay is a page option.
+ s.execute("layout.pageOptions", &json!({"pages": [1], "showParentOverlay": true})).unwrap();
+ assert!(s.doc().unwrap().doc.spreads[0].pages[0].show_parent_overlay);
+ assert!(s.execute("layout.pageOptions", &json!({"pages": [2], "showParentOverlay": true})).is_err());
+ }
+
+ #[test]
+ fn page_tool_pins_and_locks_objects_on_object_based_pages() {
+ use designcraft_tools::{CanvasLayout, Mods, PointerEvent, PointerKind};
+ let mut s = Session::new();
+ s.execute("file.new", &json!({"width": 612, "height": 792, "facingPages": false})).unwrap();
+ let id = s.execute("frame.create", &json!({"rect": [256, 72, 356, 132]})).unwrap()["id"].as_u64().unwrap();
+ s.execute("liquid.pageRule", &json!({"rule": "objectBased"})).unwrap();
+ s.execute("edit.deselectAll", &json!({})).unwrap();
+ s.set_tool("page");
+ let v = ViewInfo::at_zoom(1.0);
+ let ev =
+ |kind, p: designcraft_geom::Point, alt: bool| PointerEvent { mods: Mods { alt, ..Default::default() }, ..PointerEvent::new(kind, p.x, p.y) };
+ let canvas = |s: &Session| {
+ let d = &s.doc().unwrap().doc;
+ let l = CanvasLayout::new(d, false);
+ (
+ l.page_rect(d, 0).unwrap(),
+ l.xf(designcraft_doc::SpreadRef::Doc(0)).transform_rect_bbox(d.item(designcraft_doc::ItemId(id)).unwrap().bounds()),
+ )
+ };
+ let click = |s: &mut Session, p: designcraft_geom::Point| {
+ s.pointer(&ev(PointerKind::Down, p, false), v).unwrap();
+ s.pointer(&ev(PointerKind::Up, p, false), v).unwrap();
+ };
+ let liquid = |s: &Session| s.doc().unwrap().doc.item(designcraft_doc::ItemId(id)).unwrap().liquid;
+ // A click on the object selects it with its page; its pins and locks show.
+ let (_, o) = canvas(&s);
+ click(&mut s, o.center());
+ let sel = s.doc().unwrap().selection.clone();
+ assert_eq!((sel.page, sel.items.clone()), (Some(0), vec![designcraft_doc::ItemId(id)]));
+ assert!(
+ s.overlays(v)
+ .iter()
+ .any(|o| matches!(o, designcraft_tools::Overlay::LiquidPins { pins: [false, false, false, false], resize: [true, true], .. }))
+ );
+ // The right pin (14 px outside the right edge) and the width lock (10 px right of the centre).
+ click(&mut s, designcraft_geom::Point::new(o.x1 + 14.0, o.center().y));
+ click(&mut s, designcraft_geom::Point::new(o.center().x + 10.0, o.center().y));
+ let l = liquid(&s).unwrap();
+ assert!(l.pin_right && !l.resize_width && l.resize_height && !l.pin_left, "{l:?}");
+ // Alt-drag the page 100 pt wider: the pinned, width-locked frame keeps its size by the right edge.
+ let (p, _) = canvas(&s);
+ let right = designcraft_geom::Point::new(p.x1, p.center().y);
+ s.pointer(&ev(PointerKind::Down, right, true), v).unwrap();
+ s.pointer(&ev(PointerKind::Drag, right + designcraft_geom::Vec2::new(100.0, 0.0), true), v).unwrap();
+ s.pointer(&ev(PointerKind::Up, right + designcraft_geom::Vec2::new(100.0, 0.0), true), v).unwrap();
+ let d = &s.doc().unwrap().doc;
+ let (pg, b) = (&d.spreads[0].pages[0], d.item(designcraft_doc::ItemId(id)).unwrap().bounds());
+ assert_eq!(pg.width, 712.0);
+ assert!((b.width() - 100.0).abs() < 1e-6 && (pg.x + pg.width - b.x1 - 256.0).abs() < 1e-6, "{b:?}");
+ // Hovering a pin shows its tooltip.
+ let (_, o) = canvas(&s);
+ s.pointer(&ev(PointerKind::Move, designcraft_geom::Point::new(o.x1 + 14.0, o.center().y), false), v).unwrap();
+ assert!(s.overlays(v).iter().any(|o| matches!(o, designcraft_tools::Overlay::Tip { text, .. } if text.starts_with("Object is pinned"))));
+ }
+
+ #[test]
+ fn duplicating_a_page_keeps_its_own_size_rule_guides_and_objects() {
+ // Chris Cicchino's Page Tool video (2:06): the letterhead page is duplicated, then resized.
+ let mut s = Session::new();
+ s.execute("file.new", &json!({"width": 252, "height": 144, "facingPages": false})).unwrap();
+ s.execute("layout.pages.insert", &json!({"count": 1})).unwrap();
+ s.execute("layout.pageSize", &json!({"pages": [2], "width": 612, "height": 792})).unwrap();
+ s.execute("liquid.pageRule", &json!({"rule": "scale", "pages": [2]})).unwrap();
+ s.execute("guide.add", &json!({"spread": 1, "page": 0, "orientation": "vertical", "position": 300})).unwrap();
+ s.execute("frame.create", &json!({"spread": 1, "rect": [100, 100, 200, 200]})).unwrap();
+ let r = s.execute("layout.pages.duplicateSpread", &json!({"spread": 1})).unwrap();
+ assert_eq!(r["page"], 2);
+ let d = s.doc().unwrap().doc.clone();
+ let (si, pi) = d.page_loc(2).unwrap();
+ let pg = &d.spreads[si].pages[pi];
+ assert_eq!((pg.width, pg.height, pg.liquid), (612.0, 792.0, designcraft_doc::LiquidRule::Scale));
+ assert_eq!(pg.guides.len(), 1);
+ assert_eq!(d.spreads[si].items.len(), 1);
+ // At the end of the document (the New Page button): the business card, not the last page's size.
+ let r = s.execute("layout.pages.duplicateSpread", &json!({"spread": 0, "atEnd": true})).unwrap();
+ assert_eq!(r["page"], 3);
+ let d = s.doc().unwrap().doc.clone();
+ let (si, pi) = d.page_loc(3).unwrap();
+ assert_eq!((d.spreads[si].pages[pi].width, d.spreads[si].pages[pi].height), (252.0, 144.0));
+ }
+
/// Load the text from a frame's out port with the Selection tool and click on the pasteboard:
/// a new frame is threaded there and the overset text flows into it.
#[test]
diff --cc crates/ui-egui/src/dialogs.rs
index 09aa3f1d1,bf096ce31..370a40b0b
--- a/crates/ui-egui/src/dialogs.rs
+++ b/crates/ui-egui/src/dialogs.rs
@@@ -1186,120 -1191,322 +1193,324 @@@ pub fn show(app: &mut DesignApp, ctx: &
// forms remain reachable at large UI scales, without shrinking their text.
let footer_height = ui.spacing().interact_size.y.max(ui.text_style_height(&egui::TextStyle::Button) + 2.0 * ui.spacing().button_padding.y);
let body_height = (available.y - ui.min_size().y - footer_height - 12.0 - 2.0 * ui.spacing().item_spacing.y).max(1.0);
- egui::ScrollArea::both().id_salt(("dialog_body", &d.id)).min_scrolled_width(1.0).min_scrolled_height(1.0).max_width(width).max_height(body_height).show(ui, |ui| {
- match d.id.as_str() {
- "newDocument" => {
- ui.horizontal(|ui| {
- ui.with_layout(if crate::i18n::is_rtl(&app.ui.language) { egui::Layout::right_to_left(egui::Align::Center) } else { egui::Layout::left_to_right(egui::Align::Center) }, |ui| {
- crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, "Preset"));
- let cur = d.s("preset");
- egui::ComboBox::from_id_salt("preset").selected_text(&cur).width(180.0).show_ui(ui, |ui| {
- for p in designcraft_doc::build::PRESETS {
- if ui.selectable_label(cur == p.name, p.name).clicked() {
- d.fields.insert("preset".into(), json!(p.name));
- d.fields.insert("width".into(), json!(format_measure(p.width, p.units)));
- d.fields.insert("height".into(), json!(format_measure(p.height, p.units)));
- d.fields.insert("facingPages".into(), json!(p.intent == designcraft_doc::Intent::Print));
- }
+ egui::ScrollArea::both()
+ .id_salt(("dialog_body", &d.id))
+ .min_scrolled_width(1.0)
+ .min_scrolled_height(1.0)
+ .max_width(width)
+ .max_height(body_height)
+ .show(ui, |ui| match d.id.as_str() {
+ "newDocument" => {
+ ui.horizontal(|ui| {
+ ui.with_layout(
+ if crate::i18n::is_rtl(&app.ui.language) {
+ egui::Layout::right_to_left(egui::Align::Center)
+ } else {
+ egui::Layout::left_to_right(egui::Align::Center)
+ },
+ |ui| {
+ crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, "Preset"));
+ let cur = d.s("preset");
+ egui::ComboBox::from_id_salt("preset").selected_text(&cur).width(180.0).show_ui(ui, |ui| {
+ for p in designcraft_doc::build::PRESETS {
+ if ui.selectable_label(cur == p.name, p.name).clicked() {
+ d.fields.insert("preset".into(), json!(p.name));
+ d.fields.insert("width".into(), json!(format_measure(p.width, p.units)));
+ d.fields.insert("height".into(), json!(format_measure(p.height, p.units)));
+ d.fields.insert("facingPages".into(), json!(p.intent == designcraft_doc::Intent::Print));
+ }
+ }
+ });
+ },
+ );
+ });
+ if crate::i18n::is_rtl(&app.ui.language) {
+ // egui Grid currently supports LTR only. Use explicit RTL rows;
+ // the numeric editors retain LTR alignment and logical values.
+ for (first, key, second, other, toggle) in [
+ ("Width", "width", "Height", "height", false),
+ ("Pages", "pages", "Facing Pages", "facingPages", true),
+ ("Columns", "columns", "Gutter", "gutter", false),
+ ("Top", "marginTop", "Bottom", "marginBottom", false),
+ ("Inside", "marginInside", "Outside", "marginOutside", false),
+ ("Bleed", "bleed", "Primary Text Frame", "primaryTextFrame", true),
+ ] {
+ ui.horizontal(|ui| {
+ ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
+ crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, first));
+ text_field(ui, &mut d, key, 80.0);
+ if toggle {
+ check(ui, &mut d, other, crate::i18n::tr(&app.ui.language, second));
+ } else {
+ crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, second));
+ text_field(ui, &mut d, other, 80.0);
+ }
+ });
+ });
}
+ } else {
+ egui::Grid::new("nd").num_columns(4).spacing([8.0, 6.0]).show(ui, |ui| {
+ crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, "Width"));
+ text_field(ui, &mut d, "width", 80.0);
+ crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, "Height"));
+ text_field(ui, &mut d, "height", 80.0);
+ ui.end_row();
+ crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, "Pages"));
+ text_field(ui, &mut d, "pages", 80.0);
+ ui.label("");
+ check(ui, &mut d, "facingPages", crate::i18n::tr(&app.ui.language, "Facing Pages"));
+ ui.end_row();
+ crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, "Columns"));
+ text_field(ui, &mut d, "columns", 80.0);
+ crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, "Gutter"));
+ text_field(ui, &mut d, "gutter", 80.0);
+ ui.end_row();
+ crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, "Top"));
+ text_field(ui, &mut d, "marginTop", 80.0);
+ crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, "Bottom"));
+ text_field(ui, &mut d, "marginBottom", 80.0);
+ ui.end_row();
+ crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, "Inside"));
+ text_field(ui, &mut d, "marginInside", 80.0);
+ crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, "Outside"));
+ text_field(ui, &mut d, "marginOutside", 80.0);
+ ui.end_row();
+ crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, "Bleed"));
+ text_field(ui, &mut d, "bleed", 80.0);
+ ui.label("");
+ check(ui, &mut d, "primaryTextFrame", crate::i18n::tr(&app.ui.language, "Primary Text Frame"));
+ ui.end_row();
+ });
+ }
+ }
+ "frameSize" => {
+ egui::Grid::new("fs").num_columns(2).spacing([8.0, 6.0]).show(ui, |ui| {
+ crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, "Width"));
+ text_field(ui, &mut d, "width", 90.0);
+ ui.end_row();
+ crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, "Height"));
+ text_field(ui, &mut d, "height", 90.0);
+ ui.end_row();
});
+ }
+ "findChange" => {
+ ui.horizontal(|ui| {
+ for (label, grep) in [("Text", false), ("GREP", true)] {
+ if ui
+ .selectable_label(
+ !d.b("objectMode") && d.b("grep") == grep,
+ crate::rtl::widget(ui, crate::i18n::tr(&app.ui.language, label)),
+ )
+ .clicked()
+ {
+ if d.set_field("objectMode", json!(false)) {
+ app.session.reset_find_scope();
+ }
+ d.fields.insert("grep".into(), json!(grep));
+ }
+ }
+ if ui.selectable_label(d.b("objectMode"), crate::rtl::widget(ui, crate::i18n::tr(&app.ui.language, "Object"))).clicked()
+ && d.set_field("objectMode", json!(true))
+ {
+ app.session.reset_find_scope();
+ }
});
- });
- if crate::i18n::is_rtl(&app.ui.language) {
- // egui Grid currently supports LTR only. Use explicit RTL rows;
- // the numeric editors retain LTR alignment and logical values.
- for (first, key, second, other, toggle) in [
- ("Width", "width", "Height", "height", false),
- ("Pages", "pages", "Facing Pages", "facingPages", true),
- ("Columns", "columns", "Gutter", "gutter", false),
- ("Top", "marginTop", "Bottom", "marginBottom", false),
- ("Inside", "marginInside", "Outside", "marginOutside", false),
- ("Bleed", "bleed", "Primary Text Frame", "primaryTextFrame", true),
- ] {
+ if d.b("objectMode") {
+ // Find/Change › Object: objects by fill and kind; change their fill or opacity.
+ let swatches: Vec<String> = app
+ .session
+ .active()
+ .map(|st| st.doc.swatches.iter().filter(|w| !w.hidden).map(|w| w.name.clone()).collect())
+ .unwrap_or_default();
+ egui::Grid::new("fco").num_columns(2).spacing([8.0, 6.0]).show(ui, |ui| {
+ for (key, label, any) in [("objFill", "Find fill:", "(any)"), ("objChangeFill", "Change fill to:", "(unchanged)")] {
+ crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, label));
+ let cur = d.s(key);
+ egui::ComboBox::from_id_salt(key)
+ .selected_text(if cur.is_empty() { any } else { cur.as_str() })
+ .width(180.0)
+ .show_ui(ui, |ui| {
+ if ui
+ .selectable_label(cur.is_empty(), crate::rtl::widget(ui, crate::i18n::tr(&app.ui.language, any)))
+ .clicked()
+ {
+ d.fields.insert(key.into(), json!(""));
+ }
+ for w in &swatches {
+ if ui.selectable_label(*w == cur, w).clicked() {
+ d.fields.insert(key.into(), json!(w));
+ }
+ }
+ });
+ ui.end_row();
+ }
+ crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, "Kind:"));
+ let cur = d.s("objKind");
+ egui::ComboBox::from_id_salt("objKind").selected_text(if cur.is_empty() { "(any)" } else { cur.as_str() }).show_ui(
+ ui,
+ |ui| {
+ for v in ["", "text", "graphic", "shape", "line", "group"] {
+ if ui
+ .selectable_label(
+ cur == v,
+ crate::rtl::widget(ui, crate::i18n::tr(&app.ui.language, if v.is_empty() { "(any)" } else { v })),
+ )
+ .clicked()
+ {
+ d.fields.insert("objKind".into(), json!(v));
+ }
+ }
+ },
+ );
+ ui.end_row();
+ });
+ let mut crit = json!({});
+ if !d.s("objFill").is_empty() {
+ crit["fill"] = json!(d.s("objFill"));
+ }
+ if !d.s("objKind").is_empty() {
+ crit["kind"] = json!(d.s("objKind"));
+ }
ui.horizontal(|ui| {
- ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
- crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, first));
- text_field(ui, &mut d, key, 80.0);
- if toggle {
- check(ui, &mut d, other, crate::i18n::tr(&app.ui.language, second));
- } else {
- crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, second));
- text_field(ui, &mut d, other, 80.0);
- }
- });
+ if ui.button(crate::rtl::widget(ui, crate::i18n::tr(&app.ui.language, "Find All"))).clicked() {
+ let n = app.run("find.objects", crit.clone()).ok().and_then(|r| r["ids"].as_array().map(Vec::len)).unwrap_or(0);
+ d.fields.insert("status".into(), json!(format!("{n} found")));
+ }
+ if ui.button(crate::rtl::widget(ui, crate::i18n::tr(&app.ui.language, "Change All"))).clicked()
+ && !d.s("objChangeFill").is_empty()
+ {
+ let mut p = crit.clone();
+ p["change"] = json!({"fill": d.s("objChangeFill")});
+ let n = app.run("find.changeObjects", p).ok().and_then(|r| r["changed"].as_u64()).unwrap_or(0);
+ d.fields.insert("status".into(), json!(format!("{n} changed")));
+ }
+ });
+ ui.label(d.s("status"));
+ } else {
+ egui::Grid::new("fc").num_columns(2).spacing([8.0, 6.0]).show(ui, |ui| {
+ crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, "Find what:"));
+ text_field(ui, &mut d, "find", 260.0);
+ ui.end_row();
+ crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, "Change to:"));
+ text_field(ui, &mut d, "change", 260.0);
+ ui.end_row();
+ crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, "Search:"));
+ let cur = d.s("scope");
+ egui::ComboBox::from_id_salt("fcscope")
+ .selected_text(crate::rtl::widget(ui, crate::i18n::tr(&app.ui.language, &cur)))
+ .show_ui(ui, |ui| {
+ for v in ["document", "story", "selection"] {
+ if ui.selectable_label(cur == v, crate::rtl::widget(ui, crate::i18n::tr(&app.ui.language, v))).clicked()
+ && d.set_field("scope", json!(v))
+ {
+ app.session.reset_find_scope();
+ }
+ }
+ });
+ ui.end_row();
+ });
+ ui.horizontal(|ui| {
+ check(ui, &mut d, "caseSensitive", crate::i18n::tr(&app.ui.language, "Case sensitive"));
+ check(ui, &mut d, "wholeWord", crate::i18n::tr(&app.ui.language, "Whole word"));
+ });
+ ui.horizontal(|ui| {
+ let params0 = find_change_params(&d);
+ let params = || params0.clone();
+ if ui.button(crate::rtl::widget(ui, crate::i18n::tr(&app.ui.language, "Find Next"))).clicked() {
+ let r = app.run("find.next", params());
+ let msg = match r {
+ Ok(Value::Null) => "No matches".to_string(),
+ Ok(_) => "Found".to_string(),
+ Err(e) => e,
+ };
+ d.fields.insert("status".into(), json!(msg));
+ }
+ if ui.button(crate::rtl::widget(ui, crate::i18n::tr(&app.ui.language, "Change All"))).clicked() {
+ let msg = match app.run("find.change", params()) {
+ Ok(v) => format!("{} replacement(s) made", v["count"]),
+ Err(e) => e,
+ };
+ d.fields.insert("status".into(), json!(msg));
+ }
+ if ui.button(crate::rtl::widget(ui, crate::i18n::tr(&app.ui.language, "Count"))).clicked() {
+ let msg = match app.run("find.find", params()) {
+ Ok(v) => format!("{} match(es)", v.as_array().map(|a| a.len()).unwrap_or(0)),
+ Err(e) => e,
+ };
+ d.fields.insert("status".into(), json!(msg));
+ }
});
+ if let Some(st) = d.fields.get("status").and_then(Value::as_str) {
+ ui.label(egui::RichText::new(st).color(crate::theme::Tokens::get(ui.ctx()).text_dim));
+ }
}
- } else {
- egui::Grid::new("nd").num_columns(4).spacing([8.0, 6.0]).show(ui, |ui| {
- crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, "Width"));
- text_field(ui, &mut d, "width", 80.0);
- crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, "Height"));
- text_field(ui, &mut d, "height", 80.0);
- ui.end_row();
- crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, "Pages"));
- text_field(ui, &mut d, "pages", 80.0);
- ui.label("");
- check(ui, &mut d, "facingPages", crate::i18n::tr(&app.ui.language, "Facing Pages"));
- ui.end_row();
- crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, "Columns"));
- text_field(ui, &mut d, "columns", 80.0);
- crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, "Gutter"));
- text_field(ui, &mut d, "gutter", 80.0);
- ui.end_row();
- crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, "Top"));
- text_field(ui, &mut d, "marginTop", 80.0);
- crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, "Bottom"));
- text_field(ui, &mut d, "marginBottom", 80.0);
- ui.end_row();
- crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, "Inside"));
- text_field(ui, &mut d, "marginInside", 80.0);
- crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, "Outside"));
- text_field(ui, &mut d, "marginOutside", 80.0);
- ui.end_row();
- crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, "Bleed"));
- text_field(ui, &mut d, "bleed", 80.0);
- ui.label("");
- check(ui, &mut d, "primaryTextFrame", crate::i18n::tr(&app.ui.language, "Primary Text Frame"));
- ui.end_row();
- });
}
- }
- "frameSize" => {
- egui::Grid::new("fs").num_columns(2).spacing([8.0, 6.0]).show(ui, |ui| {
- crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, "Width"));
- text_field(ui, &mut d, "width", 90.0);
- ui.end_row();
- crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, "Height"));
- text_field(ui, &mut d, "height", 90.0);
- ui.end_row();
- });
- }
- "findChange" => {
- ui.horizontal(|ui| {
- for (label, grep) in [("Text", false), ("GREP", true)] {
- if ui.selectable_label(!d.b("objectMode") && d.b("grep") == grep, crate::rtl::widget(ui, crate::i18n::tr(&app.ui.language, label))).clicked() {
- d.fields.insert("grep".into(), json!(grep));
- d.fields.insert("objectMode".into(), json!(false));
- }
+ "paragraphStyleOptions" => paragraph_style_options(app, ui, &mut d),
++ "deleteParagraphStyle" => delete_paragraph_style(app, ui, &mut d),
+ "characterStyleOptions" => character_style_options(app, ui, &mut d),
++ "deleteCharacterStyle" => delete_character_style(app, ui, &mut d),
+ "footnoteOptions" => footnote_options(app, ui, &mut d),
+ "paragraphRules" => {
+ let current = d.fields.get("current").cloned().unwrap_or_default();
+ paragraph_rules(app, ui, &mut d, "", &current);
+ }
+ "insertXref" => insert_xref(app, ui, &mut d),
+ "findFont" => find_font(app, ui, &mut d),
+ "colorPicker" => color_picker(ui, &mut d),
+ "preferences" => preferences(app, ui, &mut d, body_height),
+ "print" => print_dialog(app, ui, &mut d),
+ "pdfImport" => {
+ ui.label(egui::RichText::new(if d.b("async") { d.s("name") } else { d.s("path") }).size(11.0));
+ ui.horizontal(|ui| {
+ crate::rtl::label(
+ ui,
+ crate::i18n::tr(&app.ui.language, "Page (1–{count}):").replace("{count}", &d.n("pages").unwrap_or(1.0).to_string()),
+ );
+ text_field(ui, &mut d, "page", 60.0);
+ });
+ ui.horizontal(|ui| {
+ crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, "Crop to:"));
+ let cur = d.s("crop");
+ let label = |v: &str| match v {
+ "trim" => crate::i18n::tr(&app.ui.language, "Trim"),
+ "bleed" => crate::i18n::tr(&app.ui.language, "Bleed"),
+ "art" => crate::i18n::tr(&app.ui.language, "Art"),
+ "media" => crate::i18n::tr(&app.ui.language, "Media"),
+ _ => crate::i18n::tr(&app.ui.language, "Crop"),
+ };
+ egui::ComboBox::from_id_salt("pdf_crop").selected_text(crate::rtl::widget(ui, label(&cur))).show_ui(ui, |ui| {
+ for v in ["crop", "trim", "bleed", "art", "media"] {
+ if ui.selectable_label(label(&cur) == label(v), label(v)).clicked() {
+ d.fields.insert("crop".into(), json!(v));
+ }
+ }
+ });
+ });
+ }
+ "layerOptions" => {
+ let mut layers = d.fields.get("layers").and_then(Value::as_array).cloned().unwrap_or_default();
+ if layers.is_empty() {
+ crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, "This PDF has no layers."));
}
- if ui.selectable_label(d.b("objectMode"),crate::rtl::widget(ui, crate::i18n::tr(&app.ui.language, "Object"))).clicked() {
- d.fields.insert("objectMode".into(), json!(true));
+ for l in &mut layers {
+ let mut on = l["visible"].as_bool().unwrap_or(true);
+ if ui.checkbox(&mut on, l["name"].as_str().unwrap_or("")).changed() {
+ l["visible"] = json!(on);
+ }
}
- });
- if d.b("objectMode") {
- // Find/Change › Object: objects by fill and kind; change their fill or opacity.
- let swatches: Vec<String> = app.session.active().map(|st| st.doc.swatches.iter().filter(|w| !w.hidden).map(|w| w.name.clone()).collect()).unwrap_or_default();
- egui::Grid::new("fco").num_columns(2).spacing([8.0, 6.0]).show(ui, |ui| {
- for (key, label, any) in [("objFill", "Find fill:", "(any)"), ("objChangeFill", "Change fill to:", "(unchanged)")] {
+ d.fields.insert("layers".into(), json!(layers));
+ }
+ "colorSettings" => {
+ let profiles = d.fields.get("profiles").and_then(Value::as_array).cloned().unwrap_or_default();
+ egui::Grid::new("color_settings").num_columns(2).spacing([8.0, 6.0]).show(ui, |ui| {
+ for (key, label, kind) in [("rgb", "RGB:", "rgb"), ("cmyk", "CMYK:", "cmyk")] {
crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, label));
let cur = d.s(key);
- egui::ComboBox::from_id_salt(key).selected_text(if cur.is_empty() { any } else { cur.as_str() }).width(180.0).show_ui(ui, |ui| {
- if ui.selectable_label(cur.is_empty(), crate::rtl::widget(ui, crate::i18n::tr(&app.ui.language, any))).clicked() {
- d.fields.insert(key.into(), json!(""));
- }
- for w in &swatches {
- if ui.selectable_label(*w == cur, w).clicked() {
- d.fields.insert(key.into(), json!(w));
+ egui::ComboBox::from_id_salt(("ws", key)).selected_text(&cur).width(260.0).show_ui(ui, |ui| {
+ for pr in profiles.iter().filter(|p| p["kind"] == kind) {
+ let name = pr["name"].as_str().unwrap_or("");
+ if ui.selectable_label(name == cur, name).clicked() {
+ d.fields.insert(key.into(), json!(name));
}
}
});
@@@ -2742,51 -2854,7 +2874,52 @@@ fn paragraph_style_options(app: &mut De
});
}
+fn delete_paragraph_style(app: &mut DesignApp, ui: &mut egui::Ui, d: &mut Dialog) {
+ let name = d.s("name");
+ ui.set_min_width(380.0);
+ crate::rtl::label(
+ ui,
+ egui::RichText::new(
+ crate::i18n::tr(&app.ui.language, "Delete the paragraph style \"{name}\"?")
+ .replace("{name}", crate::i18n::style_name(&app.ui.language, &name)),
+ )
+ .size(12.5),
+ );
+ ui.add_space(8.0);
+ let Some(st) = app.session.active() else { return };
+ let in_use = st.doc.stories.values().any(|s| s.paras.iter().any(|f| f.style == name));
+ let names: Vec<String> = st.doc.styles.paragraph.iter().map(|p| p.name.clone()).filter(|n| *n != name).collect();
+ if in_use {
+ crate::rtl::label(
+ ui,
+ egui::RichText::new(crate::i18n::tr(&app.ui.language, "This style is in use. Text using it will be reassigned to:"))
+ .size(11.0)
+ .color(crate::theme::Tokens::get(ui.ctx()).text_dim),
+ );
+ } else {
+ crate::rtl::label(
+ ui,
+ egui::RichText::new(crate::i18n::tr(&app.ui.language, "Replace with:")).size(11.0).color(crate::theme::Tokens::get(ui.ctx()).text_dim),
+ );
+ }
+ ui.add_space(4.0);
+ if !d.fields.contains_key("replaceWith") {
+ d.fields.insert("replaceWith".into(), json!(designcraft_doc::BASIC_PARAGRAPH));
+ }
+ let replace = d.s("replaceWith");
+ egui::ComboBox::from_id_salt("del_para_replace")
+ .selected_text(crate::rtl::widget(ui, crate::i18n::style_name(&app.ui.language, &replace)))
+ .width(260.0)
+ .show_ui(ui, |ui| {
+ for n in &names {
+ if ui.selectable_label(*n == replace, crate::rtl::widget(ui, crate::i18n::style_name(&app.ui.language, n))).clicked() {
+ d.fields.insert("replaceWith".into(), json!(n));
+ }
+ }
+ });
+}
+
+ /// The section list on the left of the style options dialogs.
fn section_list(lang: &str, ui: &mut egui::Ui, d: &mut Dialog, sections: &[(&str, &str)]) {
ui.vertical(|ui| {
ui.set_width(170.0);