From c441d3a81a263b7c0eca90b3baf0e9e92717630f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Fri, 27 Nov 2026 07:24:16 -0500 Subject: [PATCH 01/12] feat(ui): the Publication Layout Wizard asks for sources, reference, headings and layer figures (#3109) --- .../engine/src/cmd/layout/publication/mod.rs | 7 +- .../src/cmd/layout/publication/sheet.rs | 9 + .../ui-egui/src/publicationwizard/accent.rs | 5 + crates/ui-egui/src/publicationwizard/mod.rs | 172 ++++++++++- .../ui-egui/src/publicationwizard/review.rs | 20 +- .../ui-egui/src/publicationwizard/sources.rs | 291 ++++++++++++++++++ crates/ui-egui/src/publicationwizard/texts.rs | 58 ++-- crates/ui-egui/src/textform.rs | 83 +++-- docs/user-guide/layouts.md | 15 +- 9 files changed, 581 insertions(+), 79 deletions(-) create mode 100644 crates/ui-egui/src/publicationwizard/sources.rs diff --git a/crates/engine/src/cmd/layout/publication/mod.rs b/crates/engine/src/cmd/layout/publication/mod.rs index fdd5fd6d22..b27819dfe7 100644 --- a/crates/engine/src/cmd/layout/publication/mod.rs +++ b/crates/engine/src/cmd/layout/publication/mod.rs @@ -183,8 +183,9 @@ pub(in crate::cmd::layout) fn publication(s: &mut Session, p: &Value) -> CmdResu let room_side = if labelled.left || labelled.right { LABEL_ROOM_SIDE * strip_scale } else { 0.0 }; let room_end = if labelled.top || labelled.bottom { LABEL_ROOM_END * strip_scale } else { 0.0 }; let reference = reference.unwrap_or_else(|| { - let line = if step.is_some() { "Datum: {datum} · Graticule: {grid}" } else { "Datum: {datum}" }; - vec!["Projection: {projection}".into(), line.into()] + let [projection, datum_and_grid] = PUBLICATION_DEFAULT_REFERENCE; + let line = if step.is_some() { datum_and_grid } else { "Datum: {datum}" }; + vec![projection.into(), line.into()] }); let step_said = step.map_or_else(|| "—".to_string(), step_text); let fill = |t: &str| t.replace("{projection}", &projection).replace("{datum}", &datum).replace("{grid}", &step_said); @@ -266,7 +267,7 @@ pub(in crate::cmd::layout) fn publication(s: &mut Session, p: &Value) -> CmdResu // lines in `body_pt`, `tw` wide. Each one's elements keep their names (`Sources`, `Reference`) // whatever its heading reads, the heading filled and wrapped like the rest. let sections = |tw: f64, head_pt: f64, body_pt: f64| -> Vec<(&'static str, Broken, Broken)> { - [("Sources", heading(0, "Sources"), &sources), ("Reference", heading(1, "Cartographic reference"), &reference)] + [("Sources", heading(0, PUBLICATION_HEADINGS[0]), &sources), ("Reference", heading(1, PUBLICATION_HEADINGS[1]), &reference)] .into_iter() .filter(|(.., texts)| !texts.is_empty()) .map(|(name, head, texts)| { diff --git a/crates/engine/src/cmd/layout/publication/sheet.rs b/crates/engine/src/cmd/layout/publication/sheet.rs index 72c54fa173..77556fd14a 100644 --- a/crates/engine/src/cmd/layout/publication/sheet.rs +++ b/crates/engine/src/cmd/layout/publication/sheet.rs @@ -58,6 +58,15 @@ pub const PUBLICATION_STYLES: &[(&str, &str)] = &[ /// with today's date when the layout is drawn). pub const PUBLICATION_DEFAULT_CREDIT: &str = "Made with RustGIS · {date}"; +/// The headings of a publication's sources and cartographic reference when `"headings"` doesn't +/// give them. +pub const PUBLICATION_HEADINGS: [&str; 2] = ["Sources", "Cartographic reference"]; + +/// The cartographic reference's lines when `"reference"` isn't given (`{projection}`, `{datum}` +/// and `{grid}` are filled with the sheet's; without a graticule the second names the datum +/// alone). +pub const PUBLICATION_DEFAULT_REFERENCE: [&str; 2] = ["Projection: {projection}", "Datum: {datum} · Graticule: {grid}"]; + /// The longest text a publication layout takes in one field, in characters. pub const MAX_PUBLICATION_TEXT: usize = 2000; diff --git a/crates/ui-egui/src/publicationwizard/accent.rs b/crates/ui-egui/src/publicationwizard/accent.rs index adf71bd024..10bb5c2b01 100644 --- a/crates/ui-egui/src/publicationwizard/accent.rs +++ b/crates/ui-egui/src/publicationwizard/accent.rs @@ -112,21 +112,25 @@ mod tests { // Go back to Style while still ticked and switch to Poster: accent follows Poster. click(&mut h, "Back"); click(&mut h, "Back"); + click(&mut h, "Back"); h.get_by_label("Poster").click(); h.run_steps(2); assert_eq!(h.state().dialogs.publication.as_ref().unwrap().accent, Some(poster), "re-seeded to Poster"); // Unticking on Poster must not remember Banner's or Poster's default as a custom colour. click(&mut h, "Next"); click(&mut h, "Next"); + click(&mut h, "Next"); h.get_by_label("Pick a colour of your own").click(); h.run_steps(2); assert_eq!(h.state().dialogs.publication.as_ref().unwrap().accent, None); click(&mut h, "Back"); click(&mut h, "Back"); + click(&mut h, "Back"); h.get_by_label("Editorial").click(); h.run_steps(2); click(&mut h, "Next"); click(&mut h, "Next"); + click(&mut h, "Next"); h.get_by_label("Pick a colour of your own").click(); h.run_steps(2); assert_eq!(h.state().dialogs.publication.as_ref().unwrap().accent, Some(editorial), "starts from Editorial"); @@ -135,6 +139,7 @@ mod tests { h.state_mut().dialogs.publication.as_mut().unwrap().accent = Some(red); click(&mut h, "Back"); click(&mut h, "Back"); + click(&mut h, "Back"); h.get_by_label("Banner").click(); h.run_steps(2); assert_eq!(h.state().dialogs.publication.as_ref().unwrap().accent, Some(red), "custom colour kept"); diff --git a/crates/ui-egui/src/publicationwizard/mod.rs b/crates/ui-egui/src/publicationwizard/mod.rs index 3d8a806404..d12da2c029 100644 --- a/crates/ui-egui/src/publicationwizard/mod.rs +++ b/crates/ui-egui/src/publicationwizard/mod.rs @@ -1,19 +1,26 @@ -//! Publication Layout Wizard: `layout.publication` asked step by step (size, style, texts, accent), -//! then made at once, as the New Layout › Publication Layout menu makes it (#2850). +//! Publication Layout Wizard: `layout.publication` asked step by step (size, style, texts, sources +//! and reference, accent), then made at once, as the New Layout › Publication Layout menu makes it +//! (#2850). mod accent; mod review; mod size; +mod sources; mod style; mod texts; +use crate::textform::StatLayer; use crate::{RustGisApp, i18n, theme::Tokens}; use accent::accent_step; use review::review_step; use rustgis_engine::Session; -use rustgis_engine::cmd::layout::{PUBLICATION_PROFILES, publication_style_accent}; +use rustgis_engine::cmd::layout::{ + MAX_PUBLICATION_TEXT, PUBLICATION_DEFAULT_REFERENCE, PUBLICATION_HEADINGS, PUBLICATION_PROFILES, publication_style_accent, +}; +use rustgis_engine::map::Map; use rustgis_engine::map::layout::PAGES; use serde_json::{Value, json}; use size::size_step; +use sources::sources_step; use style::style_step; use texts::texts_step; @@ -23,10 +30,33 @@ pub enum Step { Size, Style, Texts, + Sources, Accent, Review, } +/// A text field of the wizard that takes a layer statistic. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +enum Field { + Title, + Subtitle, + Note, + Sources, + Author, + Reference, + Heading(usize), +} + +impl Field { + /// The step that asks for it. + fn step(self) -> Step { + match self { + Field::Title | Field::Subtitle | Field::Note | Field::Author | Field::Heading(2) => Step::Texts, + Field::Sources | Field::Reference | Field::Heading(_) => Step::Sources, + } + } +} + /// How a sheet is turned: `Auto` leaves it to `layout.publication` (the way the map comes out larger). #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum Orientation { @@ -51,6 +81,17 @@ pub struct Draft { pub author: String, /// No credit line at all (`"author": ""`), rather than the command's default one. pub no_author: bool, + /// The cartographic reference's lines; empty leaves the command's default. + pub reference: String, + /// No cartographic reference at all (`"reference": []`). + pub no_reference: bool, + /// The headings of the sources, the reference and an editorial sheet's column; one left empty + /// is left to the command. + pub headings: [String; 3], + /// The text field last edited, which a layer statistic is added to. + target: Option, + /// The field the last statistic didn't fit in, said until its step's text changes. + refused: Option, /// The style's colour, or `None` for the style's own. pub accent: Option, /// The colour last picked, which the swatch comes back with when the box is ticked again. @@ -74,6 +115,11 @@ impl Draft { sources: String::new(), author: String::new(), no_author: false, + reference: String::new(), + no_reference: false, + headings: Default::default(), + target: None, + refused: None, accent: None, picked: None, } @@ -94,7 +140,10 @@ impl Draft { /// The steps this draft goes through, in order. fn steps(&self) -> &'static [Step] { - if self.figure() { &[Step::Size, Step::Review] } else { &[Step::Size, Step::Style, Step::Texts, Step::Accent, Step::Review] } + if self.figure() { + return &[Step::Size, Step::Review]; + } + &[Step::Size, Step::Style, Step::Texts, Step::Sources, Step::Accent, Step::Review] } /// The step `by` places from this one, if there is one. @@ -118,7 +167,7 @@ impl Draft { } p["style"] = json!(self.style); p["title"] = json!(self.title.trim()); - for (key, text) in [("subtitle", &self.subtitle), ("note", &self.note), ("sources", &self.sources), ("author", &self.author)] { + for (key, text) in [("subtitle", &self.subtitle), ("note", &self.note), ("author", &self.author)] { if !text.trim().is_empty() { p[key] = json!(text.trim()); } @@ -126,11 +175,108 @@ impl Draft { if self.no_author { p["author"] = json!(""); } + let sources = lines(&self.sources); + if !sources.is_empty() { + p["sources"] = json!(sources); + } + let reference = lines(&self.reference); + if self.no_reference || !reference.is_empty() { + p["reference"] = json!(if self.no_reference { Vec::new() } else { reference }); + } + let headings = self.headings_sent(); + if !headings.is_empty() { + p["headings"] = json!(headings); + } if let Some(c) = self.accent { p["accent"] = json!(hex(c)); } p } + + /// `"headings"` up to the last one given, a gap before it filled with the command's own; the + /// column's only on an editorial sheet, the one style that draws it. + fn headings_sent(&self) -> Vec<&str> { + let given = |i: usize| (i < 2 || self.editorial()) && !self.headings[i].trim().is_empty(); + let Some(last) = (0..self.headings.len()).rev().find(|&i| given(i)) else { return Vec::new() }; + (0..=last) + .map(|i| if given(i) { self.headings[i].trim() } else { PUBLICATION_HEADINGS.get(i).copied().unwrap_or_default() }) + .collect() + } + + fn editorial(&self) -> bool { + self.style == "editorial" + } + + fn field_mut(&mut self, field: Field) -> &mut String { + let [sources, reference, column] = &mut self.headings; + match field { + Field::Title => &mut self.title, + Field::Subtitle => &mut self.subtitle, + Field::Note => &mut self.note, + Field::Sources => &mut self.sources, + Field::Author => &mut self.author, + Field::Reference => &mut self.reference, + Field::Heading(0) => sources, + Field::Heading(1) => reference, + Field::Heading(_) => column, + } + } + + /// Notes `field` as the one last edited while it has the focus. + fn edited(&mut self, r: &egui::Response, field: Field) { + if r.has_focus() { + self.target = Some(field); + } + if r.changed() { + self.refused = None; + } + } + + /// Adds a layer statistic to the field last edited on `own`'s step, or to `own` where none was + /// or that one is off now; one that would take the field past the limit isn't added. + fn add_statistic(&mut self, token: &str, own: Field) { + let on = |f: Field| match f { + Field::Author => !self.no_author, + Field::Reference | Field::Heading(1) => !self.no_reference, + Field::Heading(2) => self.editorial(), + _ => true, + }; + let field = self.target.filter(|&f| f.step() == own.step() && on(f)).unwrap_or(own); + let text = self.field_mut(field); + if text.chars().count() + token.chars().count() > MAX_PUBLICATION_TEXT { + self.refused = Some(field); + return; + } + text.push_str(token); + self.refused = None; + self.title_typed |= field == Field::Title; + } +} + +/// A box's lines as the command takes a list: trimmed, the empty ones left out. +fn lines(text: &str) -> Vec<&str> { + text.lines().map(str::trim).filter(|l| !l.is_empty()).collect() +} + +/// The menu that adds a layer figure of the active map (the one the sheet shows), listed as the +/// Format pane's Dynamic Text menu lists them; none where the map has no layer to read. +fn statistic_menu(ui: &mut egui::Ui, d: &mut Draft, map: &Map, own: Field) { + if !StatLayer::any(map) { + return; + } + ui.menu_button(tl!("Insert Statistic"), |ui| { + crate::textform::stat_layers(ui, &StatLayer::of_map(map), &mut |token| d.add_statistic(&token, own)); + }); +} + +/// The boxes take no more, cut a longer paste to fit and refuse a statistic past it: said, not +/// done unseen. +fn limit_note(ui: &mut egui::Ui, d: &mut Draft, fields: &[Field]) { + let refused = d.refused.is_some_and(|f| f.step() == d.step); + if refused || fields.iter().any(|&f| d.field_mut(f).chars().count() >= MAX_PUBLICATION_TEXT) { + let note = i18n::fmt("Each field takes at most {limit} characters.", &[("limit", &MAX_PUBLICATION_TEXT.to_string())]); + ui.label(egui::RichText::new(note).small().weak()); + } } /// A colour as `layout.publication` takes it: `#RRGGBB`. @@ -153,6 +299,7 @@ fn step_name(step: Step) -> &'static str { Step::Size => tl_raw!("Size"), Step::Style => tl_raw!("Style"), Step::Texts => tl_raw!("Texts"), + Step::Sources => tl_raw!("Sources and reference"), Step::Accent => tl_raw!("Accent"), Step::Review => tl_raw!("Review"), } @@ -239,7 +386,8 @@ pub fn show(app: &mut RustGisApp, ctx: &egui::Context) { .show(ui, |ui| match d.step { Step::Size => size_step(ui, &mut d), Step::Style => style_step(ui, &mut d, t.accent), - Step::Texts => texts_step(ui, &mut d), + Step::Texts => texts_step(ui, &mut d, app.session.map()), + Step::Sources => sources_step(ui, &mut d, app.session.map()), Step::Accent => accent_step(ui, &mut d, t.accent), Step::Review => review_step(ui, &d), }); @@ -374,7 +522,7 @@ mod tests { assert_eq!( d.params(), json!({"profile": "letter-landscape", "style": "panel", "title": "", "subtitle": "2026", "note": "A note", - "sources": "Natural Earth", "author": "J. G.", "accent": "#0B1B2B"}) + "sources": ["Natural Earth"], "author": "J. G.", "accent": "#0B1B2B"}) ); d.orientation = Orientation::Portrait; d.no_author = true; @@ -385,7 +533,7 @@ mod tests { assert_eq!(d.params(), json!({"profile": "figure-1col"})); } - /// A sheet goes through the five steps; a figure goes from its size to the review, the steps + /// A sheet goes through the six steps; a figure goes from its size to the review, the steps /// it takes nothing from skipped both ways. Back is off on the first step; Next becomes /// Create on the last. #[test] @@ -394,13 +542,13 @@ mod tests { open(&mut app); let mut h = harness(app); assert!(h.get_by_role_and_label(Role::Button, "Back").accesskit_node().is_disabled(), "Back is off"); - for want in [Step::Style, Step::Texts, Step::Accent, Step::Review] { + for want in [Step::Style, Step::Texts, Step::Sources, Step::Accent, Step::Review] { click(&mut h, "Next"); assert_eq!(step(&h), want); } assert!(h.query_by_role_and_label(Role::Button, "Next").is_none()); assert!(h.query_by_role_and_label(Role::Button, "Create").is_some()); - for want in [Step::Accent, Step::Texts, Step::Style, Step::Size] { + for want in [Step::Accent, Step::Sources, Step::Texts, Step::Style, Step::Size] { click(&mut h, "Back"); assert_eq!(step(&h), want); } @@ -472,7 +620,7 @@ mod tests { let mut h = harness(app); let at = |h: &egui_kittest::Harness<'static, RustGisApp>| h.get_by_role_and_label(Role::Button, "Next").rect(); let first = at(&h); - for _ in 0..3 { + for _ in 0..4 { click(&mut h, "Next"); assert_eq!(at(&h), first, "{:?}", step(&h)); } @@ -493,7 +641,7 @@ mod tests { assert_ne!(next, "Next", "{code}: the language changed"); let at = |h: &egui_kittest::Harness<'static, RustGisApp>| h.get_by_role_and_label(Role::Button, &next).rect(); let first = at(&h); - for _ in 0..3 { + for _ in 0..4 { h.get_by_role_and_label(Role::Button, &next).click(); h.run_steps(4); assert_eq!(at(&h), first, "{code}: {:?}", step(&h)); diff --git a/crates/ui-egui/src/publicationwizard/review.rs b/crates/ui-egui/src/publicationwizard/review.rs index 5c9b4c75f2..2e7d02da25 100644 --- a/crates/ui-egui/src/publicationwizard/review.rs +++ b/crates/ui-egui/src/publicationwizard/review.rs @@ -26,7 +26,25 @@ pub(super) fn review_step(ui: &mut egui::Ui, d: &Draft) { row(tl!("Title"), or_none(&d.title)); row(tl!("Subtitle"), or_none(&d.subtitle)); row(tl!("Note"), or_none(&d.note)); - row(tl!("Sources"), or_none(&d.sources)); + let sources = lines(&d.sources).join("\n"); + row(tl!("Sources"), or_none(&sources)); + let heading = |i: usize, or: &str| { + let given = d.headings[i].trim(); + if given.is_empty() { or.to_string() } else { given.to_string() } + }; + if !sources.is_empty() { + row(tl!("Sources heading"), heading(0, PUBLICATION_HEADINGS[0])); + } + let typed = lines(&d.reference).join("\n"); + if d.no_reference { + row(tl!("Reference"), none.to_string()); + } else { + row(tl!("Reference"), if typed.is_empty() { PUBLICATION_DEFAULT_REFERENCE.join("\n") } else { typed }); + row(tl!("Reference heading"), heading(1, PUBLICATION_HEADINGS[1])); + } + if d.editorial() { + row(tl!("Column heading"), heading(2, none)); + } let credit = if d.no_author { none.to_string() } else if d.author.trim().is_empty() { diff --git a/crates/ui-egui/src/publicationwizard/sources.rs b/crates/ui-egui/src/publicationwizard/sources.rs new file mode 100644 index 0000000000..c5dcf00ee0 --- /dev/null +++ b/crates/ui-egui/src/publicationwizard/sources.rs @@ -0,0 +1,291 @@ +//! The wizard's sources and reference step. +use super::*; + +/// The most lines `layout.publication` takes in a list. +const MAX_LINES: usize = 50; + +/// The sources step: the sources, the cartographic reference and their headings. +pub(super) fn sources_step(ui: &mut egui::Ui, d: &mut Draft, map: &Map) { + egui::Grid::new("publication_wizard_sources").num_columns(2).spacing(egui::vec2(8.0, 8.0)).show(ui, |ui| { + list(ui, d, tl!("Sources"), Field::Sources, "", 3, true); + heading(ui, d, tl!("Sources heading"), 0, true); + let on = !d.no_reference; + list(ui, d, tl!("Reference"), Field::Reference, &PUBLICATION_DEFAULT_REFERENCE.join("\n"), 2, on); + ui.label(""); + ui.checkbox(&mut d.no_reference, tl!("No cartographic reference")); + ui.end_row(); + heading(ui, d, tl!("Reference heading"), 1, !d.no_reference); + }); + statistic_menu(ui, d, map, Field::Sources); + let mut fields = vec![Field::Sources, Field::Heading(0)]; + if !d.no_reference { + fields.extend([Field::Reference, Field::Heading(1)]); + } + limit_note(ui, d, &fields); +} + +/// A box taking one entry per line, with a note where it holds more than the command takes. +fn list(ui: &mut egui::Ui, d: &mut Draft, label: &str, field: Field, hint: &str, rows: usize, on: bool) { + let caption = ui.label(label); + let edit = egui::TextEdit::multiline(d.field_mut(field)) + .hint_text(hint) + .desired_rows(rows) + .char_limit(MAX_PUBLICATION_TEXT) + .desired_width(field_width(ui)); + let r = ui.add_enabled(on, edit).labelled_by(caption.id); + d.edited(&r, field); + ui.end_row(); + if on && lines(d.field_mut(field)).len() > MAX_LINES { + ui.label(""); + let note = i18n::fmt("At most {limit} lines.", &[("limit", &MAX_LINES.to_string())]); + ui.label(egui::RichText::new(note).small().weak()); + ui.end_row(); + } +} + +/// A section's heading, the command's own as its hint. +fn heading(ui: &mut egui::Ui, d: &mut Draft, label: &str, at: usize, on: bool) { + let field = Field::Heading(at); + let caption = ui.label(label); + let edit = egui::TextEdit::singleline(d.field_mut(field)) + .hint_text(PUBLICATION_HEADINGS.get(at).copied().unwrap_or_default()) + .char_limit(MAX_PUBLICATION_TEXT) + .desired_width(field_width(ui)); + let r = ui.add_enabled(on, edit).labelled_by(caption.id); + d.edited(&r, field); + ui.end_row(); +} + +#[cfg(test)] +mod tests { + use super::harness::*; + use super::*; + use egui::accesskit::Role; + use egui_kittest::kittest::{NodeT, Queryable}; + use rustgis_engine::map::layout::ElementKind; + + type Wizard = egui_kittest::Harness<'static, RustGisApp>; + + fn draft() -> Draft { + Draft::new(&app().session) + } + + /// The wizard on `step`, over the sample project (its map has vector layers). + fn at(step: Step, set: impl FnOnce(&mut Draft)) -> Wizard { + let mut app = app(); + open(&mut app); + let d = app.dialogs.publication.as_mut().unwrap(); + d.step = step; + set(d); + harness(app) + } + + fn wizard(h: &Wizard) -> &Draft { + h.state().dialogs.publication.as_ref().expect("the wizard is open") + } + + /// The first vector layer of the active map, which the statistic menu lists. + fn layer(h: &Wizard) -> String { + crate::textform::StatLayer::of_map(h.state().session.map()).first().expect("a vector layer").name.clone() + } + + /// Insert Statistic › the first layer › Count. + fn insert_count(h: &mut Wizard) -> String { + let name = layer(h); + let token = format!("{{count:{name}}}"); + for label in ["Insert Statistic", &name, &format!("Count {token}")] { + h.get_by_label(label).click(); + h.run_steps(4); + } + token + } + + /// Sources go one per line, trimmed, the empty lines left out; none at all sends no key. + #[test] + fn sources_are_sent_one_per_line() { + let mut d = draft(); + d.sources = "A\n\n B \n".into(); + assert_eq!(d.params()["sources"], json!(["A", "B"])); + d.sources = " \n ".into(); + assert!(d.params().get("sources").is_none()); + } + + /// An empty reference is left to the command, one typed goes line by line, and none at all is + /// an empty list. + #[test] + fn the_reference_is_the_commands_lines_or_none() { + let mut d = draft(); + assert!(d.params().get("reference").is_none()); + d.reference = "X\nY".into(); + assert_eq!(d.params()["reference"], json!(["X", "Y"])); + d.no_reference = true; + assert_eq!(d.params()["reference"], json!([])); + } + + /// Headings are sent up to the last one given, a gap filled with the command's own; the + /// column's only for the editorial style. + #[test] + fn headings_are_sent_up_to_the_last_one_given() { + let mut d = draft(); + assert!(d.params().get("headings").is_none()); + d.headings[0] = " S ".into(); + assert_eq!(d.params()["headings"], json!(["S"])); + d.headings = [String::new(), "Ref".into(), String::new()]; + assert_eq!(d.params()["headings"], json!([PUBLICATION_HEADINGS[0], "Ref"])); + d.headings = [String::new(), String::new(), "Col".into()]; + assert!(d.params().get("headings").is_none(), "no column on a classic sheet"); + d.style = "editorial".into(); + assert_eq!(d.params()["headings"], json!([PUBLICATION_HEADINGS[0], PUBLICATION_HEADINGS[1], "Col"])); + } + + /// A figure takes none of them. + #[test] + fn a_figure_takes_no_sources_reference_or_headings() { + let mut d = draft(); + (d.sources, d.reference, d.no_reference) = ("A".into(), "B".into(), true); + d.headings[0] = "S".into(); + d.size = "figure-1col".into(); + assert_eq!(d.params(), json!({"profile": "figure-1col"})); + } + + /// The wizard's literals for the command's defaults are the engine's. + #[test] + fn the_defaults_shown_match_the_engines() { + assert_eq!(PUBLICATION_HEADINGS, ["Sources", "Cartographic reference"]); + assert_eq!(PUBLICATION_DEFAULT_REFERENCE, ["Projection: {projection}", "Datum: {datum} · Graticule: {grid}"]); + } + + /// The step has its fields, and No cartographic reference turns the reference's box off. + #[test] + fn the_step_asks_for_the_sources_the_reference_and_their_headings() { + let mut h = at(Step::Sources, |_| {}); + for label in ["Sources", "Sources heading", "Reference", "Reference heading"] { + assert!(h.query_by_label(label).is_some(), "{label}"); + } + assert!(!h.get_by_label("Reference").accesskit_node().is_disabled()); + h.get_by_role_and_label(Role::CheckBox, "No cartographic reference").click(); + h.run_steps(4); + assert!(wizard(&h).no_reference); + assert!(h.get_by_label("Reference").accesskit_node().is_disabled()); + } + + /// The column's heading is asked with the texts, for the editorial style alone. + #[test] + fn only_an_editorial_sheet_is_asked_its_columns_heading() { + let mut h = at(Step::Texts, |_| {}); + assert!(h.query_by_label("Column heading").is_none()); + h.state_mut().dialogs.publication.as_mut().unwrap().style = "editorial".into(); + h.run_steps(4); + assert!(h.query_by_label("Column heading").is_some()); + } + + /// A statistic goes to the field last edited, here the subtitle. + #[test] + fn a_statistic_goes_to_the_field_last_edited() { + let mut h = at(Step::Texts, |d| d.subtitle = "In ".into()); + h.get_by_label("Subtitle").focus(); + h.run_steps(2); + let token = insert_count(&mut h); + assert_eq!(wizard(&h).subtitle, format!("In {token}")); + assert!(wizard(&h).note.is_empty()); + } + + /// With nothing edited on the step it goes to the note, or to the sources on their step, a + /// field edited on another step left alone. + #[test] + fn with_no_field_edited_a_statistic_goes_to_the_steps_own() { + let mut h = at(Step::Texts, |_| {}); + let token = insert_count(&mut h); + assert_eq!(wizard(&h).note, token); + let mut h = at(Step::Sources, |d| d.target = Some(Field::Subtitle)); + let token = insert_count(&mut h); + assert_eq!(wizard(&h).sources, token); + assert!(wizard(&h).subtitle.is_empty()); + } + + /// A statistic put in the title is a title typed: a map opened afterwards doesn't replace it. + #[test] + fn a_statistic_in_the_title_keeps_the_title() { + let mut h = at(Step::Texts, |d| d.target = Some(Field::Title)); + insert_count(&mut h); + assert!(wizard(&h).title_typed); + } + + /// A statistic that would take its field past the limit isn't added, and that is said. + #[test] + fn a_statistic_past_the_limit_isnt_added_and_its_said() { + let full = "x".repeat(MAX_PUBLICATION_TEXT - 3); + // A one-line field: a box this full of text would push the menu out of the step's view. + let mut h = at(Step::Sources, |d| (d.headings[0], d.target) = (full.clone(), Some(Field::Heading(0)))); + let limit = format!("Each field takes at most {MAX_PUBLICATION_TEXT} characters."); + assert!(h.query_by_label(&limit).is_none()); + insert_count(&mut h); + assert_eq!(wizard(&h).headings[0], full); + assert!(wizard(&h).sources.is_empty()); + assert!(h.query_by_label(&limit).is_some()); + } + + /// A map with no vector layers has no statistic menu. + #[test] + fn a_map_without_vector_layers_has_no_statistic_menu() { + for step in [Step::Texts, Step::Sources] { + let mut h = at(step, |_| {}); + assert!(h.query_by_label("Insert Statistic").is_some(), "{step:?}"); + h.state_mut().run("map.new", json!({"name": "Empty"})).unwrap(); + h.run_steps(4); + assert!(h.query_by_label("Insert Statistic").is_none(), "{step:?}"); + } + } + + /// More than the command's 50 lines is said under the box. + #[test] + fn more_than_fifty_lines_are_said() { + let said = "At most 50 lines."; + let mut h = at(Step::Sources, |d| d.sources = "a\n".repeat(50)); + assert!(h.query_by_label(said).is_none()); + h.state_mut().dialogs.publication.as_mut().unwrap().reference = "a\n".repeat(51); + h.run_steps(4); + assert!(h.query_by_label(said).is_some()); + } + + /// The review lists the sources, the reference and the headings, the defaults where nothing + /// was typed and "(none)" for no reference. + #[test] + fn the_review_lists_sources_reference_and_headings() { + let mut h = at(Step::Review, |d| d.sources = "IBGE\nANA".into()); + assert!(h.query_by_label("IBGE\nANA").is_some()); + assert!(h.query_by_label(&PUBLICATION_DEFAULT_REFERENCE.join("\n")).is_some()); + assert!(h.query_by_label(PUBLICATION_HEADINGS[1]).is_some()); + let d = h.state_mut().dialogs.publication.as_mut().unwrap(); + d.no_reference = true; + d.style = "editorial".into(); + d.headings = ["Fontes".into(), String::new(), "About".into()]; + h.run_steps(4); + assert!(h.query_by_label(&PUBLICATION_DEFAULT_REFERENCE.join("\n")).is_none()); + assert!(h.query_by_label("Fontes").is_some() && h.query_by_label("About").is_some()); + } + + /// Create puts the sources, the reference and the heading given on the sheet, and Undo takes + /// it away. + #[test] + fn create_puts_them_on_the_sheet() { + let mut h = at(Step::Review, |d| { + (d.sources, d.reference) = ("IBGE\nANA".into(), "UTM 23S".into()); + d.headings[0] = "Fontes".into(); + }); + let before = h.state().session.project.layouts.len(); + click(&mut h, "Create"); + let layout = h.state().session.project.layouts.last().unwrap(); + let text = |name: &str| { + layout.elements.iter().find(|e| e.name == name).and_then(|e| match &e.kind { + ElementKind::Text { text, .. } => Some(text.clone()), + _ => None, + }) + }; + assert_eq!(text("Sources").as_deref(), Some("IBGE\nANA")); + assert_eq!(text("Reference").as_deref(), Some("UTM 23S")); + assert!(layout.elements.iter().any(|e| matches!(&e.kind, ElementKind::Text { text, .. } if text.eq_ignore_ascii_case("Fontes")))); + h.state_mut().run("edit.undo", Value::Null).unwrap(); + assert_eq!(h.state().session.project.layouts.len(), before); + } +} diff --git a/crates/ui-egui/src/publicationwizard/texts.rs b/crates/ui-egui/src/publicationwizard/texts.rs index 89c960fb91..e0a73a8da9 100644 --- a/crates/ui-egui/src/publicationwizard/texts.rs +++ b/crates/ui-egui/src/publicationwizard/texts.rs @@ -1,14 +1,14 @@ //! The wizard's texts step. use super::*; -use rustgis_engine::cmd::layout::MAX_PUBLICATION_TEXT; -/// The texts step: the title, subtitle, note, sources and credit line. -pub(super) fn texts_step(ui: &mut egui::Ui, d: &mut Draft) { +/// The texts step: the title, subtitle, note, credit line and an editorial sheet's column heading. +pub(super) fn texts_step(ui: &mut egui::Ui, d: &mut Draft, map: &Map) { egui::Grid::new("publication_wizard_texts").num_columns(2).spacing(egui::vec2(8.0, 8.0)).show(ui, |ui| { - let line = |ui: &mut egui::Ui, label: &str, text: &mut String| { + let line = |ui: &mut egui::Ui, d: &mut Draft, label: &str, field: Field| { let caption = ui.label(label); - ui.add(egui::TextEdit::singleline(text).char_limit(MAX_PUBLICATION_TEXT).desired_width(field_width(ui))) - .labelled_by(caption.id); + let edit = egui::TextEdit::singleline(d.field_mut(field)).char_limit(MAX_PUBLICATION_TEXT).desired_width(field_width(ui)); + let r = ui.add(edit).labelled_by(caption.id); + d.edited(&r, field); ui.end_row(); }; let label = ui.label(tl!("Title")); @@ -21,37 +21,43 @@ pub(super) fn texts_step(ui: &mut egui::Ui, d: &mut Draft) { ) .labelled_by(label.id); d.title_typed |= title.changed(); + d.edited(&title, Field::Title); ui.end_row(); - line(ui, tl!("Subtitle"), &mut d.subtitle); + line(ui, d, tl!("Subtitle"), Field::Subtitle); let label = ui.label(tl!("Note")); - ui.add(egui::TextEdit::multiline(&mut d.note).desired_rows(3).char_limit(MAX_PUBLICATION_TEXT).desired_width(field_width(ui))) + let note = ui + .add(egui::TextEdit::multiline(&mut d.note).desired_rows(3).char_limit(MAX_PUBLICATION_TEXT).desired_width(field_width(ui))) .labelled_by(label.id); + d.edited(¬e, Field::Note); ui.end_row(); - line(ui, tl!("Sources"), &mut d.sources); let label = ui.label(tl!("Credit line")); - ui.add_enabled( - !d.no_author, - egui::TextEdit::singleline(&mut d.author) - .hint_text(default_credit()) - .char_limit(MAX_PUBLICATION_TEXT) - .desired_width(field_width(ui)), - ) - .labelled_by(label.id); + let author = ui + .add_enabled( + !d.no_author, + egui::TextEdit::singleline(&mut d.author) + .hint_text(default_credit()) + .char_limit(MAX_PUBLICATION_TEXT) + .desired_width(field_width(ui)), + ) + .labelled_by(label.id); + d.edited(&author, Field::Author); ui.end_row(); ui.label(""); ui.checkbox(&mut d.no_author, tl!("No credit line")); ui.end_row(); + if d.editorial() { + line(ui, d, tl!("Column heading"), Field::Heading(2)); + } }); - // The boxes take no more, and cut a longer paste to fit: said, not done unseen. - let at_limit = [&d.title, &d.subtitle, &d.note, &d.sources].iter().any(|t| t.chars().count() >= MAX_PUBLICATION_TEXT) - || (!d.no_author && d.author.chars().count() >= MAX_PUBLICATION_TEXT); - if at_limit { - ui.label( - egui::RichText::new(i18n::fmt("Each field takes at most {limit} characters.", &[("limit", &MAX_PUBLICATION_TEXT.to_string())])) - .small() - .weak(), - ); + statistic_menu(ui, d, map, Field::Note); + let mut fields = vec![Field::Title, Field::Subtitle, Field::Note]; + if !d.no_author { + fields.push(Field::Author); + } + if d.editorial() { + fields.push(Field::Heading(2)); } + limit_note(ui, d, &fields); } #[cfg(test)] diff --git a/crates/ui-egui/src/textform.rs b/crates/ui-egui/src/textform.rs index 201e50990d..68e1aae0c6 100644 --- a/crates/ui-egui/src/textform.rs +++ b/crates/ui-egui/src/textform.rs @@ -27,21 +27,21 @@ pub struct StatLayer { impl StatLayer { /// The layers a text of `layout` can show figures of: those of the map its first frame shows - /// (as the page reads them), without a raster's or a graphics layer's, each with its numeric - /// fields. A name a token can't hold (`{`, `}`, or a field's `:`) is left out, and so is a layer - /// under another of its name, and a field after another of its name (case aside), which no token - /// reads. + /// (as the page reads them). pub fn of(layout: &rustgis_engine::map::layout::Layout, maps: &[rustgis_engine::map::Map]) -> Vec { use rustgis_engine::map::layout::ElementKind; let Some(ElementKind::MapFrame { map, .. }) = layout.first_frame().and_then(|f| layout.element(f)).map(|e| &e.kind) else { return Vec::new(); }; - let Some(map) = maps.iter().find(|m| m.name.eq_ignore_ascii_case(map)) else { return Vec::new() }; - let holds = |name: &str, colon: bool| !name.is_empty() && !name.contains(['{', '}']) && !(colon && name.contains(':')); - map.layers - .iter() - .filter(|l| !l.graphics && l.raster.is_none() && holds(&l.name, false)) - .filter(|l| map.layer_by_name(&l.name).is_some_and(|first| first.id == l.id)) + maps.iter().find(|m| m.name.eq_ignore_ascii_case(map)).map_or_else(Vec::new, Self::of_map) + } + + /// The layers of `map` a text can show figures of, without a raster's or a graphics layer's, + /// each with its numeric fields. A name a token can't hold (`{`, `}`, or a field's `:`) is left + /// out, and so is a layer under another of its name, and a field after another of its name (case + /// aside), which no token reads. + pub fn of_map(map: &rustgis_engine::map::Map) -> Vec { + Self::readable(map) .map(|l| StatLayer { name: l.name.clone(), fields: l @@ -55,36 +55,56 @@ impl StatLayer { }) .collect() } + + /// Whether [`Self::of_map`] lists any layer, without reading their fields. + pub fn any(map: &rustgis_engine::map::Map) -> bool { + Self::readable(map).next().is_some() + } + + fn readable(map: &rustgis_engine::map::Map) -> impl Iterator { + map.layers + .iter() + .filter(|l| !l.graphics && l.raster.is_none() && holds(&l.name, false)) + .filter(|l| map.layer_by_name(&l.name).is_some_and(|first| first.id == l.id)) + } +} + +/// Whether a statistic token can hold `name` (a field's takes no `:` either). +fn holds(name: &str, colon: bool) -> bool { + !name.is_empty() && !name.contains(['{', '}']) && !(colon && name.contains(':')) } /// The "Layer statistic" section of a Dynamic Text menu (#3036), the Format pane's and the -/// ribbon's: a submenu per layer, a count and, for each numeric field, its sum, mean, least and -/// greatest. `pick` takes the token chosen; with no layers there is no section. +/// ribbon's: [`stat_layers`] under that name. `pick` takes the token chosen; with no layers there +/// is no section. pub fn stat_menu(ui: &mut Ui, layers: &[StatLayer], mut pick: impl FnMut(String)) { if layers.is_empty() { return; } ui.separator(); - crate::widgets::submenu(ui, tl!("Layer statistic"), |ui| { - for layer in layers { - crate::widgets::submenu(ui, &layer.name, |ui| { - let mut add = |ui: &mut Ui, what: &str, token: String| { - if ui.button(format!("{what} {token}")).clicked() { - pick(token); - ui.close(); - } - }; - add(ui, tl!("Count"), format!("{{count:{}}}", layer.name)); - for field in &layer.fields { - crate::widgets::submenu(ui, field, |ui| { - for (code, what) in [("sum", tl!("Sum")), ("mean", tl!("Mean")), ("min", tl!("Least")), ("max", tl!("Greatest"))] { - add(ui, what, format!("{{{code}:{}:{field}}}", layer.name)); - } - }); + crate::widgets::submenu(ui, tl!("Layer statistic"), |ui| stat_layers(ui, layers, &mut pick)); +} + +/// A submenu per layer: a count and, for each numeric field, its sum, mean, least and greatest. +pub fn stat_layers(ui: &mut Ui, layers: &[StatLayer], pick: &mut impl FnMut(String)) { + for layer in layers { + crate::widgets::submenu(ui, &layer.name, |ui| { + let mut add = |ui: &mut Ui, what: &str, token: String| { + if ui.button(format!("{what} {token}")).clicked() { + pick(token); + ui.close(); } - }); - } - }); + }; + add(ui, tl!("Count"), format!("{{count:{}}}", layer.name)); + for field in &layer.fields { + crate::widgets::submenu(ui, field, |ui| { + for (code, what) in [("sum", tl!("Sum")), ("mean", tl!("Mean")), ("min", tl!("Least")), ("max", tl!("Greatest"))] { + add(ui, what, format!("{{{code}:{}:{field}}}", layer.name)); + } + }); + } + }); + } } /// What the form edits. A style is left out where the text doesn't have it. @@ -617,6 +637,7 @@ mod tests { StatLayer::of(&layout, &[map.clone(), other.clone()]), [StatLayer { name: "Cities".into(), fields: vec!["pop".into()] }] ); + assert_eq!(StatLayer::of_map(&map), StatLayer::of(&layout, std::slice::from_ref(&map)), "a map's own"); let mut second = Layout::new("L2", 100.0, 100.0); second.add("Frame", (0.0, 0.0, 50.0, 50.0), frame("Other")); assert_eq!(StatLayer::of(&second, &[map, other]), [StatLayer { name: "Rivers".into(), fields: vec!["km".into()] }]); diff --git a/docs/user-guide/layouts.md b/docs/user-guide/layouts.md index b41453a1bf..57945c8fae 100644 --- a/docs/user-guide/layouts.md +++ b/docs/user-guide/layouts.md @@ -44,12 +44,15 @@ Layouts open as tabs next to the maps; while one is open, its groups lead the Pu outline of where its title, map and footer go, and its column or panel if it has one, with the accent colour picked, or else its own, where the sheet takes it, which Classic's doesn't; a click on the outline picks the style), the texts (title, the active map's name until one is - typed; subtitle, note, sources and credit line, or none) and the accent colour, then shows - what was picked; **Create** makes the layout as the menu - does. A figure goes from its size to the review, as it takes no style, texts or accent. A - field left empty is left out (for the credit line, the dated default applies); the title is - the exception: empty, it means no title. A layout the command refuses is said, and the wizard - stays open. + typed; subtitle, note and credit line, or none; an Editorial sheet's column heading), the + sources and reference (each one per line, with its heading; the reference can be left out) and + the accent colour, then shows what was picked; **Create** makes the layout as the menu + does. **Insert Statistic**, on the texts and sources steps, adds a layer figure of the active + map to the field last edited there (the note or the sources, where none was). A figure goes + from its size to the review, as it takes no style, texts or accent. A field left empty is left + out (for the credit line, the reference and the headings, the command's default applies); the + title is the exception: empty, it means no title. A layout the command refuses is said, and the + wizard stays open. - **The map**: the `extent` given (or the view) fitted north-up, without tilt, at a round scale, two significant figures, rounded up so it still fits within the strips the graticule's labels take inside the frame. A graticule's step follows the extent (2° for a state, 15′ for a city), From 616a66aaeb333fcd9de3527f7eee584d467e3171 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Fri, 27 Nov 2026 07:36:37 -0500 Subject: [PATCH 02/12] fix(ui): send no heading for a left-out reference, and say the default reference in words (#3109) --- crates/ui-egui/src/publicationwizard/mod.rs | 12 ++++++++-- .../ui-egui/src/publicationwizard/review.rs | 3 ++- .../ui-egui/src/publicationwizard/sources.rs | 24 ++++++++++++------- 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/crates/ui-egui/src/publicationwizard/mod.rs b/crates/ui-egui/src/publicationwizard/mod.rs index d12da2c029..bb0393e06f 100644 --- a/crates/ui-egui/src/publicationwizard/mod.rs +++ b/crates/ui-egui/src/publicationwizard/mod.rs @@ -194,9 +194,17 @@ impl Draft { } /// `"headings"` up to the last one given, a gap before it filled with the command's own; the - /// column's only on an editorial sheet, the one style that draws it. + /// reference's not where there is none, and the column's only on an editorial sheet, the one + /// style that draws it. fn headings_sent(&self) -> Vec<&str> { - let given = |i: usize| (i < 2 || self.editorial()) && !self.headings[i].trim().is_empty(); + let given = |i: usize| { + let drawn = match i { + 1 => !self.no_reference, + 2 => self.editorial(), + _ => true, + }; + drawn && !self.headings[i].trim().is_empty() + }; let Some(last) = (0..self.headings.len()).rev().find(|&i| given(i)) else { return Vec::new() }; (0..=last) .map(|i| if given(i) { self.headings[i].trim() } else { PUBLICATION_HEADINGS.get(i).copied().unwrap_or_default() }) diff --git a/crates/ui-egui/src/publicationwizard/review.rs b/crates/ui-egui/src/publicationwizard/review.rs index 2e7d02da25..93b459e986 100644 --- a/crates/ui-egui/src/publicationwizard/review.rs +++ b/crates/ui-egui/src/publicationwizard/review.rs @@ -39,7 +39,8 @@ pub(super) fn review_step(ui: &mut egui::Ui, d: &Draft) { if d.no_reference { row(tl!("Reference"), none.to_string()); } else { - row(tl!("Reference"), if typed.is_empty() { PUBLICATION_DEFAULT_REFERENCE.join("\n") } else { typed }); + let default = tl!("The default: projection, datum and graticule, filled in on the sheet"); + row(tl!("Reference"), if typed.is_empty() { default.to_string() } else { typed }); row(tl!("Reference heading"), heading(1, PUBLICATION_HEADINGS[1])); } if d.editorial() { diff --git a/crates/ui-egui/src/publicationwizard/sources.rs b/crates/ui-egui/src/publicationwizard/sources.rs index c5dcf00ee0..f5d28a89a9 100644 --- a/crates/ui-egui/src/publicationwizard/sources.rs +++ b/crates/ui-egui/src/publicationwizard/sources.rs @@ -138,6 +138,18 @@ mod tests { assert_eq!(d.params()["headings"], json!([PUBLICATION_HEADINGS[0], PUBLICATION_HEADINGS[1], "Col"])); } + /// A section left out takes no heading with it: not the reference's where there is none. + #[test] + fn a_section_left_out_sends_no_heading() { + let mut d = draft(); + d.headings = [String::new(), "Ref".into(), String::new()]; + d.no_reference = true; + assert!(d.params().get("headings").is_none()); + d.style = "editorial".into(); + d.headings[2] = "Col".into(); + assert_eq!(d.params()["headings"], json!([PUBLICATION_HEADINGS[0], PUBLICATION_HEADINGS[1], "Col"])); + } + /// A figure takes none of them. #[test] fn a_figure_takes_no_sources_reference_or_headings() { @@ -148,13 +160,6 @@ mod tests { assert_eq!(d.params(), json!({"profile": "figure-1col"})); } - /// The wizard's literals for the command's defaults are the engine's. - #[test] - fn the_defaults_shown_match_the_engines() { - assert_eq!(PUBLICATION_HEADINGS, ["Sources", "Cartographic reference"]); - assert_eq!(PUBLICATION_DEFAULT_REFERENCE, ["Projection: {projection}", "Datum: {datum} · Graticule: {grid}"]); - } - /// The step has its fields, and No cartographic reference turns the reference's box off. #[test] fn the_step_asks_for_the_sources_the_reference_and_their_headings() { @@ -254,14 +259,15 @@ mod tests { fn the_review_lists_sources_reference_and_headings() { let mut h = at(Step::Review, |d| d.sources = "IBGE\nANA".into()); assert!(h.query_by_label("IBGE\nANA").is_some()); - assert!(h.query_by_label(&PUBLICATION_DEFAULT_REFERENCE.join("\n")).is_some()); + let default = "The default: projection, datum and graticule, filled in on the sheet"; + assert!(h.query_by_label(default).is_some(), "said in words, not as tokens"); assert!(h.query_by_label(PUBLICATION_HEADINGS[1]).is_some()); let d = h.state_mut().dialogs.publication.as_mut().unwrap(); d.no_reference = true; d.style = "editorial".into(); d.headings = ["Fontes".into(), String::new(), "About".into()]; h.run_steps(4); - assert!(h.query_by_label(&PUBLICATION_DEFAULT_REFERENCE.join("\n")).is_none()); + assert!(h.query_by_label(default).is_none()); assert!(h.query_by_label("Fontes").is_some() && h.query_by_label("About").is_some()); } From c298ecc8ba108ab09d75b4afb63b5d4ce8ccee82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Fri, 27 Nov 2026 07:42:20 -0500 Subject: [PATCH 03/12] refactor(ui): count a box's lines without collecting them (#3109) --- crates/ui-egui/src/publicationwizard/mod.rs | 8 ++++---- crates/ui-egui/src/publicationwizard/review.rs | 4 ++-- crates/ui-egui/src/publicationwizard/sources.rs | 2 +- crates/ui-egui/src/textform.rs | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/crates/ui-egui/src/publicationwizard/mod.rs b/crates/ui-egui/src/publicationwizard/mod.rs index bb0393e06f..6ca45daba8 100644 --- a/crates/ui-egui/src/publicationwizard/mod.rs +++ b/crates/ui-egui/src/publicationwizard/mod.rs @@ -175,11 +175,11 @@ impl Draft { if self.no_author { p["author"] = json!(""); } - let sources = lines(&self.sources); + let sources: Vec<&str> = lines(&self.sources).collect(); if !sources.is_empty() { p["sources"] = json!(sources); } - let reference = lines(&self.reference); + let reference: Vec<&str> = lines(&self.reference).collect(); if self.no_reference || !reference.is_empty() { p["reference"] = json!(if self.no_reference { Vec::new() } else { reference }); } @@ -262,8 +262,8 @@ impl Draft { } /// A box's lines as the command takes a list: trimmed, the empty ones left out. -fn lines(text: &str) -> Vec<&str> { - text.lines().map(str::trim).filter(|l| !l.is_empty()).collect() +fn lines(text: &str) -> impl Iterator { + text.lines().map(str::trim).filter(|l| !l.is_empty()) } /// The menu that adds a layer figure of the active map (the one the sheet shows), listed as the diff --git a/crates/ui-egui/src/publicationwizard/review.rs b/crates/ui-egui/src/publicationwizard/review.rs index 93b459e986..d939e38e21 100644 --- a/crates/ui-egui/src/publicationwizard/review.rs +++ b/crates/ui-egui/src/publicationwizard/review.rs @@ -26,7 +26,7 @@ pub(super) fn review_step(ui: &mut egui::Ui, d: &Draft) { row(tl!("Title"), or_none(&d.title)); row(tl!("Subtitle"), or_none(&d.subtitle)); row(tl!("Note"), or_none(&d.note)); - let sources = lines(&d.sources).join("\n"); + let sources = lines(&d.sources).collect::>().join("\n"); row(tl!("Sources"), or_none(&sources)); let heading = |i: usize, or: &str| { let given = d.headings[i].trim(); @@ -35,7 +35,7 @@ pub(super) fn review_step(ui: &mut egui::Ui, d: &Draft) { if !sources.is_empty() { row(tl!("Sources heading"), heading(0, PUBLICATION_HEADINGS[0])); } - let typed = lines(&d.reference).join("\n"); + let typed = lines(&d.reference).collect::>().join("\n"); if d.no_reference { row(tl!("Reference"), none.to_string()); } else { diff --git a/crates/ui-egui/src/publicationwizard/sources.rs b/crates/ui-egui/src/publicationwizard/sources.rs index f5d28a89a9..4ef395813d 100644 --- a/crates/ui-egui/src/publicationwizard/sources.rs +++ b/crates/ui-egui/src/publicationwizard/sources.rs @@ -35,7 +35,7 @@ fn list(ui: &mut egui::Ui, d: &mut Draft, label: &str, field: Field, hint: &str, let r = ui.add_enabled(on, edit).labelled_by(caption.id); d.edited(&r, field); ui.end_row(); - if on && lines(d.field_mut(field)).len() > MAX_LINES { + if on && lines(d.field_mut(field)).count() > MAX_LINES { ui.label(""); let note = i18n::fmt("At most {limit} lines.", &[("limit", &MAX_LINES.to_string())]); ui.label(egui::RichText::new(note).small().weak()); diff --git a/crates/ui-egui/src/textform.rs b/crates/ui-egui/src/textform.rs index 68e1aae0c6..0b19586db0 100644 --- a/crates/ui-egui/src/textform.rs +++ b/crates/ui-egui/src/textform.rs @@ -26,8 +26,8 @@ pub struct StatLayer { } impl StatLayer { - /// The layers a text of `layout` can show figures of: those of the map its first frame shows - /// (as the page reads them). + /// The layers a text of `layout` can show figures of: those [`Self::of_map`] lists for the map + /// its first frame shows (as the page reads them). pub fn of(layout: &rustgis_engine::map::layout::Layout, maps: &[rustgis_engine::map::Map]) -> Vec { use rustgis_engine::map::layout::ElementKind; let Some(ElementKind::MapFrame { map, .. }) = layout.first_frame().and_then(|f| layout.element(f)).map(|e| &e.kind) else { From c572524e5d089c4530d2cea388f14886b53772ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Fri, 27 Nov 2026 07:56:16 -0500 Subject: [PATCH 04/12] fix(ui): send no sources heading where there are no sources (#3109) --- crates/ui-egui/src/publicationwizard/mod.rs | 7 ++++--- crates/ui-egui/src/publicationwizard/sources.rs | 2 ++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/publicationwizard/mod.rs b/crates/ui-egui/src/publicationwizard/mod.rs index 6ca45daba8..eeafb5df27 100644 --- a/crates/ui-egui/src/publicationwizard/mod.rs +++ b/crates/ui-egui/src/publicationwizard/mod.rs @@ -193,12 +193,13 @@ impl Draft { p } - /// `"headings"` up to the last one given, a gap before it filled with the command's own; the - /// reference's not where there is none, and the column's only on an editorial sheet, the one - /// style that draws it. + /// `"headings"` up to the last one given, a gap before it filled with the command's own; none + /// for a section left out (no sources, no reference), and the column's only on an editorial + /// sheet, the one style that draws it. fn headings_sent(&self) -> Vec<&str> { let given = |i: usize| { let drawn = match i { + 0 => lines(&self.sources).next().is_some(), 1 => !self.no_reference, 2 => self.editorial(), _ => true, diff --git a/crates/ui-egui/src/publicationwizard/sources.rs b/crates/ui-egui/src/publicationwizard/sources.rs index 4ef395813d..de34c3f431 100644 --- a/crates/ui-egui/src/publicationwizard/sources.rs +++ b/crates/ui-egui/src/publicationwizard/sources.rs @@ -129,6 +129,8 @@ mod tests { let mut d = draft(); assert!(d.params().get("headings").is_none()); d.headings[0] = " S ".into(); + assert!(d.params().get("headings").is_none(), "no sources, so no section to head"); + d.sources = "IBGE".into(); assert_eq!(d.params()["headings"], json!(["S"])); d.headings = [String::new(), "Ref".into(), String::new()]; assert_eq!(d.params()["headings"], json!([PUBLICATION_HEADINGS[0], "Ref"])); From 8e4b1f17cc6b3f3aef6b684a01d3d322a7319318 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Fri, 27 Nov 2026 08:02:29 -0500 Subject: [PATCH 05/12] fix(ui): keep each step's last edited field for a statistic (#3109) --- crates/ui-egui/src/publicationwizard/mod.rs | 16 +++++++++---- .../ui-egui/src/publicationwizard/sources.rs | 24 ++++++++++++++++--- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/crates/ui-egui/src/publicationwizard/mod.rs b/crates/ui-egui/src/publicationwizard/mod.rs index eeafb5df27..0a61b1c7bc 100644 --- a/crates/ui-egui/src/publicationwizard/mod.rs +++ b/crates/ui-egui/src/publicationwizard/mod.rs @@ -55,6 +55,11 @@ impl Field { Field::Sources | Field::Reference | Field::Heading(_) => Step::Sources, } } + + /// Where [`Draft::targets`] keeps its step's last field. + fn slot(self) -> usize { + usize::from(self.step() == Step::Sources) + } } /// How a sheet is turned: `Auto` leaves it to `layout.publication` (the way the map comes out larger). @@ -88,8 +93,9 @@ pub struct Draft { /// The headings of the sources, the reference and an editorial sheet's column; one left empty /// is left to the command. pub headings: [String; 3], - /// The text field last edited, which a layer statistic is added to. - target: Option, + /// The field last edited on the texts step and on the sources step, which a layer statistic + /// added there goes to ([`Field::slot`]). + targets: [Option; 2], /// The field the last statistic didn't fit in, said until its step's text changes. refused: Option, /// The style's colour, or `None` for the style's own. @@ -118,7 +124,7 @@ impl Draft { reference: String::new(), no_reference: false, headings: Default::default(), - target: None, + targets: [None; 2], refused: None, accent: None, picked: None, @@ -234,7 +240,7 @@ impl Draft { /// Notes `field` as the one last edited while it has the focus. fn edited(&mut self, r: &egui::Response, field: Field) { if r.has_focus() { - self.target = Some(field); + self.targets[field.slot()] = Some(field); } if r.changed() { self.refused = None; @@ -250,7 +256,7 @@ impl Draft { Field::Heading(2) => self.editorial(), _ => true, }; - let field = self.target.filter(|&f| f.step() == own.step() && on(f)).unwrap_or(own); + let field = self.targets[own.slot()].filter(|&f| on(f)).unwrap_or(own); let text = self.field_mut(field); if text.chars().count() + token.chars().count() > MAX_PUBLICATION_TEXT { self.refused = Some(field); diff --git a/crates/ui-egui/src/publicationwizard/sources.rs b/crates/ui-egui/src/publicationwizard/sources.rs index de34c3f431..572e043f0d 100644 --- a/crates/ui-egui/src/publicationwizard/sources.rs +++ b/crates/ui-egui/src/publicationwizard/sources.rs @@ -197,6 +197,24 @@ mod tests { assert!(wizard(&h).note.is_empty()); } + /// Each step keeps its own: a field edited on the sources step leaves the texts' last one. + #[test] + fn each_step_keeps_the_field_last_edited_on_it() { + let mut h = at(Step::Texts, |_| {}); + h.get_by_label("Subtitle").focus(); + h.run_steps(2); + click(&mut h, "Next"); + h.get_by_label("Sources heading").focus(); + h.run_steps(2); + click(&mut h, "Back"); + let token = insert_count(&mut h); + assert_eq!(wizard(&h).subtitle, token); + assert!(wizard(&h).note.is_empty()); + click(&mut h, "Next"); + insert_count(&mut h); + assert_eq!(wizard(&h).headings[0], token); + } + /// With nothing edited on the step it goes to the note, or to the sources on their step, a /// field edited on another step left alone. #[test] @@ -204,7 +222,7 @@ mod tests { let mut h = at(Step::Texts, |_| {}); let token = insert_count(&mut h); assert_eq!(wizard(&h).note, token); - let mut h = at(Step::Sources, |d| d.target = Some(Field::Subtitle)); + let mut h = at(Step::Sources, |d| d.targets[0] = Some(Field::Subtitle)); let token = insert_count(&mut h); assert_eq!(wizard(&h).sources, token); assert!(wizard(&h).subtitle.is_empty()); @@ -213,7 +231,7 @@ mod tests { /// A statistic put in the title is a title typed: a map opened afterwards doesn't replace it. #[test] fn a_statistic_in_the_title_keeps_the_title() { - let mut h = at(Step::Texts, |d| d.target = Some(Field::Title)); + let mut h = at(Step::Texts, |d| d.targets[0] = Some(Field::Title)); insert_count(&mut h); assert!(wizard(&h).title_typed); } @@ -223,7 +241,7 @@ mod tests { fn a_statistic_past_the_limit_isnt_added_and_its_said() { let full = "x".repeat(MAX_PUBLICATION_TEXT - 3); // A one-line field: a box this full of text would push the menu out of the step's view. - let mut h = at(Step::Sources, |d| (d.headings[0], d.target) = (full.clone(), Some(Field::Heading(0)))); + let mut h = at(Step::Sources, |d| (d.headings[0], d.targets[1]) = (full.clone(), Some(Field::Heading(0)))); let limit = format!("Each field takes at most {MAX_PUBLICATION_TEXT} characters."); assert!(h.query_by_label(&limit).is_none()); insert_count(&mut h); From 7425f932eb75942be73d357bfa4a09d3c2f1cfec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Fri, 27 Nov 2026 08:25:54 -0500 Subject: [PATCH 06/12] fix(ui): keep a step's refusal note until its own text changes, and say a statistic goes to the field last focused (#3109) --- crates/ui-egui/src/publicationwizard/mod.rs | 11 +++++---- .../ui-egui/src/publicationwizard/sources.rs | 24 +++++++++++++++---- docs/user-guide/layouts.md | 2 +- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/crates/ui-egui/src/publicationwizard/mod.rs b/crates/ui-egui/src/publicationwizard/mod.rs index 0a61b1c7bc..3b7129f2e1 100644 --- a/crates/ui-egui/src/publicationwizard/mod.rs +++ b/crates/ui-egui/src/publicationwizard/mod.rs @@ -93,8 +93,8 @@ pub struct Draft { /// The headings of the sources, the reference and an editorial sheet's column; one left empty /// is left to the command. pub headings: [String; 3], - /// The field last edited on the texts step and on the sources step, which a layer statistic - /// added there goes to ([`Field::slot`]). + /// The field the cursor was last in on the texts step and on the sources step, which a layer + /// statistic added there goes to ([`Field::slot`]). targets: [Option; 2], /// The field the last statistic didn't fit in, said until its step's text changes. refused: Option, @@ -237,17 +237,18 @@ impl Draft { } } - /// Notes `field` as the one last edited while it has the focus. + /// Notes `field` as its step's last one while it has the focus, typed into or not, and ends + /// its step's refusal note when its text changes. fn edited(&mut self, r: &egui::Response, field: Field) { if r.has_focus() { self.targets[field.slot()] = Some(field); } - if r.changed() { + if r.changed() && self.refused.is_some_and(|f| f.step() == field.step()) { self.refused = None; } } - /// Adds a layer statistic to the field last edited on `own`'s step, or to `own` where none was + /// Adds a layer statistic to the field last focused on `own`'s step, or to `own` where none was /// or that one is off now; one that would take the field past the limit isn't added. fn add_statistic(&mut self, token: &str, own: Field) { let on = |f: Field| match f { diff --git a/crates/ui-egui/src/publicationwizard/sources.rs b/crates/ui-egui/src/publicationwizard/sources.rs index 572e043f0d..ccf2a9c90d 100644 --- a/crates/ui-egui/src/publicationwizard/sources.rs +++ b/crates/ui-egui/src/publicationwizard/sources.rs @@ -186,9 +186,9 @@ mod tests { assert!(h.query_by_label("Column heading").is_some()); } - /// A statistic goes to the field last edited, here the subtitle. + /// A statistic goes to the field the cursor was last in, here the subtitle. #[test] - fn a_statistic_goes_to_the_field_last_edited() { + fn a_statistic_goes_to_the_field_last_focused() { let mut h = at(Step::Texts, |d| d.subtitle = "In ".into()); h.get_by_label("Subtitle").focus(); h.run_steps(2); @@ -197,9 +197,9 @@ mod tests { assert!(wizard(&h).note.is_empty()); } - /// Each step keeps its own: a field edited on the sources step leaves the texts' last one. + /// Each step keeps its own: a field focused on the sources step leaves the texts' last one. #[test] - fn each_step_keeps_the_field_last_edited_on_it() { + fn each_step_keeps_the_field_last_focused_on_it() { let mut h = at(Step::Texts, |_| {}); h.get_by_label("Subtitle").focus(); h.run_steps(2); @@ -215,6 +215,22 @@ mod tests { assert_eq!(wizard(&h).headings[0], token); } + /// A statistic that didn't fit stays said when a field of the other step changes. + #[test] + fn a_refused_statistic_stays_said_after_editing_the_other_step() { + let full = "x".repeat(MAX_PUBLICATION_TEXT - 3); + let mut h = at(Step::Sources, |d| (d.headings[0], d.targets[1]) = (full, Some(Field::Heading(0)))); + let limit = format!("Each field takes at most {MAX_PUBLICATION_TEXT} characters."); + insert_count(&mut h); + click(&mut h, "Back"); + h.get_by_label("Subtitle").focus(); + h.run_steps(2); + h.get_by_label("Subtitle").type_text("a"); + h.run_steps(2); + click(&mut h, "Next"); + assert!(h.query_by_label(&limit).is_some()); + } + /// With nothing edited on the step it goes to the note, or to the sources on their step, a /// field edited on another step left alone. #[test] diff --git a/docs/user-guide/layouts.md b/docs/user-guide/layouts.md index 57945c8fae..4428f57237 100644 --- a/docs/user-guide/layouts.md +++ b/docs/user-guide/layouts.md @@ -48,7 +48,7 @@ Layouts open as tabs next to the maps; while one is open, its groups lead the Pu sources and reference (each one per line, with its heading; the reference can be left out) and the accent colour, then shows what was picked; **Create** makes the layout as the menu does. **Insert Statistic**, on the texts and sources steps, adds a layer figure of the active - map to the field last edited there (the note or the sources, where none was). A figure goes + map to the field the cursor was last in there (the note or the sources, where it was in none). A figure goes from its size to the review, as it takes no style, texts or accent. A field left empty is left out (for the credit line, the reference and the headings, the command's default applies); the title is the exception: empty, it means no title. A layout the command refuses is said, and the From eb0b5e158474078113eff438792a9bca41176a5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Fri, 27 Nov 2026 09:29:08 -0500 Subject: [PATCH 07/12] fix(ui): say when a typed heading isn't used, and share the 50-line limit with the command (#3109) --- .../src/cmd/layout/publication/sheet.rs | 9 ++++--- .../src/cmd/layout/publication/texts.rs | 6 ++--- crates/ui-egui/src/publicationwizard/mod.rs | 3 ++- .../ui-egui/src/publicationwizard/review.rs | 7 ++++++ .../ui-egui/src/publicationwizard/sources.rs | 24 +++++++++++++++---- 5 files changed, 37 insertions(+), 12 deletions(-) diff --git a/crates/engine/src/cmd/layout/publication/sheet.rs b/crates/engine/src/cmd/layout/publication/sheet.rs index 77556fd14a..3cc3643e87 100644 --- a/crates/engine/src/cmd/layout/publication/sheet.rs +++ b/crates/engine/src/cmd/layout/publication/sheet.rs @@ -62,11 +62,14 @@ pub const PUBLICATION_DEFAULT_CREDIT: &str = "Made with RustGIS · {date}"; /// give them. pub const PUBLICATION_HEADINGS: [&str; 2] = ["Sources", "Cartographic reference"]; -/// The cartographic reference's lines when `"reference"` isn't given (`{projection}`, `{datum}` -/// and `{grid}` are filled with the sheet's; without a graticule the second names the datum -/// alone). +/// The cartographic reference's lines when `"reference"` isn't given, on a sheet with a graticule +/// (`{projection}`, `{datum}` and `{grid}` are filled with the sheet's). Without one the command +/// writes the datum alone in place of the second. pub const PUBLICATION_DEFAULT_REFERENCE: [&str; 2] = ["Projection: {projection}", "Datum: {datum} · Graticule: {grid}"]; +/// The most texts a publication layout takes in one list, such as its sources. +pub const MAX_PUBLICATION_LINES: usize = 50; + /// The longest text a publication layout takes in one field, in characters. pub const MAX_PUBLICATION_TEXT: usize = 2000; diff --git a/crates/engine/src/cmd/layout/publication/texts.rs b/crates/engine/src/cmd/layout/publication/texts.rs index 1f7acbb96e..010426551a 100644 --- a/crates/engine/src/cmd/layout/publication/texts.rs +++ b/crates/engine/src/cmd/layout/publication/texts.rs @@ -81,19 +81,19 @@ pub(crate) fn datum_of(def: &str) -> Option { param("+R=").map(|_| "a sphere".into()) } -/// Texts given as one or a list (up to 50), each of at most [`MAX_PUBLICATION_TEXT`] characters: a +/// Texts given as one or a list (up to [`MAX_PUBLICATION_LINES`]), each of at most [`MAX_PUBLICATION_TEXT`] characters: a /// longer one is refused, not cut. pub(in crate::cmd::layout) fn texts_of(p: &Value, k: &str) -> Result>, String> { let within = |t: &str| crate::cmd::within(k, "a publication layout's text", t, MAX_PUBLICATION_TEXT); match p.get(k) { None | Some(Value::Null) => Ok(None), Some(Value::String(t)) => Ok(Some(vec![within(t)?])), - Some(Value::Array(a)) if a.len() <= 50 => a + Some(Value::Array(a)) if a.len() <= MAX_PUBLICATION_LINES => a .iter() .map(|v| v.as_str().ok_or_else(|| format!("{k} is a text or a list of texts")).and_then(within)) .collect::>() .map(Some), - Some(_) => Err(format!("{k} is a text or a list of up to 50 texts")), + Some(_) => Err(format!("{k} is a text or a list of up to {MAX_PUBLICATION_LINES} texts")), } } diff --git a/crates/ui-egui/src/publicationwizard/mod.rs b/crates/ui-egui/src/publicationwizard/mod.rs index 3b7129f2e1..820f763192 100644 --- a/crates/ui-egui/src/publicationwizard/mod.rs +++ b/crates/ui-egui/src/publicationwizard/mod.rs @@ -14,7 +14,8 @@ use accent::accent_step; use review::review_step; use rustgis_engine::Session; use rustgis_engine::cmd::layout::{ - MAX_PUBLICATION_TEXT, PUBLICATION_DEFAULT_REFERENCE, PUBLICATION_HEADINGS, PUBLICATION_PROFILES, publication_style_accent, + MAX_PUBLICATION_LINES, MAX_PUBLICATION_TEXT, PUBLICATION_DEFAULT_REFERENCE, PUBLICATION_HEADINGS, PUBLICATION_PROFILES, + publication_style_accent, }; use rustgis_engine::map::Map; use rustgis_engine::map::layout::PAGES; diff --git a/crates/ui-egui/src/publicationwizard/review.rs b/crates/ui-egui/src/publicationwizard/review.rs index d939e38e21..d0d031da5b 100644 --- a/crates/ui-egui/src/publicationwizard/review.rs +++ b/crates/ui-egui/src/publicationwizard/review.rs @@ -32,12 +32,19 @@ pub(super) fn review_step(ui: &mut egui::Ui, d: &Draft) { let given = d.headings[i].trim(); if given.is_empty() { or.to_string() } else { given.to_string() } }; + // A heading typed for a section left out isn't sent: said, not dropped unseen. + let typed_at = |i: usize| Some(d.headings[i].trim()).filter(|h| !h.is_empty()); if !sources.is_empty() { row(tl!("Sources heading"), heading(0, PUBLICATION_HEADINGS[0])); + } else if let Some(h) = typed_at(0) { + row(tl!("Sources heading"), i18n::fmt("{heading} (not used: no sources)", &[("heading", h)])); } let typed = lines(&d.reference).collect::>().join("\n"); if d.no_reference { row(tl!("Reference"), none.to_string()); + if let Some(h) = typed_at(1) { + row(tl!("Reference heading"), i18n::fmt("{heading} (not used: no reference)", &[("heading", h)])); + } } else { let default = tl!("The default: projection, datum and graticule, filled in on the sheet"); row(tl!("Reference"), if typed.is_empty() { default.to_string() } else { typed }); diff --git a/crates/ui-egui/src/publicationwizard/sources.rs b/crates/ui-egui/src/publicationwizard/sources.rs index ccf2a9c90d..9053a33231 100644 --- a/crates/ui-egui/src/publicationwizard/sources.rs +++ b/crates/ui-egui/src/publicationwizard/sources.rs @@ -1,9 +1,6 @@ //! The wizard's sources and reference step. use super::*; -/// The most lines `layout.publication` takes in a list. -const MAX_LINES: usize = 50; - /// The sources step: the sources, the cartographic reference and their headings. pub(super) fn sources_step(ui: &mut egui::Ui, d: &mut Draft, map: &Map) { egui::Grid::new("publication_wizard_sources").num_columns(2).spacing(egui::vec2(8.0, 8.0)).show(ui, |ui| { @@ -35,9 +32,9 @@ fn list(ui: &mut egui::Ui, d: &mut Draft, label: &str, field: Field, hint: &str, let r = ui.add_enabled(on, edit).labelled_by(caption.id); d.edited(&r, field); ui.end_row(); - if on && lines(d.field_mut(field)).count() > MAX_LINES { + if on && lines(d.field_mut(field)).count() > MAX_PUBLICATION_LINES { ui.label(""); - let note = i18n::fmt("At most {limit} lines.", &[("limit", &MAX_LINES.to_string())]); + let note = i18n::fmt("At most {limit} lines.", &[("limit", &MAX_PUBLICATION_LINES.to_string())]); ui.label(egui::RichText::new(note).small().weak()); ui.end_row(); } @@ -307,6 +304,23 @@ mod tests { assert!(h.query_by_label("Fontes").is_some() && h.query_by_label("About").is_some()); } + /// A heading typed for a section left out (no sources, no reference) is listed as not used. + #[test] + fn the_review_says_a_heading_of_a_section_left_out_isnt_used() { + let mut h = at(Step::Review, |d| { + d.headings = ["Fontes".into(), "Base".into(), String::new()]; + d.no_reference = true; + }); + for said in ["Fontes (not used: no sources)", "Base (not used: no reference)"] { + assert!(h.query_by_label(said).is_some(), "{said}"); + } + let d = h.state_mut().dialogs.publication.as_mut().unwrap(); + (d.sources, d.no_reference) = ("IBGE".into(), false); + h.run_steps(4); + assert!(h.query_by_label_contains("not used").is_none()); + assert!(h.query_by_label("Fontes").is_some() && h.query_by_label("Base").is_some()); + } + /// Create puts the sources, the reference and the heading given on the sheet, and Undo takes /// it away. #[test] From 5a728c8e6d65fdb1ef5bfae5f2096f8cf7e191fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Fri, 27 Nov 2026 09:37:10 -0500 Subject: [PATCH 08/12] fix(ui): say when a typed column heading isn't used (#3109) --- crates/engine/src/cmd/layout/publication/texts.rs | 4 ++-- crates/ui-egui/src/publicationwizard/review.rs | 2 ++ crates/ui-egui/src/publicationwizard/sources.rs | 13 ++++++++----- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/crates/engine/src/cmd/layout/publication/texts.rs b/crates/engine/src/cmd/layout/publication/texts.rs index 010426551a..a7b449c988 100644 --- a/crates/engine/src/cmd/layout/publication/texts.rs +++ b/crates/engine/src/cmd/layout/publication/texts.rs @@ -81,8 +81,8 @@ pub(crate) fn datum_of(def: &str) -> Option { param("+R=").map(|_| "a sphere".into()) } -/// Texts given as one or a list (up to [`MAX_PUBLICATION_LINES`]), each of at most [`MAX_PUBLICATION_TEXT`] characters: a -/// longer one is refused, not cut. +/// Texts given as one or a list (up to [`MAX_PUBLICATION_LINES`]), each of at most +/// [`MAX_PUBLICATION_TEXT`] characters: a longer one is refused, not cut. pub(in crate::cmd::layout) fn texts_of(p: &Value, k: &str) -> Result>, String> { let within = |t: &str| crate::cmd::within(k, "a publication layout's text", t, MAX_PUBLICATION_TEXT); match p.get(k) { diff --git a/crates/ui-egui/src/publicationwizard/review.rs b/crates/ui-egui/src/publicationwizard/review.rs index d0d031da5b..bdd2567c6d 100644 --- a/crates/ui-egui/src/publicationwizard/review.rs +++ b/crates/ui-egui/src/publicationwizard/review.rs @@ -52,6 +52,8 @@ pub(super) fn review_step(ui: &mut egui::Ui, d: &Draft) { } if d.editorial() { row(tl!("Column heading"), heading(2, none)); + } else if let Some(h) = typed_at(2) { + row(tl!("Column heading"), i18n::fmt("{heading} (not used: not an editorial sheet)", &[("heading", h)])); } let credit = if d.no_author { none.to_string() diff --git a/crates/ui-egui/src/publicationwizard/sources.rs b/crates/ui-egui/src/publicationwizard/sources.rs index 9053a33231..072d8ff935 100644 --- a/crates/ui-egui/src/publicationwizard/sources.rs +++ b/crates/ui-egui/src/publicationwizard/sources.rs @@ -304,21 +304,24 @@ mod tests { assert!(h.query_by_label("Fontes").is_some() && h.query_by_label("About").is_some()); } - /// A heading typed for a section left out (no sources, no reference) is listed as not used. + /// A heading typed for a section left out (no sources, no reference, a column on a sheet that + /// isn't editorial) is listed as not used. #[test] fn the_review_says_a_heading_of_a_section_left_out_isnt_used() { let mut h = at(Step::Review, |d| { - d.headings = ["Fontes".into(), "Base".into(), String::new()]; + d.headings = ["Fontes".into(), "Base".into(), "About".into()]; d.no_reference = true; }); - for said in ["Fontes (not used: no sources)", "Base (not used: no reference)"] { + for said in ["Fontes (not used: no sources)", "Base (not used: no reference)", "About (not used: not an editorial sheet)"] { assert!(h.query_by_label(said).is_some(), "{said}"); } let d = h.state_mut().dialogs.publication.as_mut().unwrap(); - (d.sources, d.no_reference) = ("IBGE".into(), false); + (d.sources, d.no_reference, d.style) = ("IBGE".into(), false, "editorial".into()); h.run_steps(4); assert!(h.query_by_label_contains("not used").is_none()); - assert!(h.query_by_label("Fontes").is_some() && h.query_by_label("Base").is_some()); + for sent in ["Fontes", "Base", "About"] { + assert!(h.query_by_label(sent).is_some(), "{sent}"); + } } /// Create puts the sources, the reference and the heading given on the sheet, and Undo takes From 0d1d7cad41c6c78745f790e5b737842a60f49fb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Fri, 27 Nov 2026 09:50:08 -0500 Subject: [PATCH 09/12] refactor(layout): name the default reference's projection line apart from the projection (#3109) --- .../engine/src/cmd/layout/publication/mod.rs | 4 +-- docs/user-guide/layouts.md | 28 +++++++++---------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/crates/engine/src/cmd/layout/publication/mod.rs b/crates/engine/src/cmd/layout/publication/mod.rs index b27819dfe7..87e571c581 100644 --- a/crates/engine/src/cmd/layout/publication/mod.rs +++ b/crates/engine/src/cmd/layout/publication/mod.rs @@ -183,9 +183,9 @@ pub(in crate::cmd::layout) fn publication(s: &mut Session, p: &Value) -> CmdResu let room_side = if labelled.left || labelled.right { LABEL_ROOM_SIDE * strip_scale } else { 0.0 }; let room_end = if labelled.top || labelled.bottom { LABEL_ROOM_END * strip_scale } else { 0.0 }; let reference = reference.unwrap_or_else(|| { - let [projection, datum_and_grid] = PUBLICATION_DEFAULT_REFERENCE; + let [projection_line, datum_and_grid] = PUBLICATION_DEFAULT_REFERENCE; let line = if step.is_some() { datum_and_grid } else { "Datum: {datum}" }; - vec![projection.into(), line.into()] + vec![projection_line.into(), line.into()] }); let step_said = step.map_or_else(|| "—".to_string(), step_text); let fill = |t: &str| t.replace("{projection}", &projection).replace("{datum}", &datum).replace("{grid}", &step_said); diff --git a/docs/user-guide/layouts.md b/docs/user-guide/layouts.md index 4428f57237..4ab757508b 100644 --- a/docs/user-guide/layouts.md +++ b/docs/user-guide/layouts.md @@ -39,20 +39,20 @@ Layouts open as tabs next to the maps; while one is open, its groups lead the Pu thesis (160 × 225 or 160 × 110 mm): the map edge to edge with a line of its projection and datum under it, at 7 pt. A figure's title and sources belong in its caption, so they are left out, and the result says so. - - **Step by step**: **Publication Layout Wizard…**, at the end of the same menu, asks for the - size (a sheet turned Auto, Portrait or Landscape, or a figure), the style (each beside an - outline of where its title, map and footer go, and its column or panel if it has one, with - the accent colour picked, or else its own, where the sheet takes it, which Classic's doesn't; - a click on the outline picks the style), the texts (title, the active map's name until one is - typed; subtitle, note and credit line, or none; an Editorial sheet's column heading), the - sources and reference (each one per line, with its heading; the reference can be left out) and - the accent colour, then shows what was picked; **Create** makes the layout as the menu - does. **Insert Statistic**, on the texts and sources steps, adds a layer figure of the active - map to the field the cursor was last in there (the note or the sources, where it was in none). A figure goes - from its size to the review, as it takes no style, texts or accent. A field left empty is left - out (for the credit line, the reference and the headings, the command's default applies); the - title is the exception: empty, it means no title. A layout the command refuses is said, and the - wizard stays open. + - **Step by step**: **Publication Layout Wizard…**, at the end of the same menu, asks for the size + (a sheet turned Auto, Portrait or Landscape, or a figure), the style (each beside an outline of + where its title, map and footer go, and its column or panel if it has one, with the accent + colour picked, or else its own, where the sheet takes it, which Classic's doesn't; a click on + the outline picks the style), the texts (title, the active map's name until one is typed; + subtitle, note and credit line, or none; an Editorial sheet's column heading), the sources and + reference (each one per line, with its heading; the reference can be left out) and the accent + colour, then shows what was picked; **Create** makes the layout as the menu does. **Insert + Statistic**, on the texts and sources steps, adds a layer figure of the active map to the field + the cursor was last in there (the note or the sources, where it was in none). A figure goes from + its size to the review, as it takes no style, texts or accent. A field left empty is left out + (for the credit line, the reference and the headings, the command's default applies); the title + is the exception: empty, it means no title. A layout the command refuses is said, and the wizard + stays open. - **The map**: the `extent` given (or the view) fitted north-up, without tilt, at a round scale, two significant figures, rounded up so it still fits within the strips the graticule's labels take inside the frame. A graticule's step follows the extent (2° for a state, 15′ for a city), From 765db880ccbc0a580a3e7cacb97d9b67af4e0446 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Fri, 27 Nov 2026 10:06:15 -0500 Subject: [PATCH 10/12] refactor(ui): decide in one place what a publication sheet has no place for, and say reference lines switched off (#3109) --- crates/ui-egui/src/publicationwizard/mod.rs | 45 +++++++++------ .../ui-egui/src/publicationwizard/review.rs | 51 ++++++++--------- .../ui-egui/src/publicationwizard/sources.rs | 57 +++++++++++++++---- crates/ui-egui/src/publicationwizard/texts.rs | 11 +--- 4 files changed, 100 insertions(+), 64 deletions(-) diff --git a/crates/ui-egui/src/publicationwizard/mod.rs b/crates/ui-egui/src/publicationwizard/mod.rs index 820f763192..c51791cdb2 100644 --- a/crates/ui-egui/src/publicationwizard/mod.rs +++ b/crates/ui-egui/src/publicationwizard/mod.rs @@ -36,6 +36,14 @@ pub enum Step { Review, } +/// Why `layout.publication` draws no place for a field's text. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +enum LeftOut { + NoSources, + NoReference, + NotEditorial, +} + /// A text field of the wizard that takes a layer statistic. #[derive(Clone, Copy, Debug, PartialEq, Eq)] enum Field { @@ -204,15 +212,7 @@ impl Draft { /// for a section left out (no sources, no reference), and the column's only on an editorial /// sheet, the one style that draws it. fn headings_sent(&self) -> Vec<&str> { - let given = |i: usize| { - let drawn = match i { - 0 => lines(&self.sources).next().is_some(), - 1 => !self.no_reference, - 2 => self.editorial(), - _ => true, - }; - drawn && !self.headings[i].trim().is_empty() - }; + let given = |i: usize| self.left_out(Field::Heading(i)).is_none() && !self.headings[i].trim().is_empty(); let Some(last) = (0..self.headings.len()).rev().find(|&i| given(i)) else { return Vec::new() }; (0..=last) .map(|i| if given(i) { self.headings[i].trim() } else { PUBLICATION_HEADINGS.get(i).copied().unwrap_or_default() }) @@ -223,6 +223,23 @@ impl Draft { self.style == "editorial" } + /// Why the sheet has no place for `field`'s text, if it hasn't: what is sent, what the review + /// says isn't used and which boxes are off all follow from this. + fn left_out(&self, field: Field) -> Option { + match field { + Field::Heading(0) if lines(&self.sources).next().is_none() => Some(LeftOut::NoSources), + Field::Reference | Field::Heading(1) if self.no_reference => Some(LeftOut::NoReference), + Field::Heading(2) if !self.editorial() => Some(LeftOut::NotEditorial), + _ => None, + } + } + + /// Whether `field`'s box is switched off or not shown. The sources' heading stays on with no + /// sources, which may be typed after it. + fn off(&self, field: Field) -> bool { + field == Field::Author && self.no_author || matches!(self.left_out(field), Some(LeftOut::NoReference | LeftOut::NotEditorial)) + } + fn field_mut(&mut self, field: Field) -> &mut String { let [sources, reference, column] = &mut self.headings; match field { @@ -252,13 +269,7 @@ impl Draft { /// Adds a layer statistic to the field last focused on `own`'s step, or to `own` where none was /// or that one is off now; one that would take the field past the limit isn't added. fn add_statistic(&mut self, token: &str, own: Field) { - let on = |f: Field| match f { - Field::Author => !self.no_author, - Field::Reference | Field::Heading(1) => !self.no_reference, - Field::Heading(2) => self.editorial(), - _ => true, - }; - let field = self.targets[own.slot()].filter(|&f| on(f)).unwrap_or(own); + let field = self.targets[own.slot()].filter(|&f| !self.off(f)).unwrap_or(own); let text = self.field_mut(field); if text.chars().count() + token.chars().count() > MAX_PUBLICATION_TEXT { self.refused = Some(field); @@ -290,7 +301,7 @@ fn statistic_menu(ui: &mut egui::Ui, d: &mut Draft, map: &Map, own: Field) { /// done unseen. fn limit_note(ui: &mut egui::Ui, d: &mut Draft, fields: &[Field]) { let refused = d.refused.is_some_and(|f| f.step() == d.step); - if refused || fields.iter().any(|&f| d.field_mut(f).chars().count() >= MAX_PUBLICATION_TEXT) { + if refused || fields.iter().any(|&f| !d.off(f) && d.field_mut(f).chars().count() >= MAX_PUBLICATION_TEXT) { let note = i18n::fmt("Each field takes at most {limit} characters.", &[("limit", &MAX_PUBLICATION_TEXT.to_string())]); ui.label(egui::RichText::new(note).small().weak()); } diff --git a/crates/ui-egui/src/publicationwizard/review.rs b/crates/ui-egui/src/publicationwizard/review.rs index bdd2567c6d..b0ed52b070 100644 --- a/crates/ui-egui/src/publicationwizard/review.rs +++ b/crates/ui-egui/src/publicationwizard/review.rs @@ -28,33 +28,17 @@ pub(super) fn review_step(ui: &mut egui::Ui, d: &Draft) { row(tl!("Note"), or_none(&d.note)); let sources = lines(&d.sources).collect::>().join("\n"); row(tl!("Sources"), or_none(&sources)); - let heading = |i: usize, or: &str| { - let given = d.headings[i].trim(); - if given.is_empty() { or.to_string() } else { given.to_string() } - }; - // A heading typed for a section left out isn't sent: said, not dropped unseen. - let typed_at = |i: usize| Some(d.headings[i].trim()).filter(|h| !h.is_empty()); - if !sources.is_empty() { - row(tl!("Sources heading"), heading(0, PUBLICATION_HEADINGS[0])); - } else if let Some(h) = typed_at(0) { - row(tl!("Sources heading"), i18n::fmt("{heading} (not used: no sources)", &[("heading", h)])); - } + heading_row(&mut row, d, 0, tl!("Sources heading"), PUBLICATION_HEADINGS[0]); let typed = lines(&d.reference).collect::>().join("\n"); - if d.no_reference { - row(tl!("Reference"), none.to_string()); - if let Some(h) = typed_at(1) { - row(tl!("Reference heading"), i18n::fmt("{heading} (not used: no reference)", &[("heading", h)])); - } - } else { - let default = tl!("The default: projection, datum and graticule, filled in on the sheet"); - row(tl!("Reference"), if typed.is_empty() { default.to_string() } else { typed }); - row(tl!("Reference heading"), heading(1, PUBLICATION_HEADINGS[1])); - } - if d.editorial() { - row(tl!("Column heading"), heading(2, none)); - } else if let Some(h) = typed_at(2) { - row(tl!("Column heading"), i18n::fmt("{heading} (not used: not an editorial sheet)", &[("heading", h)])); - } + let reference = match d.left_out(Field::Reference) { + Some(_) if typed.is_empty() => none.to_string(), + Some(_) => tl!("(none; the lines typed aren't used)").to_string(), + None if typed.is_empty() => tl!("The default: projection, datum and graticule, filled in on the sheet").to_string(), + None => typed, + }; + row(tl!("Reference"), reference); + heading_row(&mut row, d, 1, tl!("Reference heading"), PUBLICATION_HEADINGS[1]); + heading_row(&mut row, d, 2, tl!("Column heading"), none); let credit = if d.no_author { none.to_string() } else if d.author.trim().is_empty() { @@ -71,6 +55,21 @@ pub(super) fn review_step(ui: &mut egui::Ui, d: &Draft) { } } +/// A heading's row: the one typed, or `or` for the command's; for a section left out, none, but +/// one typed there is said not to be used rather than dropped unseen. +fn heading_row(row: &mut impl FnMut(&str, String), d: &Draft, at: usize, label: &str, or: &str) { + let typed = d.headings[at].trim(); + let value = match d.left_out(Field::Heading(at)) { + None if typed.is_empty() => or.to_string(), + None => typed.to_string(), + Some(_) if typed.is_empty() => return, + Some(LeftOut::NoSources) => i18n::fmt("{heading} (not used: no sources)", &[("heading", typed)]), + Some(LeftOut::NoReference) => i18n::fmt("{heading} (not used: no reference)", &[("heading", typed)]), + Some(LeftOut::NotEditorial) => i18n::fmt("{heading} (not used: not an editorial sheet)", &[("heading", typed)]), + }; + row(label, value); +} + #[cfg(test)] mod tests { use super::harness::*; diff --git a/crates/ui-egui/src/publicationwizard/sources.rs b/crates/ui-egui/src/publicationwizard/sources.rs index 072d8ff935..fa4b23aea6 100644 --- a/crates/ui-egui/src/publicationwizard/sources.rs +++ b/crates/ui-egui/src/publicationwizard/sources.rs @@ -4,25 +4,21 @@ use super::*; /// The sources step: the sources, the cartographic reference and their headings. pub(super) fn sources_step(ui: &mut egui::Ui, d: &mut Draft, map: &Map) { egui::Grid::new("publication_wizard_sources").num_columns(2).spacing(egui::vec2(8.0, 8.0)).show(ui, |ui| { - list(ui, d, tl!("Sources"), Field::Sources, "", 3, true); - heading(ui, d, tl!("Sources heading"), 0, true); - let on = !d.no_reference; - list(ui, d, tl!("Reference"), Field::Reference, &PUBLICATION_DEFAULT_REFERENCE.join("\n"), 2, on); + list(ui, d, tl!("Sources"), Field::Sources, "", 3); + heading(ui, d, tl!("Sources heading"), 0); + list(ui, d, tl!("Reference"), Field::Reference, &PUBLICATION_DEFAULT_REFERENCE.join("\n"), 2); ui.label(""); ui.checkbox(&mut d.no_reference, tl!("No cartographic reference")); ui.end_row(); - heading(ui, d, tl!("Reference heading"), 1, !d.no_reference); + heading(ui, d, tl!("Reference heading"), 1); }); statistic_menu(ui, d, map, Field::Sources); - let mut fields = vec![Field::Sources, Field::Heading(0)]; - if !d.no_reference { - fields.extend([Field::Reference, Field::Heading(1)]); - } - limit_note(ui, d, &fields); + limit_note(ui, d, &[Field::Sources, Field::Heading(0), Field::Reference, Field::Heading(1)]); } /// A box taking one entry per line, with a note where it holds more than the command takes. -fn list(ui: &mut egui::Ui, d: &mut Draft, label: &str, field: Field, hint: &str, rows: usize, on: bool) { +fn list(ui: &mut egui::Ui, d: &mut Draft, label: &str, field: Field, hint: &str, rows: usize) { + let on = !d.off(field); let caption = ui.label(label); let edit = egui::TextEdit::multiline(d.field_mut(field)) .hint_text(hint) @@ -41,8 +37,9 @@ fn list(ui: &mut egui::Ui, d: &mut Draft, label: &str, field: Field, hint: &str, } /// A section's heading, the command's own as its hint. -fn heading(ui: &mut egui::Ui, d: &mut Draft, label: &str, at: usize, on: bool) { +fn heading(ui: &mut egui::Ui, d: &mut Draft, label: &str, at: usize) { let field = Field::Heading(at); + let on = !d.off(field); let caption = ui.label(label); let edit = egui::TextEdit::singleline(d.field_mut(field)) .hint_text(PUBLICATION_HEADINGS.get(at).copied().unwrap_or_default()) @@ -324,6 +321,42 @@ mod tests { } } + /// Over every way a section is left out, a heading typed is either sent or said not to be + /// used: never neither, never both. + #[test] + fn every_typed_heading_is_sent_or_said_not_to_be_used() { + for sources in ["", "IBGE"] { + for no_reference in [false, true] { + for style in ["classic", "editorial"] { + let mut h = at(Step::Review, |d| { + d.headings = ["H0".into(), "H1".into(), "H2".into()]; + (d.sources, d.no_reference, d.style) = (sources.into(), no_reference, style.into()); + }); + h.run_steps(2); + let sent = wizard(&h).params()["headings"].clone(); + for i in 0..3 { + let typed = format!("H{i}"); + let is_sent = sent.as_array().is_some_and(|a| a.iter().any(|v| v == typed.as_str())); + let said = h.query_by_label_contains(&format!("{typed} (not used")).is_some(); + assert_ne!(is_sent, said, "{typed}: sources {sources:?}, no reference {no_reference}, {style}"); + assert_eq!(h.query_by_label(&typed).is_some(), is_sent, "{typed} listed as it is sent"); + } + } + } + } + } + + /// Reference lines typed and then switched off are said not to be used. + #[test] + fn the_review_says_reference_lines_switched_off_arent_used() { + let said = "(none; the lines typed aren't used)"; + let mut h = at(Step::Review, |d| d.no_reference = true); + assert!(h.query_by_label(said).is_none(), "nothing typed, nothing lost"); + h.state_mut().dialogs.publication.as_mut().unwrap().reference = "UTM 23S".into(); + h.run_steps(4); + assert!(h.query_by_label(said).is_some()); + } + /// Create puts the sources, the reference and the heading given on the sheet, and Undo takes /// it away. #[test] diff --git a/crates/ui-egui/src/publicationwizard/texts.rs b/crates/ui-egui/src/publicationwizard/texts.rs index e0a73a8da9..ebfdcacd80 100644 --- a/crates/ui-egui/src/publicationwizard/texts.rs +++ b/crates/ui-egui/src/publicationwizard/texts.rs @@ -33,7 +33,7 @@ pub(super) fn texts_step(ui: &mut egui::Ui, d: &mut Draft, map: &Map) { let label = ui.label(tl!("Credit line")); let author = ui .add_enabled( - !d.no_author, + !d.off(Field::Author), egui::TextEdit::singleline(&mut d.author) .hint_text(default_credit()) .char_limit(MAX_PUBLICATION_TEXT) @@ -50,14 +50,7 @@ pub(super) fn texts_step(ui: &mut egui::Ui, d: &mut Draft, map: &Map) { } }); statistic_menu(ui, d, map, Field::Note); - let mut fields = vec![Field::Title, Field::Subtitle, Field::Note]; - if !d.no_author { - fields.push(Field::Author); - } - if d.editorial() { - fields.push(Field::Heading(2)); - } - limit_note(ui, d, &fields); + limit_note(ui, d, &[Field::Title, Field::Subtitle, Field::Note, Field::Author, Field::Heading(2)]); } #[cfg(test)] From 00a66628a1a4c15eb63988c3cab3d579db6e2157 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Fri, 27 Nov 2026 10:37:12 -0500 Subject: [PATCH 11/12] fix(ui): keep each step's refused statistic of its own (#3109) --- crates/ui-egui/src/publicationwizard/mod.rs | 38 ++++++++++--------- .../ui-egui/src/publicationwizard/sources.rs | 22 +++++++++++ 2 files changed, 43 insertions(+), 17 deletions(-) diff --git a/crates/ui-egui/src/publicationwizard/mod.rs b/crates/ui-egui/src/publicationwizard/mod.rs index c51791cdb2..8f09d6807e 100644 --- a/crates/ui-egui/src/publicationwizard/mod.rs +++ b/crates/ui-egui/src/publicationwizard/mod.rs @@ -36,6 +36,14 @@ pub enum Step { Review, } +impl Step { + /// Where [`Draft`] keeps what each of the two steps with text fields has of its own: the + /// texts step's at 0, the sources step's at 1. + fn slot(self) -> usize { + usize::from(self == Step::Sources) + } +} + /// Why `layout.publication` draws no place for a field's text. #[derive(Clone, Copy, Debug, PartialEq, Eq)] enum LeftOut { @@ -64,11 +72,6 @@ impl Field { Field::Sources | Field::Reference | Field::Heading(_) => Step::Sources, } } - - /// Where [`Draft::targets`] keeps its step's last field. - fn slot(self) -> usize { - usize::from(self.step() == Step::Sources) - } } /// How a sheet is turned: `Auto` leaves it to `layout.publication` (the way the map comes out larger). @@ -103,10 +106,11 @@ pub struct Draft { /// is left to the command. pub headings: [String; 3], /// The field the cursor was last in on the texts step and on the sources step, which a layer - /// statistic added there goes to ([`Field::slot`]). + /// statistic added there goes to ([`Step::slot`]). targets: [Option; 2], - /// The field the last statistic didn't fit in, said until its step's text changes. - refused: Option, + /// Whether the last statistic added on each of those steps didn't fit its field, said until + /// that step's text changes or one fits there. + refused: [bool; 2], /// The style's colour, or `None` for the style's own. pub accent: Option, /// The colour last picked, which the swatch comes back with when the box is ticked again. @@ -134,7 +138,7 @@ impl Draft { no_reference: false, headings: Default::default(), targets: [None; 2], - refused: None, + refused: [false; 2], accent: None, picked: None, } @@ -259,24 +263,25 @@ impl Draft { /// its step's refusal note when its text changes. fn edited(&mut self, r: &egui::Response, field: Field) { if r.has_focus() { - self.targets[field.slot()] = Some(field); + self.targets[field.step().slot()] = Some(field); } - if r.changed() && self.refused.is_some_and(|f| f.step() == field.step()) { - self.refused = None; + if r.changed() { + self.refused[field.step().slot()] = false; } } /// Adds a layer statistic to the field last focused on `own`'s step, or to `own` where none was /// or that one is off now; one that would take the field past the limit isn't added. fn add_statistic(&mut self, token: &str, own: Field) { - let field = self.targets[own.slot()].filter(|&f| !self.off(f)).unwrap_or(own); + let slot = own.step().slot(); + let field = self.targets[slot].filter(|&f| !self.off(f)).unwrap_or(own); let text = self.field_mut(field); if text.chars().count() + token.chars().count() > MAX_PUBLICATION_TEXT { - self.refused = Some(field); + self.refused[slot] = true; return; } text.push_str(token); - self.refused = None; + self.refused[slot] = false; self.title_typed |= field == Field::Title; } } @@ -300,8 +305,7 @@ fn statistic_menu(ui: &mut egui::Ui, d: &mut Draft, map: &Map, own: Field) { /// The boxes take no more, cut a longer paste to fit and refuse a statistic past it: said, not /// done unseen. fn limit_note(ui: &mut egui::Ui, d: &mut Draft, fields: &[Field]) { - let refused = d.refused.is_some_and(|f| f.step() == d.step); - if refused || fields.iter().any(|&f| !d.off(f) && d.field_mut(f).chars().count() >= MAX_PUBLICATION_TEXT) { + if d.refused[d.step.slot()] || fields.iter().any(|&f| !d.off(f) && d.field_mut(f).chars().count() >= MAX_PUBLICATION_TEXT) { let note = i18n::fmt("Each field takes at most {limit} characters.", &[("limit", &MAX_PUBLICATION_TEXT.to_string())]); ui.label(egui::RichText::new(note).small().weak()); } diff --git a/crates/ui-egui/src/publicationwizard/sources.rs b/crates/ui-egui/src/publicationwizard/sources.rs index fa4b23aea6..93185ff4ef 100644 --- a/crates/ui-egui/src/publicationwizard/sources.rs +++ b/crates/ui-egui/src/publicationwizard/sources.rs @@ -225,6 +225,28 @@ mod tests { assert!(h.query_by_label(&limit).is_some()); } + /// Each step keeps its own refusal: a statistic added or refused on the texts step leaves the + /// sources step's one said. + #[test] + fn a_statistic_on_one_step_leaves_the_others_refusal_said() { + let limit = format!("Each field takes at most {MAX_PUBLICATION_TEXT} characters."); + for note_full in [false, true] { + let full = "x".repeat(MAX_PUBLICATION_TEXT - 3); + let mut h = at(Step::Sources, |d| { + (d.headings[0], d.targets[1]) = (full.clone(), Some(Field::Heading(0))); + if note_full { + (d.subtitle, d.targets[0]) = (full.clone(), Some(Field::Subtitle)); + } + }); + insert_count(&mut h); + click(&mut h, "Back"); + insert_count(&mut h); + assert_eq!(h.query_by_label(&limit).is_some(), note_full, "the texts step says only its own"); + click(&mut h, "Next"); + assert!(h.query_by_label(&limit).is_some(), "note full: {note_full}"); + } + } + /// With nothing edited on the step it goes to the note, or to the sources on their step, a /// field edited on another step left alone. #[test] From 7c6c382d18bf1927e6f59d199d187dcaa824a6a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Fri, 27 Nov 2026 10:51:16 -0500 Subject: [PATCH 12/12] fix(ui): say that a statistic past the limit wasn't added (#3109) --- crates/ui-egui/src/publicationwizard/mod.rs | 13 +++++++++---- crates/ui-egui/src/publicationwizard/sources.rs | 11 ++++++++--- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/crates/ui-egui/src/publicationwizard/mod.rs b/crates/ui-egui/src/publicationwizard/mod.rs index 8f09d6807e..7b9641989e 100644 --- a/crates/ui-egui/src/publicationwizard/mod.rs +++ b/crates/ui-egui/src/publicationwizard/mod.rs @@ -305,10 +305,15 @@ fn statistic_menu(ui: &mut egui::Ui, d: &mut Draft, map: &Map, own: Field) { /// The boxes take no more, cut a longer paste to fit and refuse a statistic past it: said, not /// done unseen. fn limit_note(ui: &mut egui::Ui, d: &mut Draft, fields: &[Field]) { - if d.refused[d.step.slot()] || fields.iter().any(|&f| !d.off(f) && d.field_mut(f).chars().count() >= MAX_PUBLICATION_TEXT) { - let note = i18n::fmt("Each field takes at most {limit} characters.", &[("limit", &MAX_PUBLICATION_TEXT.to_string())]); - ui.label(egui::RichText::new(note).small().weak()); - } + let limit = [("limit", &*MAX_PUBLICATION_TEXT.to_string())]; + let note = if d.refused[d.step.slot()] { + i18n::fmt("The statistic wasn't added: each field takes at most {limit} characters.", &limit) + } else if fields.iter().any(|&f| !d.off(f) && d.field_mut(f).chars().count() >= MAX_PUBLICATION_TEXT) { + i18n::fmt("Each field takes at most {limit} characters.", &limit) + } else { + return; + }; + ui.label(egui::RichText::new(note).small().weak()); } /// A colour as `layout.publication` takes it: `#RRGGBB`. diff --git a/crates/ui-egui/src/publicationwizard/sources.rs b/crates/ui-egui/src/publicationwizard/sources.rs index 93185ff4ef..d059f3d584 100644 --- a/crates/ui-egui/src/publicationwizard/sources.rs +++ b/crates/ui-egui/src/publicationwizard/sources.rs @@ -83,6 +83,11 @@ mod tests { crate::textform::StatLayer::of_map(h.state().session.map()).first().expect("a vector layer").name.clone() } + /// What is said of a statistic that didn't fit its field. + fn refusal() -> String { + format!("The statistic wasn't added: each field takes at most {MAX_PUBLICATION_TEXT} characters.") + } + /// Insert Statistic › the first layer › Count. fn insert_count(h: &mut Wizard) -> String { let name = layer(h); @@ -214,7 +219,7 @@ mod tests { fn a_refused_statistic_stays_said_after_editing_the_other_step() { let full = "x".repeat(MAX_PUBLICATION_TEXT - 3); let mut h = at(Step::Sources, |d| (d.headings[0], d.targets[1]) = (full, Some(Field::Heading(0)))); - let limit = format!("Each field takes at most {MAX_PUBLICATION_TEXT} characters."); + let limit = refusal(); insert_count(&mut h); click(&mut h, "Back"); h.get_by_label("Subtitle").focus(); @@ -229,7 +234,7 @@ mod tests { /// sources step's one said. #[test] fn a_statistic_on_one_step_leaves_the_others_refusal_said() { - let limit = format!("Each field takes at most {MAX_PUBLICATION_TEXT} characters."); + let limit = refusal(); for note_full in [false, true] { let full = "x".repeat(MAX_PUBLICATION_TEXT - 3); let mut h = at(Step::Sources, |d| { @@ -274,7 +279,7 @@ mod tests { let full = "x".repeat(MAX_PUBLICATION_TEXT - 3); // A one-line field: a box this full of text would push the menu out of the step's view. let mut h = at(Step::Sources, |d| (d.headings[0], d.targets[1]) = (full.clone(), Some(Field::Heading(0)))); - let limit = format!("Each field takes at most {MAX_PUBLICATION_TEXT} characters."); + let limit = refusal(); assert!(h.query_by_label(&limit).is_none()); insert_count(&mut h); assert_eq!(wizard(&h).headings[0], full);