Skip to content

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

Paragraph Style Options: Align to Grid (None, All Lines, First Line Only) in Indents and Spacing (#1759)

aiongg7848c2122099
diff --git a/ROADMAP.md b/ROADMAP.md
index c997b9e35..caec23486 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -358,6 +358,7 @@ list) · [roadmap.md](docs/roadmap.md) (milestones, plan) · [parity-checklist.m
Newest first.
+- **2026-10-24** · Paragraph Style Options › Indents and Spacing has an Align to Grid menu: None, All Lines or First Line Only. It shows the style's current setting. A First Line Only style could be set only in the CJK Grid Settings section, which shows only with CJK features on, or through commands. No readiness percentage change.
- **2026-10-24** · Anchored text frames, such as marginal notes, compose where their host story places them: they align to the baseline grid at that position, and page-number markers and spine-relative alignment inside them read the host's page. They composed against a grid measured from their stored position and on no page, so a note set to Only Align First Line to Grid could sit a fraction of a line off the body text's grid line. No readiness percentage change.
- **2026-10-24** · New documents start with Hyphenate Capitalized Words, Hyphenate Last Word and Hyphenate Across Column off in [Basic Paragraph], as in InDesign. Opened and imported files keep the values they carry. No readiness percentage change.
- **2026-10-24** · The baseline grid's Relative To setting applies: with Top Margin, the grid starts at each page's own top margin in text composition, on the canvas and for snapping. It started at the page top, so grid-aligned text sat on the wrong lines and a page could fit one line fewer. No readiness percentage change.
diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs
index 3a1818f91..e9ad8ca60 100644
--- a/crates/ui-egui/src/dialogs.rs
+++ b/crates/ui-egui/src/dialogs.rs
@@ -3981,6 +3981,26 @@ fn paragraph_style_options(app: &mut DesignApp, ui: &mut egui::Ui, d: &mut Dialo
}
ui.end_row();
}
+ // The CJK Grid Settings section edits the same `p.gridAlign` field.
+ use designcraft_doc::GridAlign;
+ const GRID_ALIGN: [(GridAlign, &str); 3] =
+ [(GridAlign::None, "None"), (GridAlign::AllLines, "All Lines"), (GridAlign::FirstLineOnly, "First Line Only")];
+ crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, "Align to Grid:"));
+ let g: GridAlign = serde_json::from_value(cur(d, "p.gridAlign", &pv["gridAlign"])).unwrap_or_default();
+ let shown = GRID_ALIGN.iter().find(|o| o.0 == g).map_or("", |o| o.1);
+ egui::ComboBox::from_id_salt("psgridalign")
+ .selected_text(crate::rtl::widget(ui, crate::i18n::tr(&app.ui.language, shown)))
+ .width(240.0)
+ .show_ui(ui, |ui| {
+ for (v, label) in GRID_ALIGN {
+ if ui.selectable_label(v == g, crate::rtl::widget(ui, crate::i18n::tr(&app.ui.language, label))).clicked()
+ && let Ok(v) = serde_json::to_value(v)
+ {
+ d.fields.insert("p.gridAlign".into(), v);
+ }
+ }
+ });
+ ui.end_row();
});
}
"tabs" => style_tabs(&app.ui.language, ui, d, &pv, &doc),
@@ -9658,6 +9678,31 @@ mod tests {
assert_eq!(st.doc.styles.para(&name).unwrap().para.align, Some(designcraft_doc::Align::Center));
}
+ #[test]
+ fn paragraph_style_options_align_to_grid_shows_and_sets_the_style_grid_alignment() {
+ use designcraft_doc::GridAlign;
+ use egui_kittest::kittest::Queryable;
+ let mut app = test_app();
+ app.session.execute("style.paragraph.create", &json!({"name": "Grid Body", "para": {"gridAlign": "firstLineOnly"}})).unwrap();
+ app.ui.dialog = Some(Dialog::new("paragraphStyleOptions", json!({"name": "Grid Body", "section": "indents"})));
+ let mut h = crate::test_window::open(app, egui::vec2(1400.0, 900.0));
+ let grid = |h: &egui_kittest::Harness<'static, crate::test_window::Window>| {
+ h.state().app.session.active().unwrap().doc.styles.para("Grid Body").unwrap().para.grid_align
+ };
+ h.run_steps(4);
+ h.get_by_value("First Line Only");
+ confirm(&mut h.state_mut().app).unwrap();
+ assert_eq!(grid(&h), Some(GridAlign::FirstLineOnly), "OK without edits keeps the style's alignment");
+ h.state_mut().app.ui.dialog = Some(Dialog::new("paragraphStyleOptions", json!({"name": "Grid Body", "section": "indents"})));
+ h.run_steps(4);
+ h.get_by_value("First Line Only").click();
+ h.run_steps(3);
+ h.get_by_label("All Lines").click();
+ h.run_steps(3);
+ confirm(&mut h.state_mut().app).unwrap();
+ assert_eq!(grid(&h), Some(GridAlign::AllLines));
+ }
+
#[test]
fn delete_paragraph_style_dialog_removes_the_style_and_reassigns_text() {
let mut app = test_app();