Skip to content

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

Merge branch 'list-buttons-hanging-indent' into control-panel-lists-shading

moppeeera41ff9c6090d
diff --cc crates/ui-egui/src/panels/properties.rs
index 3e68ead70,f3d31c584..c1f2f23a1
--- a/crates/ui-egui/src/panels/properties.rs
+++ b/crates/ui-egui/src/panels/properties.rs
@@@ -1479,66 -1361,19 +1479,69 @@@ fn paragraph_section(app: &mut DesignAp
}
}
+/// Properties › Paragraph after •••: left and right indent, first line and last line indent,
+/// space before and after, drop cap lines and characters, then Hyphenate and Align to Baseline
+/// Grid, as InDesign lays them out.
+fn paragraph_more(app: &mut DesignApp, ui: &mut Ui, p: &Value, fw: f32) {
+ let lang_ui = app.ui.language.clone();
+ let tr = |s: &str| crate::i18n::tr(&lang_ui, s).to_string();
+ let u = units(app);
+ let half = (fw - 10.0) / 2.0;
+ ui.add_space(4.0);
+ let b = block(ui, 4.0 * FIELD_H + 15.0);
+ let rows = [
+ (("indent-left", "Left Indent", "leftIndent"), ("indent-right", "Right Indent", "rightIndent")),
+ (("indent-first", "First Line Left Indent", "firstLineIndent"), ("indent-last", "Last Line Right Indent", "lastLineIndent")),
+ (("space-before", "Space Before", "spaceBefore"), ("space-after", "Space After", "spaceAfter")),
+ ];
+ for (i, (l, r)) in rows.into_iter().enumerate() {
+ let y = i as f32 * (FIELD_H + 5.0);
+ for (right, (icon, tip, key)) in [(false, l), (true, r)] {
+ let min = if key == "firstLineIndent" { -10_000.0 } else { 0.0 };
+ let field = NumField::measure(key, p[key].as_f64(), u).spinner().range(min, 10_000.0);
+ if let Some(v) = half_field(ui, b, right, y, half, icon, &tr(tip), field) {
+ let _ = app.run("type.para", json!({"attrs": {key: v}}));
+ }
+ }
+ }
+ let y = 3.0 * (FIELD_H + 5.0);
+ for (right, icon, tip, key, max) in [
+ (false, "drop-lines", "Drop Cap Number of Lines", "dropCapLines", designcraft_compose::MAX_DROP_CAP_LINES),
+ (true, "drop-chars", "Drop Cap One or More Characters", "dropCapChars", designcraft_compose::MAX_DROP_CAP_CHARS),
+ ] {
+ let field = NumField::number(key, p[key].as_f64(), "", 0).spinner().range(0.0, max as f64);
+ if let Some(v) = half_field(ui, b, right, y, half, icon, &tr(tip), field) {
+ let _ = app.run("type.para", json!({"attrs": {key: (v.max(0.0) as u64).min(max as u64)}}));
+ }
+ }
+ ui.add_space(4.0);
+ ui.horizontal(|ui| {
+ let grid = p["gridAlign"].as_str() == Some("allLines");
+ if widgets::icon_toggle(ui, "grid-baseline", grid, &tr("Align to Baseline Grid")).clicked() {
+ let _ = app.run("type.para", json!({"attrs": {"gridAlign": if grid { "none" } else { "allLines" }}}));
+ }
+ ui.add_space(12.0);
+ let mut h = p["hyphenate"].as_bool().unwrap_or(true);
+ if widgets::checkbox(ui, &mut h, &tr("Hyphenate")).changed() {
+ let _ = app.run("type.para", json!({"attrs": {"hyphenate": h}}));
+ }
+ });
+ ui.add_space(4.0);
+}
+
fn bullets_section(app: &mut DesignApp, ui: &mut Ui) {
- let Some(a) = text_attrs(app) else { return };
- let lt = a["para"]["listType"].as_str().unwrap_or("none").to_string();
+ if text_attrs(app).is_none() {
+ return;
+ }
ui.horizontal(|ui| {
ui.spacing_mut().item_spacing.x = 10.0;
- // As InDesign's: a list with the default hanging indent, or (pressed) no list.
+ // As InDesign's: a list with the default hanging indent, or (pressed: every selected
+ // paragraph has it, as Type › Apply Bullets shows) no list.
+ use designcraft_doc::ListType;
for (icon, kind, cmd, tip) in
- [("bullets", "bullets", "list.bullets", "Bulleted List"), ("numbering", "numbers", "list.numbers", "Numbered List")]
+ [("bullets", ListType::Bullets, "list.bullets", "Bulleted List"), ("numbering", ListType::Numbers, "list.numbers", "Numbered List")]
{
- let on = lt == kind;
+ let on = app.session.selection_has_list(kind);
if icon_toggle(ui, icon, on, crate::i18n::tr(&app.ui.language, tip)).clicked() {
let _ = app.run(cmd, json!({"on": !on}));
}