diff --git a/crates/engine/src/cmd/layout/publication/mod.rs b/crates/engine/src/cmd/layout/publication/mod.rs index fdd5fd6d22..87e571c581 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_line, datum_and_grid] = PUBLICATION_DEFAULT_REFERENCE; + let line = if step.is_some() { datum_and_grid } else { "Datum: {datum}" }; + 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); @@ -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..3cc3643e87 100644 --- a/crates/engine/src/cmd/layout/publication/sheet.rs +++ b/crates/engine/src/cmd/layout/publication/sheet.rs @@ -58,6 +58,18 @@ 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, 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..a7b449c988 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 -/// 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) { 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/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..7b9641989e 100644 --- a/crates/ui-egui/src/publicationwizard/mod.rs +++ b/crates/ui-egui/src/publicationwizard/mod.rs @@ -1,19 +1,27 @@ -//! 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_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; use serde_json::{Value, json}; use size::size_step; +use sources::sources_step; use style::style_step; use texts::texts_step; @@ -23,10 +31,49 @@ pub enum Step { Size, Style, Texts, + Sources, Accent, 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 { + NoSources, + NoReference, + NotEditorial, +} + +/// 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 +98,19 @@ 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 field the cursor was last in on the texts step and on the sources step, which a layer + /// statistic added there goes to ([`Step::slot`]). + targets: [Option; 2], + /// 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. @@ -74,6 +134,11 @@ impl Draft { sources: String::new(), author: String::new(), no_author: false, + reference: String::new(), + no_reference: false, + headings: Default::default(), + targets: [None; 2], + refused: [false; 2], accent: None, picked: None, } @@ -94,7 +159,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 +186,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 +194,126 @@ impl Draft { if self.no_author { p["author"] = json!(""); } + let sources: Vec<&str> = lines(&self.sources).collect(); + 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); + } 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; 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| 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() }) + .collect() + } + + fn editorial(&self) -> bool { + 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 { + 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 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.step().slot()] = Some(field); + } + 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 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[slot] = true; + return; + } + text.push_str(token); + self.refused[slot] = false; + 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) -> 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 +/// 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 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`. @@ -153,6 +336,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 +423,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 +559,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 +570,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 +579,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 +657,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 +678,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..b0ed52b070 100644 --- a/crates/ui-egui/src/publicationwizard/review.rs +++ b/crates/ui-egui/src/publicationwizard/review.rs @@ -26,7 +26,19 @@ 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).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); + 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() { @@ -43,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 new file mode 100644 index 0000000000..d059f3d584 --- /dev/null +++ b/crates/ui-egui/src/publicationwizard/sources.rs @@ -0,0 +1,410 @@ +//! The wizard's sources and reference step. +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); + 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); + }); + statistic_menu(ui, d, map, Field::Sources); + 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) { + let on = !d.off(field); + 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)).count() > MAX_PUBLICATION_LINES { + ui.label(""); + 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(); + } +} + +/// A section's heading, the command's own as its hint. +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()) + .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() + } + + /// 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); + 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!(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"])); + 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 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() { + 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 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 the cursor was last in, here the subtitle. + #[test] + 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); + let token = insert_count(&mut h); + assert_eq!(wizard(&h).subtitle, format!("In {token}")); + assert!(wizard(&h).note.is_empty()); + } + + /// 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_focused_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); + } + + /// 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 = refusal(); + 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()); + } + + /// 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 = refusal(); + 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] + 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.targets[0] = 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.targets[0] = 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.targets[1]) = (full.clone(), Some(Field::Heading(0)))); + let limit = refusal(); + 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()); + 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(default).is_none()); + 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, 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(), "About".into()]; + d.no_reference = true; + }); + 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, d.style) = ("IBGE".into(), false, "editorial".into()); + h.run_steps(4); + assert!(h.query_by_label_contains("not used").is_none()); + for sent in ["Fontes", "Base", "About"] { + assert!(h.query_by_label(sent).is_some(), "{sent}"); + } + } + + /// 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] + 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..ebfdcacd80 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,36 @@ 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.off(Field::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); + limit_note(ui, d, &[Field::Title, Field::Subtitle, Field::Note, Field::Author, Field::Heading(2)]); } #[cfg(test)] diff --git a/crates/ui-egui/src/textform.rs b/crates/ui-egui/src/textform.rs index 201e50990d..0b19586db0 100644 --- a/crates/ui-egui/src/textform.rs +++ b/crates/ui-egui/src/textform.rs @@ -26,22 +26,22 @@ 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. + /// 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 { 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..4ab757508b 100644 --- a/docs/user-guide/layouts.md +++ b/docs/user-guide/layouts.md @@ -39,16 +39,19 @@ 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, 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 + - **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