From 09c75b6054396dc51abf4fc77150634234a636dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Fri, 27 Nov 2026 07:01:17 -0500 Subject: [PATCH 1/7] feat(ui): the Publication Layout Wizard asks which corner each surround takes (#3108) --- .../src/cmd/layout/publication/arrangement.rs | 6 +- .../ui-egui/src/publicationwizard/accent.rs | 5 + .../ui-egui/src/publicationwizard/arrange.rs | 385 ++++++++++++++++++ crates/ui-egui/src/publicationwizard/mod.rs | 53 ++- .../ui-egui/src/publicationwizard/review.rs | 2 + crates/ui-egui/src/publicationwizard/texts.rs | 5 +- docs/user-guide/layouts.md | 11 +- 7 files changed, 446 insertions(+), 21 deletions(-) create mode 100644 crates/ui-egui/src/publicationwizard/arrange.rs diff --git a/crates/engine/src/cmd/layout/publication/arrangement.rs b/crates/engine/src/cmd/layout/publication/arrangement.rs index d0a77a4e2f..6bd69eb759 100644 --- a/crates/engine/src/cmd/layout/publication/arrangement.rs +++ b/crates/engine/src/cmd/layout/publication/arrangement.rs @@ -12,10 +12,10 @@ pub const ARRANGEMENTS: [(&str, Homes); 4] = [("classic", [0, 1, 2, 3]), ("mirrored", [1, 0, 3, 2]), ("legendRight", [0, 1, 3, 2]), ("legendTop", [2, 1, 0, 3])]; /// The keys of an arrangement given surround by surround, in [`Homes`]'s order. -pub(in crate::cmd::layout) const ARRANGEMENT_KEYS: [&str; 4] = ["locator", "northArrow", "legend", "scaleBar"]; +pub const ARRANGEMENT_KEYS: [&str; 4] = ["locator", "northArrow", "legend", "scaleBar"]; /// The corners by name, in [`Homes`]'s numbering. -pub(in crate::cmd::layout) const CORNER_NAMES: [&str; 4] = ["top-left", "top-right", "bottom-left", "bottom-right"]; +pub const CORNER_NAMES: [&str; 4] = ["top-left", "top-right", "bottom-left", "bottom-right"]; /// A surround's place in [`Homes`]. pub(in crate::cmd::layout) fn home_slot(kind: Surround) -> usize { @@ -141,7 +141,7 @@ pub(in crate::cmd::layout) fn arrangement_label(v: &Value, homes: Homes, saved: } /// The corners of an arrangement, by surround. -pub(in crate::cmd::layout) fn corners_of(homes: Homes) -> Value { +pub fn corners_of(homes: Homes) -> Value { Value::Object(ARRANGEMENT_KEYS.iter().zip(homes).map(|(k, h)| ((*k).to_string(), json!(CORNER_NAMES[h]))).collect()) } 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/arrange.rs b/crates/ui-egui/src/publicationwizard/arrange.rs new file mode 100644 index 0000000000..c6921883c6 --- /dev/null +++ b/crates/ui-egui/src/publicationwizard/arrange.rs @@ -0,0 +1,385 @@ +//! The wizard's placement step: which corner each surround takes. +use super::*; +use rustgis_engine::cmd::layout::{ARRANGEMENTS, Homes, corners_of, parse_arrangement, usable_saved_arrangement}; + +/// The arrangement `layout.publication` is asked for. +#[derive(Clone, Debug, PartialEq, Eq)] +pub enum Arrangement { + /// The command's default. + Best, + Favourite, + /// A built-in or saved arrangement, by name. + Named(String), + /// A corner for each surround. + Custom(Homes), +} + +impl Arrangement { + /// The command's `"arrangement"`, or `None` to leave it to the command. + pub(super) fn value(&self) -> Option { + match self { + Arrangement::Best => None, + Arrangement::Favourite => Some(json!("favourite")), + Arrangement::Named(name) => Some(json!(name)), + Arrangement::Custom(homes) => Some(corners_of(*homes)), + } + } + + /// What making this the favourite saves: an arrangement chosen by name or corner by corner; + /// `best` and the favourite itself aren't one. + pub(super) fn as_favourite(&self) -> Option { + matches!(self, Arrangement::Named(_) | Arrangement::Custom(_)).then(|| self.value()).flatten() + } + + /// Its name, as the review says it. + pub(super) fn label(&self) -> String { + match self { + Arrangement::Best => tl!("Best").to_string(), + Arrangement::Favourite => tl!("Favourite").to_string(), + Arrangement::Named(name) => i18n::display(built_in(name).unwrap_or(name)), + Arrangement::Custom(_) => tl!("Custom").to_string(), + } + } + + /// The corners it gives, or `None` for `best`, which the command picks against the map. + fn homes(&self, s: &Session) -> Option { + match self { + Arrangement::Best => None, + Arrangement::Favourite => Some(favourite_homes(s)), + Arrangement::Named(name) => parse_arrangement(&json!(name), &s.layout_arrangements).ok(), + Arrangement::Custom(homes) => Some(*homes), + } + } +} + +/// A built-in arrangement's name as the step shows it, in logical order. +fn built_in(name: &str) -> Option<&'static str> { + let labels = [tl_raw!("Classic"), tl_raw!("Mirrored"), tl_raw!("Legend right"), tl_raw!("Legend top")]; + ARRANGEMENTS.iter().zip(labels).find(|((n, _), _)| n.eq_ignore_ascii_case(name.trim())).map(|(_, label)| label) +} + +/// The favourite's corners; one that can't be read is `classic`. +fn favourite_homes(s: &Session) -> Homes { + parse_arrangement(&s.layout_favourite, &s.layout_arrangements).unwrap_or(ARRANGEMENTS[0].1) +} + +/// The favourite as its option names it. +fn favourite_label(s: &Session) -> String { + let name = s.layout_favourite.as_str().map_or(tl_raw!("custom corners"), |n| built_in(n).unwrap_or(n)); + i18n::fmt("Favourite: {name}", &[("name", name)]) +} + +/// The corners' names, in [`Homes`]'s numbering. +fn corner_labels() -> [&'static str; 4] { + [tl_raw!("Top left"), tl_raw!("Top right"), tl_raw!("Bottom left"), tl_raw!("Bottom right")] +} + +/// The surrounds' names, in [`Homes`]'s order. +fn surround_labels() -> [&'static str; 4] { + [tl_raw!("Locator"), tl_raw!("North arrow"), tl_raw!("Legend"), tl_raw!("Scale bar")] +} + +/// The placement step: the arrangements to pick from, and what goes in each corner. +pub(super) fn arrange_step(ui: &mut egui::Ui, s: &Session, d: &mut Draft) { + let mut option = |ui: &mut egui::Ui, choice: Arrangement, label: &str| { + let response = ui.radio(d.arrangement == choice, label); + if response.clicked() { + d.arrangement = choice; + } + response + }; + ui.horizontal_wrapped(|ui| { + option(ui, Arrangement::Best, tl!("Best")) + .on_hover_text(tl!("The arrangement that moves the surrounds least off their corners and covers the map least.")); + option(ui, Arrangement::Favourite, &favourite_label(s)); + }); + ui.horizontal_wrapped(|ui| { + for (name, _) in ARRANGEMENTS { + let label = i18n::display(built_in(name).unwrap_or(name)); + option(ui, Arrangement::Named(name.into()), &label); + } + // Those saved with `layout.arrangement` that this version reads, under their own names. + for (name, _) in s.layout_arrangements.iter().filter(|(n, c)| usable_saved_arrangement(n, c)) { + option(ui, Arrangement::Named(name.clone()), &i18n::display(name)); + } + }); + let custom = matches!(d.arrangement, Arrangement::Custom(_)); + if ui.radio(custom, tl!("Custom")).clicked() && !custom { + d.arrangement = Arrangement::Custom(d.arrangement.homes(s).unwrap_or_else(|| favourite_homes(s))); + } + if let Arrangement::Custom(homes) = &mut d.arrangement { + corner_pickers(ui, homes); + } + if let Some(homes) = d.arrangement.homes(s) { + ui.add_space(4.0); + egui::Grid::new("publication_wizard_corners").num_columns(2).spacing(egui::vec2(24.0, 6.0)).show(ui, |ui| { + for (corner, name) in corner_labels().into_iter().enumerate() { + if let Some(surround) = homes.iter().position(|&h| h == corner) { + let values = [("corner", name), ("surround", surround_labels()[surround])]; + ui.group(|ui| ui.label(i18n::fmt("{corner}: {surround}", &values))); + } + if corner % 2 == 1 { + ui.end_row(); + } + } + }); + } + // The styles with a column keep the locator and legend in it (`cmd/layout/publication`). + if !d.figure() && matches!(d.style.as_str(), "panel" | "editorial" | "modular") { + let note = tl!("The locator and legend sit in this style's column: only the north arrow and scale bar take these corners."); + ui.label(egui::RichText::new(note).small().weak()); + } + ui.add_space(4.0); + ui.add_enabled_ui(d.arrangement.as_favourite().is_some(), |ui| { + ui.checkbox(&mut d.make_favourite, tl!("Make this my favourite")) + .on_hover_text(tl!("Create also keeps it with the app's preferences as the favourite arrangement.")); + }); +} + +/// A corner for each surround; one picked that another has swaps the two, so each keeps a corner +/// of its own. +fn corner_pickers(ui: &mut egui::Ui, homes: &mut Homes) { + egui::Grid::new("publication_wizard_custom").num_columns(2).spacing(egui::vec2(8.0, 6.0)).show(ui, |ui| { + for (surround, name) in surround_labels().into_iter().enumerate() { + let label = ui.label(i18n::display(name)); + let corners = corner_labels(); + egui::ComboBox::from_id_salt(("publication_wizard_corner", surround)) + .selected_text(i18n::display(corners[homes[surround]])) + .width(field_width(ui)) + .show_ui(ui, |ui| { + for (corner, name) in corners.into_iter().enumerate() { + if ui.selectable_label(homes[surround] == corner, i18n::display(name)).clicked() + && let Some(other) = homes.iter().position(|&h| h == corner) + { + homes.swap(surround, other); + } + } + }) + .response + .labelled_by(label.id); + ui.end_row(); + } + }); +} + +#[cfg(test)] +mod tests { + use super::super::harness::*; + use super::*; + use egui::accesskit::Role; + use egui_kittest::kittest::{NodeT, Queryable}; + use rustgis_engine::cmd::layout::{ARRANGEMENTS, parse_arrangement}; + + type Wizard = egui_kittest::Harness<'static, RustGisApp>; + + /// The wizard on its placement step. + fn placement(prepare: impl FnOnce(&mut RustGisApp)) -> Wizard { + let mut app = app(); + open(&mut app); + app.dialogs.publication.as_mut().unwrap().step = Step::Placement; + prepare(&mut app); + harness(app) + } + + fn draft(h: &Wizard) -> &Draft { + h.state().dialogs.publication.as_ref().expect("the wizard is open") + } + + fn pick(h: &mut Wizard, label: &str) { + h.get_by_role_and_label(Role::RadioButton, label).click(); + h.run_steps(4); + } + + /// What the 2 × 2 grid says, corner by corner. + fn shown(h: &Wizard, text: &str) -> bool { + h.query_by_label(text).is_some() + } + + /// A new draft asks for no arrangement, as before the step, and makes no favourite. + #[test] + fn a_new_draft_leaves_the_arrangement_to_the_command() { + let app = app(); + let d = Draft::new(&app.session); + assert_eq!((d.arrangement.clone(), d.make_favourite), (Arrangement::Best, false)); + assert!(d.params().get("arrangement").is_none()); + } + + /// A sheet and a figure both send the arrangement chosen. + #[test] + fn the_arrangement_chosen_is_sent_for_a_sheet_and_a_figure() { + let app = app(); + for size in ["a4", "figure-1col"] { + let mut d = Draft::new(&app.session); + d.size = size.into(); + d.arrangement = Arrangement::Named("mirrored".into()); + assert_eq!(d.params()["arrangement"], "mirrored", "{size}"); + d.arrangement = Arrangement::Favourite; + assert_eq!(d.params()["arrangement"], "favourite", "{size}"); + } + } + + /// Each arrangement by name sends its name and shows its corners. + #[test] + fn each_built_in_arrangement_sends_its_name_and_shows_its_corners() { + let mut h = placement(|_| {}); + for ((name, homes), label) in ARRANGEMENTS.iter().zip(["Classic", "Mirrored", "Legend right", "Legend top"]) { + pick(&mut h, label); + assert_eq!(draft(&h).params()["arrangement"], *name); + for (surround, corner) in ["Locator", "North arrow", "Legend", "Scale bar"].iter().zip(homes) { + let corner = ["Top left", "Top right", "Bottom left", "Bottom right"][*corner]; + assert!(shown(&h, &format!("{corner}: {surround}")), "{name}: {surround} at {corner}"); + } + } + } + + /// The favourite is named: classic unset, a name, a saved one, or corners of its own. + #[test] + fn the_favourite_is_listed_with_its_name() { + let h = placement(|_| {}); + assert!(h.query_by_role_and_label(Role::RadioButton, "Favourite: Classic").is_some()); + let own = json!({"locator": "bottom-right", "northArrow": "top-left", "legend": "top-right", "scaleBar": "bottom-left"}); + for (favourite, label) in [(json!("mirrored"), "Favourite: Mirrored"), (own, "Favourite: custom corners")] { + let mut h = placement(|app| app.session.layout_favourite = favourite); + pick(&mut h, label); + assert_eq!(draft(&h).params()["arrangement"], "favourite"); + } + } + + /// Each saved arrangement is listed under its name; with none saved, there is nothing more. + #[test] + fn saved_arrangements_are_listed_by_name() { + let corners = json!({"locator": "bottom-right", "northArrow": "top-left", "legend": "top-right", "scaleBar": "bottom-left"}); + let h = placement(|_| {}); + assert!(h.query_by_role_and_label(Role::RadioButton, "Atlas").is_none()); + let mut h = placement(|app| { + app.session.layout_arrangements.insert("Atlas".into(), corners.clone()); + }); + pick(&mut h, "Atlas"); + assert_eq!(draft(&h).params()["arrangement"], "Atlas"); + assert!(shown(&h, "Top right: Legend")); + } + + /// Custom starts from the corners of what was selected: the favourite's for Best and + /// Favourite. + #[test] + fn custom_starts_from_the_corners_selected() { + let mut h = placement(|app| app.session.layout_favourite = json!("mirrored")); + pick(&mut h, "Custom"); + assert_eq!(draft(&h).arrangement, Arrangement::Custom(ARRANGEMENTS[1].1), "from Best: the favourite's"); + pick(&mut h, "Legend top"); + pick(&mut h, "Custom"); + assert_eq!(draft(&h).arrangement, Arrangement::Custom(ARRANGEMENTS[3].1)); + let params = draft(&h).params(); + assert_eq!(parse_arrangement(¶ms["arrangement"], &Default::default()), Ok(ARRANGEMENTS[3].1)); + } + + /// Giving a surround a corner another has swaps the two, whichever corner it is. + #[test] + fn picking_a_taken_corner_swaps_the_two_surrounds() { + for (corner, name) in ["Top left", "Top right", "Bottom left", "Bottom right"].iter().enumerate() { + let mut h = placement(|app| app.dialogs.publication.as_mut().unwrap().arrangement = Arrangement::Custom([0, 1, 2, 3])); + // The legend (at 2) is given each corner in turn. + h.get_by_role_and_label(Role::ComboBox, "Legend").click(); + h.run_steps(4); + h.get_by_role_and_label(Role::Button, name).click(); + h.run_steps(4); + let mut want = [0, 1, 2, 3]; + want.swap(2, corner); + assert_eq!(draft(&h).arrangement, Arrangement::Custom(want), "{name}"); + } + } + + /// The styles with a column say that the locator and legend sit in it. + #[test] + fn column_styles_say_which_surrounds_take_the_corners() { + for (style, column) in + [("classic", false), ("banner", false), ("panel", true), ("editorial", true), ("modular", true), ("poster", false)] + { + let h = placement(|app| app.dialogs.publication.as_mut().unwrap().style = style.into()); + assert_eq!(h.query_by_label_contains("sit in this style's column").is_some(), column, "{style}"); + } + let h = placement(|app| { + let d = app.dialogs.publication.as_mut().unwrap(); + (d.style, d.size) = ("panel".into(), "figure-1col".into()); + }); + assert!(h.query_by_label_contains("sit in this style's column").is_none(), "a figure has no column"); + } + + /// Only a chosen arrangement can be made the favourite. + #[test] + fn make_favourite_is_off_for_best_and_favourite() { + let mut h = placement(|_| {}); + let off = |h: &Wizard| h.get_by_role_and_label(Role::CheckBox, "Make this my favourite").accesskit_node().is_disabled(); + assert!(off(&h), "Best"); + pick(&mut h, "Favourite: Classic"); + assert!(off(&h), "Favourite"); + pick(&mut h, "Mirrored"); + assert!(!off(&h)); + pick(&mut h, "Custom"); + assert!(!off(&h)); + } + + /// The wizard on its review, with `arrangement` to be made the favourite. + fn creating(arrangement: Arrangement, prepare: impl FnOnce(&mut Draft)) -> Wizard { + let mut app = app(); + open(&mut app); + let d = app.dialogs.publication.as_mut().unwrap(); + (d.step, d.arrangement, d.make_favourite) = (Step::Review, arrangement, true); + prepare(d); + harness(app) + } + + /// Create sets the favourite, by name or by corners; Undo takes the layout, not the + /// favourite. + #[test] + fn create_makes_the_chosen_arrangement_the_favourite() { + let custom = [3, 0, 1, 2]; + for (arrangement, want) in [ + (Arrangement::Named("mirrored".into()), json!("mirrored")), + (Arrangement::Custom(custom), rustgis_engine::cmd::layout::corners_of(custom)), + ] { + let mut h = creating(arrangement, |_| {}); + let before = h.state().session.project.layouts.len(); + click(&mut h, "Create"); + assert_eq!(h.state().session.project.layouts.len(), before + 1); + assert_eq!(h.state().session.layout_favourite, want); + assert_eq!(h.state().ui.tab, "Publish"); + h.state_mut().run("edit.undo", Value::Null).unwrap(); + assert_eq!(h.state().session.project.layouts.len(), before); + assert_eq!(h.state().session.layout_favourite, want, "a preference, not undone"); + } + } + + /// A flag left ticked behind Best or Favourite sets nothing. + #[test] + fn create_leaves_the_favourite_for_best_and_favourite() { + for arrangement in [Arrangement::Best, Arrangement::Favourite] { + let mut h = creating(arrangement, |_| {}); + click(&mut h, "Create"); + assert_eq!(h.state().session.layout_favourite, json!("classic")); + } + } + + /// A layout the command refuses changes no favourite and keeps the wizard open: an unknown + /// style, or a saved arrangement removed meanwhile. + #[test] + fn a_refused_layout_leaves_the_favourite() { + for (arrangement, style) in [(Arrangement::Named("mirrored".into()), "unknown"), (Arrangement::Named("Gone".into()), "classic")] { + let mut h = creating(arrangement, |d| d.style = style.into()); + let before = h.state().session.project.layouts.len(); + click(&mut h, "Create"); + assert_eq!(h.state().session.project.layouts.len(), before, "nothing made"); + assert_eq!(h.state().session.layout_favourite, json!("classic")); + assert_eq!(h.state().dialogs.open, Some("publicationWizard")); + } + } + + /// The review says the placement, of a sheet and of a figure. + #[test] + fn the_review_says_the_placement() { + for size in ["a4", "figure-1col"] { + let h = creating(Arrangement::Named("legendTop".into()), |d| d.size = size.into()); + assert!(h.query_by_label("Legend top").is_some(), "{size}"); + } + } +} diff --git a/crates/ui-egui/src/publicationwizard/mod.rs b/crates/ui-egui/src/publicationwizard/mod.rs index 3d8a806404..a834b7dc0d 100644 --- a/crates/ui-egui/src/publicationwizard/mod.rs +++ b/crates/ui-egui/src/publicationwizard/mod.rs @@ -1,6 +1,7 @@ -//! Publication Layout Wizard: `layout.publication` asked step by step (size, style, texts, accent), +//! Publication Layout Wizard: `layout.publication` asked step by step (size, style, placement, texts, accent), //! then made at once, as the New Layout › Publication Layout menu makes it (#2850). mod accent; +mod arrange; mod review; mod size; mod style; @@ -8,6 +9,7 @@ mod texts; use crate::{RustGisApp, i18n, theme::Tokens}; use accent::accent_step; +use arrange::{Arrangement, arrange_step}; use review::review_step; use rustgis_engine::Session; use rustgis_engine::cmd::layout::{PUBLICATION_PROFILES, publication_style_accent}; @@ -22,6 +24,7 @@ use texts::texts_step; pub enum Step { Size, Style, + Placement, Texts, Accent, Review, @@ -55,6 +58,10 @@ pub struct Draft { pub accent: Option, /// The colour last picked, which the swatch comes back with when the box is ticked again. picked: Option, + /// The corners the surrounds take. + pub arrangement: Arrangement, + /// Whether Create also sets a chosen arrangement as the favourite. + pub make_favourite: bool, } impl Draft { @@ -76,6 +83,8 @@ impl Draft { no_author: false, accent: None, picked: None, + arrangement: Arrangement::Best, + make_favourite: false, } } @@ -94,7 +103,11 @@ 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() { + &[Step::Size, Step::Placement, Step::Review] + } else { + &[Step::Size, Step::Style, Step::Placement, Step::Texts, Step::Accent, Step::Review] + } } /// The step `by` places from this one, if there is one. @@ -113,6 +126,9 @@ impl Draft { (false, Orientation::Landscape) => format!("{}-landscape", self.size), }; let mut p = json!({"profile": profile}); + if let Some(arrangement) = self.arrangement.value() { + p["arrangement"] = arrangement; + } if self.figure() { return p; } @@ -152,6 +168,7 @@ fn step_name(step: Step) -> &'static str { match step { Step::Size => tl_raw!("Size"), Step::Style => tl_raw!("Style"), + Step::Placement => tl_raw!("Placement"), Step::Texts => tl_raw!("Texts"), Step::Accent => tl_raw!("Accent"), Step::Review => tl_raw!("Review"), @@ -239,6 +256,7 @@ 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::Placement => arrange_step(ui, &app.session, &mut d), Step::Texts => texts_step(ui, &mut d), Step::Accent => accent_step(ui, &mut d, t.accent), Step::Review => review_step(ui, &d), @@ -268,6 +286,13 @@ pub fn show(app: &mut RustGisApp, ctx: &egui::Context) { // A layout the command refuses is said (a map with no extent), and the wizard stays. if create && crate::ribbon::make_publication(app, d.params()) { close = true; + // Only once the layout is made: a refused one changes no preference. + if d.make_favourite + && let Some(favourite) = d.arrangement.as_favourite() + && let Err(e) = app.run("layout.arrangement", json!({"favourite": favourite})) + { + app.session.notify(e, true); + } } if !open || close { app.dialogs.open = None; @@ -385,8 +410,8 @@ 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 - /// it takes nothing from skipped both ways. Back is off on the first step; Next becomes + /// A sheet goes through the six steps; a figure goes from its size to its placement 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() { @@ -394,22 +419,26 @@ 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::Placement, Step::Texts, 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::Texts, Step::Placement, Step::Style, Step::Size] { click(&mut h, "Back"); assert_eq!(step(&h), want); } h.state_mut().dialogs.publication.as_mut().unwrap().size = "figure-2col".into(); h.run_steps(2); - click(&mut h, "Next"); - assert_eq!(step(&h), Step::Review); - click(&mut h, "Back"); - assert_eq!(step(&h), Step::Size); + for want in [Step::Placement, Step::Review] { + click(&mut h, "Next"); + assert_eq!(step(&h), want); + } + for want in [Step::Placement, Step::Size] { + click(&mut h, "Back"); + assert_eq!(step(&h), want); + } } /// Create makes the layout in one step, closes the wizard and opens the Publish tab, as the @@ -472,7 +501,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 +522,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..3d7a00a9c2 100644 --- a/crates/ui-egui/src/publicationwizard/review.rs +++ b/crates/ui-egui/src/publicationwizard/review.rs @@ -13,6 +13,7 @@ pub(super) fn review_step(ui: &mut egui::Ui, d: &Draft) { }; row(tl!("Size"), size_label(&d.size)); if d.figure() { + row(tl!("Placement"), d.arrangement.label()); return; } let turned = match d.orientation { @@ -23,6 +24,7 @@ pub(super) fn review_step(ui: &mut egui::Ui, d: &Draft) { row(tl!("Orientation"), turned.to_string()); let style = crate::ribbon::publication_style(&d.style).map(|s| s.0.to_string()).unwrap_or_else(|| d.style.clone()); row(tl!("Style"), style); + row(tl!("Placement"), d.arrangement.label()); row(tl!("Title"), or_none(&d.title)); row(tl!("Subtitle"), or_none(&d.subtitle)); row(tl!("Note"), or_none(&d.note)); diff --git a/crates/ui-egui/src/publicationwizard/texts.rs b/crates/ui-egui/src/publicationwizard/texts.rs index 89c960fb91..4193fcf312 100644 --- a/crates/ui-egui/src/publicationwizard/texts.rs +++ b/crates/ui-egui/src/publicationwizard/texts.rs @@ -70,8 +70,9 @@ mod tests { h.state_mut().run("map.new", json!({"name": "Rivers"})).unwrap(); h.run_steps(2); assert_eq!(h.state().dialogs.publication.as_ref().unwrap().title, "Rivers"); - click(&mut h, "Next"); - click(&mut h, "Next"); + for _ in 0..3 { + click(&mut h, "Next"); + } h.get_by_label("Title").focus(); h.run_steps(1); h.get_by_label("Title").type_text(" basins"); diff --git a/docs/user-guide/layouts.md b/docs/user-guide/layouts.md index 84beb6364e..f5f395a307 100644 --- a/docs/user-guide/layouts.md +++ b/docs/user-guide/layouts.md @@ -43,10 +43,13 @@ Layouts open as tabs next to the maps; while one is open, its groups lead the Pu 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 + a click on the outline picks the style), the placement, 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. The + **placement** is the arrangement (below): `best`, the favourite, one by name or one saved, or + **Custom**, a corner for each surround (a corner another has swaps the two); a chosen one can + be made the favourite, once the layout is made. A figure goes from its size to its placement + and 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. From 87be3f14f875b8c094394addad42e8dfe46e0061 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 2/7] fix(ui): a placement removed after it was picked is none in the wizard's step, review and Create (#3108) --- .../ui-egui/src/publicationwizard/accent.rs | 5 ++ .../ui-egui/src/publicationwizard/arrange.rs | 64 +++++++++++++++---- crates/ui-egui/src/publicationwizard/mod.rs | 3 +- .../ui-egui/src/publicationwizard/review.rs | 4 +- crates/ui-egui/src/publicationwizard/texts.rs | 2 +- docs/user-guide/layouts.md | 13 ++-- 6 files changed, 70 insertions(+), 21 deletions(-) diff --git a/crates/ui-egui/src/publicationwizard/accent.rs b/crates/ui-egui/src/publicationwizard/accent.rs index 10bb5c2b01..a1b1c5680f 100644 --- a/crates/ui-egui/src/publicationwizard/accent.rs +++ b/crates/ui-egui/src/publicationwizard/accent.rs @@ -113,6 +113,7 @@ mod tests { click(&mut h, "Back"); 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"); @@ -120,17 +121,20 @@ mod tests { click(&mut h, "Next"); 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"); + 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"); + 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"); @@ -140,6 +144,7 @@ mod tests { click(&mut h, "Back"); 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/arrange.rs b/crates/ui-egui/src/publicationwizard/arrange.rs index c6921883c6..1daac97e85 100644 --- a/crates/ui-egui/src/publicationwizard/arrange.rs +++ b/crates/ui-egui/src/publicationwizard/arrange.rs @@ -31,9 +31,10 @@ impl Arrangement { matches!(self, Arrangement::Named(_) | Arrangement::Custom(_)).then(|| self.value()).flatten() } - /// Its name, as the review says it. - pub(super) fn label(&self) -> String { + /// Its name, as the review says it: none for one that no longer holds. + pub(super) fn label(&self, s: &Session) -> String { match self { + _ if self.held(s).is_err() => tl!("(none)").to_string(), Arrangement::Best => tl!("Best").to_string(), Arrangement::Favourite => tl!("Favourite").to_string(), Arrangement::Named(name) => i18n::display(built_in(name).unwrap_or(name)), @@ -41,13 +42,17 @@ impl Arrangement { } } - /// The corners it gives, or `None` for `best`, which the command picks against the map. - fn homes(&self, s: &Session) -> Option { + /// The corners it gives now, `None` for `best`, which the command picks against the map; or + /// why it no longer holds (a saved one removed meanwhile): the one check the step, the review + /// and Create share. + pub(super) fn held(&self, s: &Session) -> Result, &'static str> { match self { - Arrangement::Best => None, - Arrangement::Favourite => Some(favourite_homes(s)), - Arrangement::Named(name) => parse_arrangement(&json!(name), &s.layout_arrangements).ok(), - Arrangement::Custom(homes) => Some(*homes), + Arrangement::Best => Ok(None), + Arrangement::Favourite => Ok(Some(favourite_homes(s))), + Arrangement::Named(name) => parse_arrangement(&json!(name), &s.layout_arrangements) + .map(Some) + .map_err(|_| tl!("The arrangement picked is no longer saved: pick the placement again.")), + Arrangement::Custom(homes) => Ok(Some(*homes)), } } } @@ -105,12 +110,13 @@ pub(super) fn arrange_step(ui: &mut egui::Ui, s: &Session, d: &mut Draft) { }); let custom = matches!(d.arrangement, Arrangement::Custom(_)); if ui.radio(custom, tl!("Custom")).clicked() && !custom { - d.arrangement = Arrangement::Custom(d.arrangement.homes(s).unwrap_or_else(|| favourite_homes(s))); + let from = d.arrangement.held(s).ok().flatten().unwrap_or_else(|| favourite_homes(s)); + d.arrangement = Arrangement::Custom(from); } if let Arrangement::Custom(homes) = &mut d.arrangement { corner_pickers(ui, homes); } - if let Some(homes) = d.arrangement.homes(s) { + if let Ok(Some(homes)) = d.arrangement.held(s) { ui.add_space(4.0); egui::Grid::new("publication_wizard_corners").num_columns(2).spacing(egui::vec2(24.0, 6.0)).show(ui, |ui| { for (corner, name) in corner_labels().into_iter().enumerate() { @@ -130,7 +136,8 @@ pub(super) fn arrange_step(ui: &mut egui::Ui, s: &Session, d: &mut Draft) { ui.label(egui::RichText::new(note).small().weak()); } ui.add_space(4.0); - ui.add_enabled_ui(d.arrangement.as_favourite().is_some(), |ui| { + let favourable = d.arrangement.held(s).is_ok() && d.arrangement.as_favourite().is_some(); + ui.add_enabled_ui(favourable, |ui| { ui.checkbox(&mut d.make_favourite, tl!("Make this my favourite")) .on_hover_text(tl!("Create also keeps it with the app's preferences as the favourite arrangement.")); }); @@ -382,4 +389,39 @@ mod tests { assert!(h.query_by_label("Legend top").is_some(), "{size}"); } } + + /// A saved arrangement removed after it was picked is none in the step, the review and Create, + /// each by the same check: nothing marked or ticked, and nothing made. + #[test] + fn a_saved_arrangement_removed_after_it_was_picked_holds_nowhere() { + let gone = || Arrangement::Named("Gone".into()); + let h = placement(|app| app.dialogs.publication.as_mut().unwrap().arrangement = gone()); + assert!(h.get_by_role_and_label(Role::CheckBox, "Make this my favourite").accesskit_node().is_disabled()); + let mut h = creating(gone(), |_| {}); + assert!(h.query_by_label("Gone").is_none(), "the review doesn't name it"); + let before = h.state().session.project.layouts.len(); + let said = h.state().session.notices.len(); + click(&mut h, "Create"); + assert_eq!(h.state().session.project.layouts.len(), before, "nothing made"); + assert!(h.state().session.notices[said..].iter().any(|n| n.text.contains("pick the placement again")), "said"); + } + + /// The longest names saved, one of them the favourite, don't take the step off a narrow screen. + #[test] + fn long_saved_names_stay_on_a_narrow_screen() { + let mut app = app(); + open(&mut app); + let name = "W".repeat(40); + let corners = rustgis_engine::cmd::layout::corners_of(ARRANGEMENTS[1].1); + app.session.layout_arrangements.insert(name.clone(), corners); + app.session.layout_favourite = json!(name); + app.dialogs.publication.as_mut().unwrap().step = Step::Placement; + let h = harness_sized(app, egui::vec2(320.0, 900.0)); + for label in [name.clone(), format!("Favourite: {name}")] { + let rect = h.get_by_role_and_label(Role::RadioButton, &label).rect(); + assert!(rect.right() <= 320.0, "{label} at {rect:?} on a screen 320 wide"); + } + let next = h.get_by_role_and_label(Role::Button, "Next").rect(); + assert!(next.right() <= 320.0, "Next at {next:?} on a screen 320 wide"); + } } diff --git a/crates/ui-egui/src/publicationwizard/mod.rs b/crates/ui-egui/src/publicationwizard/mod.rs index bbec4dcb46..5e96c38171 100644 --- a/crates/ui-egui/src/publicationwizard/mod.rs +++ b/crates/ui-egui/src/publicationwizard/mod.rs @@ -530,7 +530,8 @@ pub fn show(app: &mut RustGisApp, ctx: &egui::Context) { }); // A layout the command refuses is said (a map with no extent), and the wizard stays. if create { - match area_extent(&app.session, &d.area) { + let held = d.arrangement.held(&app.session).map_err(String::from); + match held.and_then(|_| area_extent(&app.session, &d.area)) { Ok(extent) => { let mut params = d.params(); if let Some(extent) = extent { diff --git a/crates/ui-egui/src/publicationwizard/review.rs b/crates/ui-egui/src/publicationwizard/review.rs index 1c7d10fbac..971d53935c 100644 --- a/crates/ui-egui/src/publicationwizard/review.rs +++ b/crates/ui-egui/src/publicationwizard/review.rs @@ -17,7 +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() { - row(tl!("Placement"), d.arrangement.label()); + row(tl!("Placement"), d.arrangement.label(s)); // 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 { @@ -38,7 +38,7 @@ pub(super) fn review_step(ui: &mut egui::Ui, s: &Session, d: &Draft) { row(tl!("Orientation"), turned.to_string()); let style = crate::ribbon::publication_style(&d.style).map(|s| s.0.to_string()).unwrap_or_else(|| d.style.clone()); row(tl!("Style"), style); - row(tl!("Placement"), d.arrangement.label()); + row(tl!("Placement"), d.arrangement.label(s)); row(tl!("Title"), or_none(&d.title)); row(tl!("Subtitle"), or_none(&d.subtitle)); row(tl!("Note"), or_none(&d.note)); diff --git a/crates/ui-egui/src/publicationwizard/texts.rs b/crates/ui-egui/src/publicationwizard/texts.rs index 006f0c2456..85d1c83529 100644 --- a/crates/ui-egui/src/publicationwizard/texts.rs +++ b/crates/ui-egui/src/publicationwizard/texts.rs @@ -69,7 +69,7 @@ mod tests { h.state_mut().run("map.new", json!({"name": "Rivers"})).unwrap(); h.run_steps(2); assert_eq!(h.state().dialogs.publication.as_ref().unwrap().title, "Rivers"); - for _ in 0..3 { + for _ in 0..4 { click(&mut h, "Next"); } h.get_by_label("Title").focus(); diff --git a/docs/user-guide/layouts.md b/docs/user-guide/layouts.md index 024248dea1..793b1c1985 100644 --- a/docs/user-guide/layouts.md +++ b/docs/user-guide/layouts.md @@ -57,12 +57,13 @@ Layouts open as tabs next to the maps; while one is open, its groups lead the Pu says when a layout has that name, so the new one is numbered. The **placement** is the arrangement (below): `best`, the favourite, one by name or one saved, or **Custom**, a corner for each surround (a corner another has swaps the two); a chosen one can be made the favourite, - once the layout is made. A figure goes from its size to its map, its placement and 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 window - can be resized. Its steps are listed on the left, and a click goes to one; a narrow screen - leaves the list out, and the heading still says which step this is. + once the layout is made. A saved one removed after it was picked is said at Create and nothing + is made. A figure goes from its size to its map, its placement and 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 window can be + resized. Its steps are listed on the left, and a click goes to one; a narrow screen leaves the + list out, and the heading still says which step this is. - **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 524b38925cd8fe943bb941c921b65dfa0de21928 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Fri, 27 Nov 2026 17:05:20 -0500 Subject: [PATCH 3/7] refactor(engine): keep the arrangement keys and corner names private (#3108) --- crates/engine/src/cmd/layout/publication/arrangement.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/cmd/layout/publication/arrangement.rs b/crates/engine/src/cmd/layout/publication/arrangement.rs index 6bd69eb759..3bf9beff2e 100644 --- a/crates/engine/src/cmd/layout/publication/arrangement.rs +++ b/crates/engine/src/cmd/layout/publication/arrangement.rs @@ -12,10 +12,10 @@ pub const ARRANGEMENTS: [(&str, Homes); 4] = [("classic", [0, 1, 2, 3]), ("mirrored", [1, 0, 3, 2]), ("legendRight", [0, 1, 3, 2]), ("legendTop", [2, 1, 0, 3])]; /// The keys of an arrangement given surround by surround, in [`Homes`]'s order. -pub const ARRANGEMENT_KEYS: [&str; 4] = ["locator", "northArrow", "legend", "scaleBar"]; +pub(in crate::cmd::layout) const ARRANGEMENT_KEYS: [&str; 4] = ["locator", "northArrow", "legend", "scaleBar"]; /// The corners by name, in [`Homes`]'s numbering. -pub const CORNER_NAMES: [&str; 4] = ["top-left", "top-right", "bottom-left", "bottom-right"]; +pub(in crate::cmd::layout) const CORNER_NAMES: [&str; 4] = ["top-left", "top-right", "bottom-left", "bottom-right"]; /// A surround's place in [`Homes`]. pub(in crate::cmd::layout) fn home_slot(kind: Surround) -> usize { From d1f9743c736711b2ad5155a902755a23971e0b11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Fri, 27 Nov 2026 17:19:56 -0500 Subject: [PATCH 4/7] docs(ui): rewrap a wizard test's comment (#3108) --- crates/ui-egui/src/publicationwizard/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/publicationwizard/mod.rs b/crates/ui-egui/src/publicationwizard/mod.rs index 5e96c38171..50fecc0751 100644 --- a/crates/ui-egui/src/publicationwizard/mod.rs +++ b/crates/ui-egui/src/publicationwizard/mod.rs @@ -669,8 +669,8 @@ mod tests { } /// A sheet goes through the eight steps; a figure goes from its size to its map, its placement - /// 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. + /// 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(); From 055c8b6ab0649695eb539edb08d17e010d030e6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Fri, 27 Nov 2026 17:30:30 -0500 Subject: [PATCH 5/7] fix(ui): the wizard's review says when Create sets the favourite, and the column note asks the engine (#3108) --- .../engine/src/cmd/layout/publication/mod.rs | 2 +- .../src/cmd/layout/publication/sheet.rs | 11 ++++++ .../ui-egui/src/publicationwizard/arrange.rs | 39 +++++++++++++++---- crates/ui-egui/src/publicationwizard/mod.rs | 9 ++++- .../ui-egui/src/publicationwizard/review.rs | 12 +++++- 5 files changed, 60 insertions(+), 13 deletions(-) diff --git a/crates/engine/src/cmd/layout/publication/mod.rs b/crates/engine/src/cmd/layout/publication/mod.rs index 9acd033c4f..ac19e98700 100644 --- a/crates/engine/src/cmd/layout/publication/mod.rs +++ b/crates/engine/src/cmd/layout/publication/mod.rs @@ -62,7 +62,7 @@ pub(in crate::cmd::layout) fn landscape_suits(aspect: f64, short: f64, long: f64 // An edge sheet's map takes the page's whole width. let sides = if style == Style::Edge { 0.0 } else { 30.0 * k }; let (iw, ih) = (w - sides, h - texts); - let fw = if matches!(style, Style::Panel | Style::Editorial | Style::Modular) { 0.68 * iw } else { iw }; + let fw = if style.has_column() { 0.68 * iw } else { iw }; let (fw, fh) = (fw - 2.0 * LABEL_ROOM_SIDE * k, ih - 2.0 * LABEL_ROOM_END * k); fw.min(fh / aspect.max(1e-6)) }; diff --git a/crates/engine/src/cmd/layout/publication/sheet.rs b/crates/engine/src/cmd/layout/publication/sheet.rs index a07ee14a6d..e49a7bbe3f 100644 --- a/crates/engine/src/cmd/layout/publication/sheet.rs +++ b/crates/engine/src/cmd/layout/publication/sheet.rs @@ -79,6 +79,12 @@ pub fn publication_style_accent(style: &str) -> Option { Style::parse(style).map(Style::accent) } +/// Whether a [`PUBLICATION_STYLES`] style id keeps the locator and legend in a column beside the +/// map, leaving only the north arrow and scale bar to the frame's corners. +pub fn publication_style_has_column(style: &str) -> bool { + Style::parse(style).is_some_and(Style::has_column) +} + /// How a publication sheet is arranged around its map. #[derive(Clone, Copy, PartialEq, Debug)] pub(in crate::cmd::layout) enum Style { @@ -144,6 +150,11 @@ impl Style { } } + /// Whether it has a column beside the map for the locator and legend. + pub(in crate::cmd::layout) fn has_column(self) -> bool { + matches!(self, Style::Panel | Style::Editorial | Style::Modular) + } + /// Whether its surrounds sit on cards with rounded corners. pub(in crate::cmd::layout) fn cards(self) -> bool { matches!(self, Style::Modular | Style::Poster) diff --git a/crates/ui-egui/src/publicationwizard/arrange.rs b/crates/ui-egui/src/publicationwizard/arrange.rs index 1daac97e85..6a80ed2fef 100644 --- a/crates/ui-egui/src/publicationwizard/arrange.rs +++ b/crates/ui-egui/src/publicationwizard/arrange.rs @@ -1,6 +1,8 @@ //! The wizard's placement step: which corner each surround takes. use super::*; -use rustgis_engine::cmd::layout::{ARRANGEMENTS, Homes, corners_of, parse_arrangement, usable_saved_arrangement}; +use rustgis_engine::cmd::layout::{ + ARRANGEMENTS, Homes, corners_of, parse_arrangement, publication_style_has_column, usable_saved_arrangement, +}; /// The arrangement `layout.publication` is asked for. #[derive(Clone, Debug, PartialEq, Eq)] @@ -25,10 +27,11 @@ impl Arrangement { } } - /// What making this the favourite saves: an arrangement chosen by name or corner by corner; - /// `best` and the favourite itself aren't one. - pub(super) fn as_favourite(&self) -> Option { - matches!(self, Arrangement::Named(_) | Arrangement::Custom(_)).then(|| self.value()).flatten() + /// What making this the favourite saves: an arrangement chosen by name or corner by corner, + /// one that still holds; `best` and the favourite itself aren't one. + pub(super) fn as_favourite(&self, s: &Session) -> Option { + let chosen = matches!(self, Arrangement::Named(_) | Arrangement::Custom(_)) && self.held(s).is_ok(); + chosen.then(|| self.value()).flatten() } /// Its name, as the review says it: none for one that no longer holds. @@ -131,13 +134,12 @@ pub(super) fn arrange_step(ui: &mut egui::Ui, s: &Session, d: &mut Draft) { }); } // The styles with a column keep the locator and legend in it (`cmd/layout/publication`). - if !d.figure() && matches!(d.style.as_str(), "panel" | "editorial" | "modular") { + if !d.figure() && publication_style_has_column(&d.style) { let note = tl!("The locator and legend sit in this style's column: only the north arrow and scale bar take these corners."); ui.label(egui::RichText::new(note).small().weak()); } ui.add_space(4.0); - let favourable = d.arrangement.held(s).is_ok() && d.arrangement.as_favourite().is_some(); - ui.add_enabled_ui(favourable, |ui| { + ui.add_enabled_ui(d.arrangement.as_favourite(s).is_some(), |ui| { ui.checkbox(&mut d.make_favourite, tl!("Make this my favourite")) .on_hover_text(tl!("Create also keeps it with the app's preferences as the favourite arrangement.")); }); @@ -424,4 +426,25 @@ mod tests { let next = h.get_by_role_and_label(Role::Button, "Next").rect(); assert!(next.right() <= 320.0, "Next at {next:?} on a screen 320 wide"); } + + /// The review says Create makes the arrangement the favourite only where it will: ticked, and + /// on an arrangement by name or Custom. + #[test] + fn the_review_says_when_create_sets_the_favourite() { + let said = |h: &Wizard| h.query_by_label("Create makes this arrangement the favourite").is_some(); + for size in ["a4", "figure-1col"] { + for (arrangement, will) in [ + (Arrangement::Named("mirrored".into()), true), + (Arrangement::Custom([3, 0, 1, 2]), true), + (Arrangement::Best, false), + (Arrangement::Favourite, false), + (Arrangement::Named("Gone".into()), false), + ] { + let h = creating(arrangement.clone(), |d| d.size = size.into()); + assert_eq!(said(&h), will, "{size}: {arrangement:?}"); + } + } + let h = creating(Arrangement::Named("mirrored".into()), |d| d.make_favourite = false); + assert!(!said(&h), "unticked"); + } } diff --git a/crates/ui-egui/src/publicationwizard/mod.rs b/crates/ui-egui/src/publicationwizard/mod.rs index 50fecc0751..f490454f89 100644 --- a/crates/ui-egui/src/publicationwizard/mod.rs +++ b/crates/ui-egui/src/publicationwizard/mod.rs @@ -183,6 +183,12 @@ impl Draft { &[Step::Size, Step::Map, Step::Style, Step::Placement, Step::Texts, Step::Sources, Step::Accent, Step::Review] } + /// The favourite Create sets once the layout is made, if any: what the review says and what + /// Create does. + fn favourite_to_set(&self, s: &Session) -> Option { + self.arrangement.as_favourite(s).filter(|_| self.make_favourite) + } + /// The step `by` places from this one, if there is one. fn moved(&self, by: isize) -> Option { let steps = self.steps(); @@ -540,8 +546,7 @@ pub fn show(app: &mut RustGisApp, ctx: &egui::Context) { if crate::ribbon::make_publication(app, params) { close = true; // Only once the layout is made: a refused one changes no preference. - if d.make_favourite - && let Some(favourite) = d.arrangement.as_favourite() + if let Some(favourite) = d.favourite_to_set(&app.session) && let Err(e) = app.run("layout.arrangement", json!({"favourite": favourite})) { app.session.notify(e, true); diff --git a/crates/ui-egui/src/publicationwizard/review.rs b/crates/ui-egui/src/publicationwizard/review.rs index 971d53935c..bf6cf4d858 100644 --- a/crates/ui-egui/src/publicationwizard/review.rs +++ b/crates/ui-egui/src/publicationwizard/review.rs @@ -17,7 +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() { - row(tl!("Placement"), d.arrangement.label(s)); + placement_rows(&mut row, s, d); // 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 { @@ -38,7 +38,7 @@ pub(super) fn review_step(ui: &mut egui::Ui, s: &Session, d: &Draft) { row(tl!("Orientation"), turned.to_string()); let style = crate::ribbon::publication_style(&d.style).map(|s| s.0.to_string()).unwrap_or_else(|| d.style.clone()); row(tl!("Style"), style); - row(tl!("Placement"), d.arrangement.label(s)); + placement_rows(&mut row, s, d); row(tl!("Title"), or_none(&d.title)); row(tl!("Subtitle"), or_none(&d.subtitle)); row(tl!("Note"), or_none(&d.note)); @@ -71,6 +71,14 @@ pub(super) fn review_step(ui: &mut egui::Ui, s: &Session, d: &Draft) { } } +/// The placement's row, and one more when Create also makes it the favourite. +fn placement_rows(row: &mut impl FnMut(&str, String), s: &Session, d: &Draft) { + row(tl!("Placement"), d.arrangement.label(s)); + if d.favourite_to_set(s).is_some() { + row(tl!("Favourite"), tl!("Create makes this arrangement the favourite").to_string()); + } +} + /// 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) { From 5bb821910b9833b7b04bb1b3c4c1a0fe8401b265 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Fri, 27 Nov 2026 18:21:06 -0500 Subject: [PATCH 6/7] fix(ui): on a column style the wizard gives the locator and legend no corner (#3108) --- .../ui-egui/src/publicationwizard/arrange.rs | 86 ++++++++++++++----- docs/user-guide/layouts.md | 19 ++-- 2 files changed, 75 insertions(+), 30 deletions(-) diff --git a/crates/ui-egui/src/publicationwizard/arrange.rs b/crates/ui-egui/src/publicationwizard/arrange.rs index 6a80ed2fef..460d33fe19 100644 --- a/crates/ui-egui/src/publicationwizard/arrange.rs +++ b/crates/ui-egui/src/publicationwizard/arrange.rs @@ -82,6 +82,10 @@ fn corner_labels() -> [&'static str; 4] { [tl_raw!("Top left"), tl_raw!("Top right"), tl_raw!("Bottom left"), tl_raw!("Bottom right")] } +/// The locator and the legend, by their place in [`Homes`]: what a column style keeps in its +/// column. +const IN_COLUMN: [usize; 2] = [0, 2]; + /// The surrounds' names, in [`Homes`]'s order. fn surround_labels() -> [&'static str; 4] { [tl_raw!("Locator"), tl_raw!("North arrow"), tl_raw!("Legend"), tl_raw!("Scale bar")] @@ -116,16 +120,26 @@ pub(super) fn arrange_step(ui: &mut egui::Ui, s: &Session, d: &mut Draft) { let from = d.arrangement.held(s).ok().flatten().unwrap_or_else(|| favourite_homes(s)); d.arrangement = Arrangement::Custom(from); } + // The styles with a column keep the locator and legend in it (`cmd/layout/publication`), so + // those two take no corner. + let column = !d.figure() && publication_style_has_column(&d.style); + let cornered = |surround: usize| !(column && IN_COLUMN.contains(&surround)); if let Arrangement::Custom(homes) = &mut d.arrangement { - corner_pickers(ui, homes); + corner_pickers(ui, homes, cornered); } if let Ok(Some(homes)) = d.arrangement.held(s) { ui.add_space(4.0); egui::Grid::new("publication_wizard_corners").num_columns(2).spacing(egui::vec2(24.0, 6.0)).show(ui, |ui| { for (corner, name) in corner_labels().into_iter().enumerate() { - if let Some(surround) = homes.iter().position(|&h| h == corner) { - let values = [("corner", name), ("surround", surround_labels()[surround])]; - ui.group(|ui| ui.label(i18n::fmt("{corner}: {surround}", &values))); + match homes.iter().position(|&h| h == corner).filter(|&s| cornered(s)) { + Some(surround) => { + let values = [("corner", name), ("surround", surround_labels()[surround])]; + ui.group(|ui| ui.label(i18n::fmt("{corner}: {surround}", &values))); + } + // Its cell is kept, so the others stay at their side. + None => { + ui.label(""); + } } if corner % 2 == 1 { ui.end_row(); @@ -133,8 +147,7 @@ pub(super) fn arrange_step(ui: &mut egui::Ui, s: &Session, d: &mut Draft) { } }); } - // The styles with a column keep the locator and legend in it (`cmd/layout/publication`). - if !d.figure() && publication_style_has_column(&d.style) { + if column { let note = tl!("The locator and legend sit in this style's column: only the north arrow and scale bar take these corners."); ui.label(egui::RichText::new(note).small().weak()); } @@ -146,26 +159,29 @@ pub(super) fn arrange_step(ui: &mut egui::Ui, s: &Session, d: &mut Draft) { } /// A corner for each surround; one picked that another has swaps the two, so each keeps a corner -/// of its own. -fn corner_pickers(ui: &mut egui::Ui, homes: &mut Homes) { +/// of its own. A surround that takes no corner on this sheet has its picker off, still showing the +/// one it holds for the sheets and the favourite where it does. +fn corner_pickers(ui: &mut egui::Ui, homes: &mut Homes, cornered: impl Fn(usize) -> bool) { egui::Grid::new("publication_wizard_custom").num_columns(2).spacing(egui::vec2(8.0, 6.0)).show(ui, |ui| { for (surround, name) in surround_labels().into_iter().enumerate() { let label = ui.label(i18n::display(name)); let corners = corner_labels(); - egui::ComboBox::from_id_salt(("publication_wizard_corner", surround)) - .selected_text(i18n::display(corners[homes[surround]])) - .width(field_width(ui)) - .show_ui(ui, |ui| { - for (corner, name) in corners.into_iter().enumerate() { - if ui.selectable_label(homes[surround] == corner, i18n::display(name)).clicked() - && let Some(other) = homes.iter().position(|&h| h == corner) - { - homes.swap(surround, other); + ui.add_enabled_ui(cornered(surround), |ui| { + egui::ComboBox::from_id_salt(("publication_wizard_corner", surround)) + .selected_text(i18n::display(corners[homes[surround]])) + .width(field_width(ui)) + .show_ui(ui, |ui| { + for (corner, name) in corners.into_iter().enumerate() { + if ui.selectable_label(homes[surround] == corner, i18n::display(name)).clicked() + && let Some(other) = homes.iter().position(|&h| h == corner) + { + homes.swap(surround, other); + } } - } - }) - .response - .labelled_by(label.id); + }) + .response + .labelled_by(label.id); + }); ui.end_row(); } }); @@ -447,4 +463,32 @@ mod tests { let h = creating(Arrangement::Named("mirrored".into()), |d| d.make_favourite = false); assert!(!said(&h), "unticked"); } + + /// On a column style the locator and legend have no corner: the grid lists neither and their + /// pickers are off; the north arrow and scale bar keep theirs. Elsewhere all four have one. + #[test] + fn column_styles_give_no_corner_to_the_locator_and_legend() { + for (style, size, column) in [ + ("classic", "a4", false), + ("panel", "a4", true), + ("editorial", "a4", true), + ("modular", "a4", true), + ("panel", "figure-1col", false), + ] { + let h = placement(|app| { + let d = app.dialogs.publication.as_mut().unwrap(); + (d.style, d.size, d.arrangement) = (style.into(), size.into(), Arrangement::Custom([0, 1, 2, 3])); + }); + for (surround, corner, free) in [ + ("Locator", "Top left", !column), + ("North arrow", "Top right", true), + ("Legend", "Bottom left", !column), + ("Scale bar", "Bottom right", true), + ] { + assert_eq!(shown(&h, &format!("{corner}: {surround}")), free, "{style} {size}: {surround} in the grid"); + let off = h.get_by_role_and_label(Role::ComboBox, surround).accesskit_node().is_disabled(); + assert_eq!(off, !free, "{style} {size}: {surround}'s picker"); + } + } + } } diff --git a/docs/user-guide/layouts.md b/docs/user-guide/layouts.md index 20624a5aa7..5497b9212b 100644 --- a/docs/user-guide/layouts.md +++ b/docs/user-guide/layouts.md @@ -56,15 +56,16 @@ Layouts open as tabs next to the maps; while one is open, its groups lead the Pu 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. The **placement** is the arrangement (below): `best`, the favourite, one by name or one saved, or **Custom**, a corner - for each surround (a corner another has swaps the two); a chosen one can be made the favourite, - once the layout is made. A saved one removed after it was picked is said at Create and nothing - is made. A figure goes from its size to its map, its placement, 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 narrow screen leaves the list out, and the - heading still says which step this is. + for each surround (a corner another has swaps the two; on Panel, Editorial and Modular only the + north arrow and scale bar take one, the locator and legend sitting in the column); a chosen one + can be made the favourite, once the layout is made. A saved one removed after it was picked is + said at Create and nothing is made. A figure goes from its size to its map, its placement, 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 narrow screen + leaves the list out, and the heading still says which step this is. - **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 0cc9fa921c3dec59cd9023a289a3f477a0f79807 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Fri, 27 Nov 2026 18:32:00 -0500 Subject: [PATCH 7/7] fix(ui): the wizard gives a figure's locator no corner, as a figure draws none (#3108) --- .../ui-egui/src/publicationwizard/arrange.rs | 34 +++++++++++++------ docs/user-guide/layouts.md | 19 ++++++----- 2 files changed, 33 insertions(+), 20 deletions(-) diff --git a/crates/ui-egui/src/publicationwizard/arrange.rs b/crates/ui-egui/src/publicationwizard/arrange.rs index 460d33fe19..688366712d 100644 --- a/crates/ui-egui/src/publicationwizard/arrange.rs +++ b/crates/ui-egui/src/publicationwizard/arrange.rs @@ -82,9 +82,12 @@ fn corner_labels() -> [&'static str; 4] { [tl_raw!("Top left"), tl_raw!("Top right"), tl_raw!("Bottom left"), tl_raw!("Bottom right")] } +/// The locator's place in [`Homes`]. +const LOCATOR: usize = 0; + /// The locator and the legend, by their place in [`Homes`]: what a column style keeps in its /// column. -const IN_COLUMN: [usize; 2] = [0, 2]; +const IN_COLUMN: [usize; 2] = [LOCATOR, 2]; /// The surrounds' names, in [`Homes`]'s order. fn surround_labels() -> [&'static str; 4] { @@ -120,10 +123,12 @@ pub(super) fn arrange_step(ui: &mut egui::Ui, s: &Session, d: &mut Draft) { let from = d.arrangement.held(s).ok().flatten().unwrap_or_else(|| favourite_homes(s)); d.arrangement = Arrangement::Custom(from); } - // The styles with a column keep the locator and legend in it (`cmd/layout/publication`), so - // those two take no corner. - let column = !d.figure() && publication_style_has_column(&d.style); - let cornered = |surround: usize| !(column && IN_COLUMN.contains(&surround)); + // What `cmd/layout/publication` puts in no corner, whatever the arrangement: the locator and + // legend of a style with a column, which sit in it, and a figure's locator, which it doesn't + // draw unless asked (the wizard doesn't ask). + let figure = d.figure(); + let column = !figure && publication_style_has_column(&d.style); + let cornered = |surround: usize| !(column && IN_COLUMN.contains(&surround) || figure && surround == LOCATOR); if let Arrangement::Custom(homes) = &mut d.arrangement { corner_pickers(ui, homes, cornered); } @@ -147,8 +152,12 @@ pub(super) fn arrange_step(ui: &mut egui::Ui, s: &Session, d: &mut Draft) { } }); } - if column { - let note = tl!("The locator and legend sit in this style's column: only the north arrow and scale bar take these corners."); + let note = if figure { + Some(tl!("A figure draws no locator.")) + } else { + column.then(|| tl!("The locator and legend sit in this style's column: only the north arrow and scale bar take these corners.")) + }; + if let Some(note) = note { ui.label(egui::RichText::new(note).small().weak()); } ui.add_space(4.0); @@ -464,10 +473,11 @@ mod tests { assert!(!said(&h), "unticked"); } - /// On a column style the locator and legend have no corner: the grid lists neither and their - /// pickers are off; the north arrow and scale bar keep theirs. Elsewhere all four have one. + /// A surround with no corner on the sheet isn't listed in the grid and has its picker off: on a + /// column style the locator and legend, on a figure (which draws none) the locator. The rest, + /// and all four elsewhere, keep theirs; a figure says why. #[test] - fn column_styles_give_no_corner_to_the_locator_and_legend() { + fn surrounds_without_a_corner_are_not_given_one() { for (style, size, column) in [ ("classic", "a4", false), ("panel", "a4", true), @@ -480,7 +490,7 @@ mod tests { (d.style, d.size, d.arrangement) = (style.into(), size.into(), Arrangement::Custom([0, 1, 2, 3])); }); for (surround, corner, free) in [ - ("Locator", "Top left", !column), + ("Locator", "Top left", !column && size == "a4"), ("North arrow", "Top right", true), ("Legend", "Bottom left", !column), ("Scale bar", "Bottom right", true), @@ -489,6 +499,8 @@ mod tests { let off = h.get_by_role_and_label(Role::ComboBox, surround).accesskit_node().is_disabled(); assert_eq!(off, !free, "{style} {size}: {surround}'s picker"); } + let said = h.query_by_label("A figure draws no locator.").is_some(); + assert_eq!(said, size != "a4", "{style} {size}: the figure's note"); } } } diff --git a/docs/user-guide/layouts.md b/docs/user-guide/layouts.md index 5497b9212b..2543526a5c 100644 --- a/docs/user-guide/layouts.md +++ b/docs/user-guide/layouts.md @@ -57,15 +57,16 @@ Layouts open as tabs next to the maps; while one is open, its groups lead the Pu says when a layout has that name, so the new one is numbered. The **placement** is the arrangement (below): `best`, the favourite, one by name or one saved, or **Custom**, a corner for each surround (a corner another has swaps the two; on Panel, Editorial and Modular only the - north arrow and scale bar take one, the locator and legend sitting in the column); a chosen one - can be made the favourite, once the layout is made. A saved one removed after it was picked is - said at Create and nothing is made. A figure goes from its size to its map, its placement, 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 narrow screen - leaves the list out, and the heading still says which step this is. + north arrow and scale bar take one, the locator and legend sitting in the column, and a figure + gives the locator none, as it draws none); a chosen one can be made the favourite, once the + layout is made. A saved one removed after it was picked is said at Create and nothing is made. A + figure goes from its size to its map, its placement, 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 narrow screen leaves the list out, and the heading still + says which step this is. - **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),