From 1cdc7ac03b45e3fef92579c4e8e856e8e0558d38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Fri, 27 Nov 2026 17:05:07 -0500 Subject: [PATCH] feat(ui): the Publication Layout Wizard asks for a figure's cartographic reference (#3131) --- crates/ui-egui/src/publicationwizard/mod.rs | 48 ++++--- .../ui-egui/src/publicationwizard/review.rs | 32 ++--- .../ui-egui/src/publicationwizard/sources.rs | 133 +++++++++++++++--- docs/user-guide/layouts.md | 5 +- 4 files changed, 155 insertions(+), 63 deletions(-) diff --git a/crates/ui-egui/src/publicationwizard/mod.rs b/crates/ui-egui/src/publicationwizard/mod.rs index 6081d3b5f4..a2a13bc740 100644 --- a/crates/ui-egui/src/publicationwizard/mod.rs +++ b/crates/ui-egui/src/publicationwizard/mod.rs @@ -24,7 +24,7 @@ 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 sources::{reference_step, sources_step}; use style::style_step; use texts::texts_step; @@ -36,6 +36,8 @@ pub enum Step { Style, Texts, Sources, + /// A figure's cartographic reference, the one text it draws. + Reference, Accent, Review, } @@ -69,7 +71,7 @@ enum Field { } impl Field { - /// The step that asks for it. + /// The sheet's step that asks for it. fn step(self) -> Step { match self { Field::Title | Field::Subtitle | Field::Note | Field::Author | Field::Heading(2) => Step::Texts, @@ -160,8 +162,9 @@ impl Draft { self.accent.filter(|&c| self.picked.is_some() || c != own) } - /// Whether the size is a figure, which takes no style, texts or accent: the command draws the - /// map edge to edge and leaves the rest to the caption. + /// Whether the size is a figure, which takes no style or accent and no text but its reference: + /// the command draws the map edge to edge, the reference under it, and leaves the rest to the + /// caption. fn figure(&self) -> bool { PUBLICATION_PROFILES.iter().any(|p| !p.sheet && p.id == self.size) } @@ -169,7 +172,7 @@ impl Draft { /// The steps this draft goes through, in order. fn steps(&self) -> &'static [Step] { if self.figure() { - return &[Step::Size, Step::Map, Step::Review]; + return &[Step::Size, Step::Map, Step::Reference, Step::Review]; } &[Step::Size, Step::Map, Step::Style, Step::Texts, Step::Sources, Step::Accent, Step::Review] } @@ -193,6 +196,10 @@ impl Draft { if !self.name.trim().is_empty() { p["name"] = json!(self.name.trim()); } + 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 }); + } if self.figure() { return p; } @@ -210,10 +217,6 @@ impl Draft { if !sources.is_empty() { p["sources"] = json!(sources); } - 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 }); - } let headings = self.headings_sent(); if !headings.is_empty() { p["headings"] = json!(headings); @@ -271,10 +274,11 @@ impl Draft { } } - /// 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. + /// Notes `field` as its step's last one while it has the focus, typed into or not (but on a + /// figure's step, which adds no statistic), and ends its step's refusal note when its text + /// changes. fn edited(&mut self, r: &egui::Response, field: Field) { - if r.has_focus() { + if r.has_focus() && self.step != Step::Reference { self.targets[field.step().slot()] = Some(field); } if r.changed() { @@ -318,7 +322,8 @@ 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 limit = [("limit", &*MAX_PUBLICATION_TEXT.to_string())]; - let note = if d.refused[d.step.slot()] { + // A figure's step adds no statistic: a refusal on the sheet's sources step isn't its own. + let note = if d.step != Step::Reference && 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) @@ -350,6 +355,7 @@ fn step_name(step: Step) -> &'static str { Step::Style => tl_raw!("Style"), Step::Texts => tl_raw!("Texts"), Step::Sources => tl_raw!("Sources and reference"), + Step::Reference => tl_raw!("Reference"), Step::Accent => tl_raw!("Accent"), Step::Review => tl_raw!("Review"), } @@ -363,6 +369,7 @@ fn step_label(step: Step) -> &'static str { Step::Style => tl!("Style"), Step::Texts => tl!("Texts"), Step::Sources => tl!("Sources"), + Step::Reference => tl!("Reference"), Step::Accent => tl!("Accent"), Step::Review => tl!("Review"), } @@ -487,6 +494,7 @@ pub fn show(app: &mut RustGisApp, ctx: &egui::Context) { Step::Style => style_step(ui, &mut d, t.accent), Step::Texts => texts_step(ui, &mut d, app.session.map()), Step::Sources => sources_step(ui, &mut d, app.session.map()), + Step::Reference => reference_step(ui, &mut d), Step::Accent => accent_step(ui, &mut d, t.accent), Step::Review => review_step(ui, &app.session, &d), }); @@ -643,9 +651,9 @@ mod tests { assert_eq!(d.params(), json!({"profile": "figure-1col"})); } - /// A sheet goes through the seven steps; a figure goes from its size to its map and the review, - /// the steps it takes nothing from skipped both ways. Back is off on the first step; Next becomes - /// Create on the last. + /// A sheet goes through the seven steps; a figure goes from its size to its map, its reference + /// and 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] fn a_sheet_takes_every_step_and_a_figure_skips_what_it_doesnt_draw() { let mut app = app(); @@ -664,11 +672,11 @@ mod tests { } h.state_mut().dialogs.publication.as_mut().unwrap().size = "figure-2col".into(); h.run_steps(2); - for want in [Step::Map, Step::Review] { + for want in [Step::Map, Step::Reference, Step::Review] { click(&mut h, "Next"); assert_eq!(step(&h), want); } - for want in [Step::Map, Step::Size] { + for want in [Step::Reference, Step::Map, Step::Size] { click(&mut h, "Back"); assert_eq!(step(&h), want); } @@ -729,7 +737,7 @@ mod tests { /// The names the step list holds, in order, and the one it marks as the current step. fn listed(h: &egui_kittest::Harness<'static, RustGisApp>) -> (Vec<&'static str>, Vec<&'static str>) { let (mut names, mut current) = (Vec::new(), Vec::new()); - for name in ["Size", "Map", "Style", "Texts", "Sources", "Accent", "Review"] { + for name in ["Size", "Map", "Style", "Texts", "Sources", "Reference", "Accent", "Review"] { if let Some(n) = h.query_by_role_and_label(Role::Button, name) { names.push(name); if n.accesskit_node().toggled() == Some(egui::accesskit::Toggled::True) { @@ -770,7 +778,7 @@ mod tests { click(&mut h, "Back"); h.state_mut().dialogs.publication.as_mut().unwrap().size = "figure-1col".into(); h.run_steps(2); - assert_eq!(listed(&h), (vec!["Size", "Map", "Review"], vec!["Size"])); + assert_eq!(listed(&h), (vec!["Size", "Map", "Reference", "Review"], vec!["Size"])); } /// A step clicked in the list is the one shown, first, middle or last, keeping what was diff --git a/crates/ui-egui/src/publicationwizard/review.rs b/crates/ui-egui/src/publicationwizard/review.rs index 0829d50b12..326d25e91b 100644 --- a/crates/ui-egui/src/publicationwizard/review.rs +++ b/crates/ui-egui/src/publicationwizard/review.rs @@ -17,16 +17,7 @@ pub(super) fn review_step(ui: &mut egui::Ui, s: &Session, d: &Draft) { row(tl!("Map extent"), area_label(s, &d.area)); row(tl!("Name"), name_label(s, &d.name)); if d.figure() { - // The figure note sends a sheet's texts to the caption. Its reference doesn't go there - // (the figure draws the default one), so it is said here. - let unused = if d.no_reference { - Some(tl!("\"No cartographic reference\" isn't used: a figure takes the default reference")) - } else { - lines(&d.reference).next().map(|_| tl!("The lines typed aren't used: a figure takes the default reference")) - }; - if let Some(unused) = unused { - row(tl!("Reference"), unused.to_string()); - } + row(tl!("Reference"), reference_value(d)); return; } let turned = match d.orientation { @@ -43,14 +34,7 @@ pub(super) fn review_step(ui: &mut egui::Ui, s: &Session, d: &Draft) { let sources = lines(&d.sources).collect::>().join("\n"); row(tl!("Sources"), or_none(&sources)); heading_row(&mut row, d, 0, tl!("Sources heading"), PUBLICATION_HEADINGS[0]); - let typed = lines(&d.reference).collect::>().join("\n"); - 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); + row(tl!("Reference"), reference_value(d)); 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 { @@ -69,6 +53,18 @@ pub(super) fn review_step(ui: &mut egui::Ui, s: &Session, d: &Draft) { } } +/// The reference as it will be drawn: the lines typed, or the command's default; left out, none, +/// but lines typed then are said not to be used. +fn reference_value(d: &Draft) -> String { + let typed = lines(&d.reference).collect::>().join("\n"); + match d.left_out(Field::Reference) { + Some(_) if typed.is_empty() => tl!("(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, + } +} + /// 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) { diff --git a/crates/ui-egui/src/publicationwizard/sources.rs b/crates/ui-egui/src/publicationwizard/sources.rs index 112c29dc8b..53581ba00d 100644 --- a/crates/ui-egui/src/publicationwizard/sources.rs +++ b/crates/ui-egui/src/publicationwizard/sources.rs @@ -6,22 +6,33 @@ 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); heading(ui, d, tl!("Sources heading"), 0); - list(ui, d, tl!("Reference"), Field::Reference, &PUBLICATION_DEFAULT_REFERENCE.join("\n"), 2); - ui.label(""); - // Wrapped to the column: a long label would widen the narrowed window. - let width = field_width(ui); - ui.horizontal(|ui| { - ui.set_max_width(width); - ui.style_mut().wrap_mode = Some(egui::TextWrapMode::Wrap); - ui.checkbox(&mut d.no_reference, tl!("No cartographic reference")); - }); - ui.end_row(); + reference_rows(ui, d); heading(ui, d, tl!("Reference heading"), 1); }); statistic_menu(ui, d, map, Field::Sources); limit_note(ui, d, &[Field::Sources, Field::Heading(0), Field::Reference, Field::Heading(1)]); } +/// A figure's reference step: the one text it draws, with no heading. +pub(super) fn reference_step(ui: &mut egui::Ui, d: &mut Draft) { + egui::Grid::new("publication_wizard_reference").num_columns(2).spacing(egui::vec2(8.0, 8.0)).show(ui, |ui| reference_rows(ui, d)); + limit_note(ui, d, &[Field::Reference]); +} + +/// The reference's box and the tick that leaves it out, as two rows of a step's grid. +fn reference_rows(ui: &mut egui::Ui, d: &mut Draft) { + list(ui, d, tl!("Reference"), Field::Reference, &PUBLICATION_DEFAULT_REFERENCE.join("\n"), 2); + ui.label(""); + // Wrapped to the column: a long label would widen the narrowed window. + let width = field_width(ui); + ui.horizontal(|ui| { + ui.set_max_width(width); + ui.style_mut().wrap_mode = Some(egui::TextWrapMode::Wrap); + ui.checkbox(&mut d.no_reference, tl!("No cartographic reference")); + }); + ui.end_row(); +} + /// 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) { let on = !d.off(field); @@ -158,14 +169,62 @@ mod tests { assert_eq!(d.params()["headings"], json!([PUBLICATION_HEADINGS[0], PUBLICATION_HEADINGS[1], "Col"])); } - /// A figure takes none of them. + /// A figure takes the reference, but no sources or headings. #[test] - fn a_figure_takes_no_sources_reference_or_headings() { + fn a_figure_takes_the_reference_but_no_sources_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"})); + (d.sources, d.reference) = ("A".into(), "UTM 23S\n\n X ".into()); + d.headings = ["S".into(), "R".into(), "C".into()]; + assert_eq!(d.params(), json!({"profile": "figure-1col", "reference": ["UTM 23S", "X"]})); + d.no_reference = true; + assert_eq!(d.params(), json!({"profile": "figure-1col", "reference": []})); + d.size = "a4".into(); + d.no_reference = false; + assert_eq!(d.params()["reference"], json!(["UTM 23S", "X"]), "kept for the sheet"); + } + + /// A figure's step asks for the reference alone: no sources, no headings, no statistic menu. + #[test] + fn a_figures_step_asks_for_the_reference_alone() { + let mut h = at(Step::Reference, |d| d.size = "figure-1col".into()); + for label in ["Sources", "Sources heading", "Reference heading"] { + assert!(h.query_by_role_and_label(Role::Label, label).is_none(), "{label}"); + } + assert!(h.query_by_label("Insert Statistic").is_none()); + assert!(!h.get_by_role_and_label(Role::MultilineTextInput, "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_role_and_label(Role::MultilineTextInput, "Reference").accesskit_node().is_disabled()); + } + + /// The figure's step says the command's limits, and not a statistic refused on the sheet's + /// sources step. + #[test] + fn a_figures_step_says_its_limits_only() { + let mut h = at(Step::Reference, |d| { + d.size = "figure-1col".into(); + d.refused = [false, true]; + }); + assert!(h.query_by_label(&refusal()).is_none()); + assert!(h.query_by_label("At most 50 lines.").is_none()); + h.state_mut().dialogs.publication.as_mut().unwrap().reference = "a\n".repeat(51); + h.run_steps(4); + assert!(h.query_by_label("At most 50 lines.").is_some()); + h.state_mut().dialogs.publication.as_mut().unwrap().reference = "x".repeat(MAX_PUBLICATION_TEXT); + h.run_steps(4); + assert!(h.query_by_label(&format!("Each field takes at most {MAX_PUBLICATION_TEXT} characters.")).is_some()); + } + + /// The cursor put in the reference on a figure's step leaves where the sheet's statistic goes. + #[test] + fn a_figures_step_leaves_the_sheets_statistic_target() { + let mut h = at(Step::Reference, |d| d.size = "figure-1col".into()); + h.get_by_role_and_label(Role::MultilineTextInput, "Reference").focus(); + h.run_steps(2); + assert_eq!(wizard(&h).targets, [None, None]); } /// The step has its fields, and No cartographic reference turns the reference's box off. @@ -392,20 +451,48 @@ mod tests { assert!(h.query_by_label(said).is_some()); } - /// A figure takes the command's default reference: the review says the lines or the tick set - /// on a sheet aren't used, and says nothing where neither was set. + /// A figure's review lists its reference as a sheet's does: the default, the lines, none, and + /// lines typed and then switched off said not to be used; no headings. #[test] - fn a_figures_review_says_the_sheets_reference_isnt_used() { - let typed = "The lines typed aren't used: a figure takes the default reference"; - let tick = "\"No cartographic reference\" isn't used: a figure takes the default reference"; - let mut h = at(Step::Review, |d| d.size = "figure-1col".into()); - assert!(h.query_by_label_contains("default reference").is_none(), "nothing set, nothing lost"); + fn a_figures_review_lists_its_reference() { + let default = "The default: projection, datum and graticule, filled in on the sheet"; + let unused = "(none; the lines typed aren't used)"; + let mut h = at(Step::Review, |d| { + d.size = "figure-1col".into(); + d.headings[1] = "Ref".into(); + }); + assert!(h.query_by_label(default).is_some() && h.query_by_label_contains("Ref (not used").is_none()); h.state_mut().dialogs.publication.as_mut().unwrap().reference = "UTM 23S".into(); h.run_steps(4); - assert!(h.query_by_label(typed).is_some() && h.query_by_label(tick).is_none()); + assert!(h.query_by_label("UTM 23S").is_some() && h.query_by_label(default).is_none()); h.state_mut().dialogs.publication.as_mut().unwrap().no_reference = true; h.run_steps(4); - assert!(h.query_by_label(tick).is_some() && h.query_by_label(typed).is_none()); + assert!(h.query_by_label(unused).is_some() && h.query_by_label("UTM 23S").is_none()); + h.state_mut().dialogs.publication.as_mut().unwrap().reference.clear(); + h.run_steps(4); + assert!(h.query_by_label("(none)").is_some() && h.query_by_label(unused).is_none()); + } + + /// Create puts a figure's reference under its map, or makes it with none, and Undo takes it + /// away. + #[test] + fn create_puts_a_figures_reference_on_it() { + for (no_reference, want) in [(false, "UTM 23S"), (true, "")] { + let mut h = at(Step::Review, |d| { + (d.size, d.reference, d.no_reference) = ("figure-1col".into(), "UTM 23S".into(), no_reference); + }); + let before = h.state().session.project.layouts.len(); + click(&mut h, "Create"); + assert_eq!(h.state().session.project.layouts.len(), before + 1); + let layout = h.state().session.project.layouts.last().unwrap(); + let text = layout.elements.iter().find(|e| e.name == "Reference").and_then(|e| match &e.kind { + ElementKind::Text { text, .. } => Some(text.as_str()), + _ => None, + }); + assert_eq!(text, Some(want)); + h.state_mut().run("edit.undo", Value::Null).unwrap(); + assert_eq!(h.state().session.project.layouts.len(), before); + } } /// Create puts the sources, the reference and the heading given on the sheet, and Undo takes diff --git a/docs/user-guide/layouts.md b/docs/user-guide/layouts.md index b69b00760b..f1e76c3e16 100644 --- a/docs/user-guide/layouts.md +++ b/docs/user-guide/layouts.md @@ -54,8 +54,9 @@ Layouts open as tabs next to the maps; while one is open, its groups lead the Pu 0.01°, and what lies past ±180° or ±90° is left out of the frame; an area with nothing to frame, one gone by Create, or one picked before the map or the project was switched or the map renamed, is said and nothing is made); without a name the layout is `Publication`; the review says when a - layout has that name, so the new one is numbered. A figure goes from its size to its map and the - review, as it takes no style, texts or accent. A field left empty is left out (for the credit + layout has that name, so the new one is numbered. A figure goes from its size to its map, its + reference (each line typed; with no heading, and it can be left out) and the review, as it takes + no style, accent or other text. 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 window can be resized. Its steps are listed on the left, and a click goes to one; a