From f2dc4605cf363ede260c12c142312d3093abb300 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Tue, 24 Nov 2026 07:35:01 -0500 Subject: [PATCH 01/13] feat(layout): a Publication Layout Wizard asks size, style, texts and accent step by step (#2850) --- crates/ui-egui/src/dialogs.rs | 6 + crates/ui-egui/src/lib.rs | 9 + crates/ui-egui/src/publicationwizard.rs | 526 ++++++++++++++++++++++++ crates/ui-egui/src/ribbon.rs | 54 ++- docs/user-guide/layouts.md | 7 + 5 files changed, 598 insertions(+), 4 deletions(-) create mode 100644 crates/ui-egui/src/publicationwizard.rs diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index 645586301e..29e6e1a1dc 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -22,6 +22,8 @@ pub struct Dialogs { /// Map-local layer IDs require the dialog to retain its original project and map as well. pub projection_map: Option<(u64, usize, String)>, pub geometry: Option, + /// Publication Layout Wizard: what it has asked so far (#2850). + pub publication: Option, pub repair: Option, pub conflicts: Option, #[cfg(not(target_arch = "wasm32"))] @@ -333,6 +335,10 @@ pub fn show(app: &mut RustGisApp, ctx: &egui::Context) { crate::reloaddata::show(app, ctx); return; } + if which == "publicationWizard" { + crate::publicationwizard::show(app, ctx); + return; + } if which == "repairSource" { crate::repairsource::show(app, ctx); return; diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index ec2381883f..109ec0d343 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -86,6 +86,7 @@ mod pluginstart; mod pluginsui; mod popupmedia; mod portalsui; +mod publicationwizard; #[cfg(not(target_arch = "wasm32"))] mod readjob; #[cfg(not(target_arch = "wasm32"))] @@ -5802,6 +5803,14 @@ impl RustGisApp { self.dialogs = dialogs::Dialogs { open: Some("calculateGeometry"), geometry: Some(form), ..Default::default() }; return Ok(Value::Null); } + if which == "publicationWizard" { + // Opened again while open, it keeps what was entered. + if self.dialogs.open != Some("publicationWizard") || self.dialogs.publication.is_none() { + let draft = publicationwizard::Draft::new(&self.session); + self.dialogs = dialogs::Dialogs { open: Some("publicationWizard"), publication: Some(draft), ..Default::default() }; + } + return Ok(Value::Null); + } if which == "offlineConflicts" { let area = p.get("area").and_then(Value::as_str).ok_or_else(|| tl!("Name the offline area.").to_string())?; let form = conflictsui::Form::new(&self.session, area)?; diff --git a/crates/ui-egui/src/publicationwizard.rs b/crates/ui-egui/src/publicationwizard.rs new file mode 100644 index 0000000000..208d8faed9 --- /dev/null +++ b/crates/ui-egui/src/publicationwizard.rs @@ -0,0 +1,526 @@ +//! 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). +use crate::{RustGisApp, i18n, theme::Tokens}; +use rustgis_engine::Session; +use rustgis_engine::cmd::layout::{PUBLICATION_PROFILES, PUBLICATION_STYLES}; +use rustgis_engine::map::layout::PAGES; +use serde_json::{Value, json}; + +/// The wizard's steps, in order. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum Step { + Size, + Style, + Texts, + Accent, + Review, +} + +/// 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 { + Auto, + Portrait, + Landscape, +} + +/// What the wizard has asked so far: `layout.publication`'s fields, under the command's names. +pub struct Draft { + pub step: Step, + /// A page size's id (`a4`, from [`PAGES`]) or a figure's profile id (`figure-1col`). + pub size: String, + pub orientation: Orientation, + pub style: String, + pub title: String, + pub subtitle: String, + pub note: String, + pub sources: String, + pub author: String, + /// No credit line at all (`"author": ""`), rather than the command's default one. + pub no_author: bool, + /// The style's colour, or `None` for the style's own. + pub accent: Option, +} + +impl Draft { + /// What the menu makes: an A4 sheet turned as the map comes out larger, the classic style and + /// the map's name as the title. + pub fn new(s: &Session) -> Self { + Self { + step: Step::Size, + size: "a4".into(), + orientation: Orientation::Auto, + style: "classic".into(), + title: s.map().name.clone(), + subtitle: String::new(), + note: String::new(), + sources: String::new(), + author: String::new(), + no_author: false, + accent: None, + } + } + + /// Whether the size is a figure, which takes no style, texts or accent: the command draws the + /// map edge to edge and leaves the rest to the caption. + fn figure(&self) -> bool { + PUBLICATION_PROFILES.iter().any(|p| !p.sheet && p.id == self.size) + } + + /// 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] } + } + + /// The step `by` places from this one, if there is one. + fn moved(&self, by: isize) -> Option { + let steps = self.steps(); + let at = steps.iter().position(|s| *s == self.step)?; + steps.get(at.checked_add_signed(by)?).copied() + } + + /// `layout.publication`'s parameters: the fields set; one left empty is left to the command's + /// default, but for the title, which empty means none. + pub fn params(&self) -> Value { + let profile = match (self.figure(), self.orientation) { + (true, _) | (false, Orientation::Auto) => self.size.clone(), + (false, Orientation::Portrait) => format!("{}-portrait", self.size), + (false, Orientation::Landscape) => format!("{}-landscape", self.size), + }; + let mut p = json!({"profile": profile}); + if self.figure() { + return p; + } + 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)] { + if !text.trim().is_empty() { + p[key] = json!(text.trim()); + } + } + if self.no_author { + p["author"] = json!(""); + } + if let Some(c) = self.accent { + p["accent"] = json!(format!("#{:02X}{:02X}{:02X}", c.r(), c.g(), c.b())); + } + p + } + + /// The size as the menu names it: `A4 (210 × 297 mm)`, or a figure's name. + fn size_label(&self) -> String { + size_label(&self.size) + } +} + +/// A page size's or a figure's name, as New Layout › Publication Layout lists it. +fn size_label(id: &str) -> String { + if let Some((_, label, w, h)) = PAGES.iter().find(|p| p.0 == id) { + return crate::ribbon::page_label(label, *w, *h); + } + let profile = PUBLICATION_PROFILES.iter().find(|p| p.id == id); + crate::ribbon::publication_label(id) + .map(str::to_string) + .or_else(|| profile.map(|p| tl!(p.label).to_string())) + .unwrap_or_else(|| id.to_string()) +} + +/// A step's name, as its heading and the review give it. +fn step_name(step: Step) -> &'static str { + match step { + Step::Size => tl!("Size"), + Step::Style => tl!("Style"), + Step::Texts => tl!("Texts"), + Step::Accent => tl!("Accent"), + Step::Review => tl!("Review"), + } +} + +/// The size step: a sheet on any page size New Layout offers, turned as asked, or a figure. +fn size_step(ui: &mut egui::Ui, d: &mut Draft) { + egui::Grid::new("publication_wizard_size").num_columns(2).spacing(egui::vec2(8.0, 8.0)).show(ui, |ui| { + let label = ui.label(tl!("Size")); + egui::ComboBox::from_id_salt("publication_wizard_size_pick") + .selected_text(d.size_label()) + .width(260.0) + .show_ui(ui, |ui| { + for (id, ..) in PAGES { + ui.selectable_value(&mut d.size, (*id).to_string(), size_label(id)); + } + ui.separator(); + for p in PUBLICATION_PROFILES.iter().filter(|p| !p.sheet) { + ui.selectable_value(&mut d.size, p.id.to_string(), size_label(p.id)); + } + }) + .response + .labelled_by(label.id); + ui.end_row(); + ui.label(tl!("Orientation")); + ui.add_enabled_ui(!d.figure(), |ui| { + ui.horizontal(|ui| { + ui.radio_value(&mut d.orientation, Orientation::Auto, tl!("Auto")).on_hover_text(tl!("The way the map comes out larger.")); + ui.radio_value(&mut d.orientation, Orientation::Portrait, tl!("Portrait")); + ui.radio_value(&mut d.orientation, Orientation::Landscape, tl!("Landscape")); + }); + }); + ui.end_row(); + }); + if d.figure() { + ui.label(egui::RichText::new(tl!("A figure is the map edge to edge: its title and sources go in its caption.")).small().weak()); + } +} + +/// The style step: each sheet style, by the name and description the menu gives it. +fn style_step(ui: &mut egui::Ui, d: &mut Draft) { + for (id, name) in PUBLICATION_STYLES { + let (name, about) = crate::ribbon::publication_style(id).unwrap_or_else(|| (tl!(*name), "")); + ui.radio_value(&mut d.style, (*id).to_string(), name); + ui.indent(*id, |ui| ui.label(egui::RichText::new(about).small().weak())); + } +} + +/// The texts step: the title, subtitle, note, sources and credit line. +fn texts_step(ui: &mut egui::Ui, d: &mut Draft) { + 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, hint: &str| { + let label = ui.label(label); + ui.add(egui::TextEdit::singleline(text).hint_text(hint).desired_width(260.0)).labelled_by(label.id); + ui.end_row(); + }; + line(ui, tl!("Title"), &mut d.title, tl!("No title")); + line(ui, tl!("Subtitle"), &mut d.subtitle, ""); + let label = ui.label(tl!("Note")); + ui.add(egui::TextEdit::multiline(&mut d.note).desired_rows(3).desired_width(260.0)).labelled_by(label.id); + 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(tl!("Made with RustGIS and the date")).desired_width(260.0), + ) + .labelled_by(label.id); + ui.end_row(); + ui.label(""); + ui.checkbox(&mut d.no_author, tl!("No credit line")); + ui.end_row(); + }); +} + +/// The accent step: the style's own colour, or one picked. +fn accent_step(ui: &mut egui::Ui, d: &mut Draft, own: egui::Color32) { + let mut picked = d.accent.is_some(); + if ui.checkbox(&mut picked, tl!("Pick the accent colour")).changed() { + d.accent = picked.then_some(own); + } + if let Some(c) = &mut d.accent { + egui::color_picker::color_edit_button_srgba(ui, c, egui::color_picker::Alpha::Opaque); + } else { + ui.label(egui::RichText::new(tl!("The style's own colour.")).small().weak()); + } +} + +/// The review step: what was picked, step by step. +fn review_step(ui: &mut egui::Ui, d: &Draft) { + let none = tl!("(none)"); + let or_none = |t: &str| if t.trim().is_empty() { none.to_string() } else { t.trim().to_string() }; + egui::Grid::new("publication_wizard_review").num_columns(2).spacing(egui::vec2(12.0, 6.0)).show(ui, |ui| { + let mut row = |key: &str, value: String| { + ui.label(egui::RichText::new(key).weak()); + ui.label(value); + ui.end_row(); + }; + row(tl!("Size"), d.size_label()); + if d.figure() { + return; + } + let turned = match d.orientation { + Orientation::Auto => tl!("Auto"), + Orientation::Portrait => tl!("Portrait"), + Orientation::Landscape => tl!("Landscape"), + }; + 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!("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 credit = if d.no_author { + none.to_string() + } else if d.author.trim().is_empty() { + tl!("Made with RustGIS and the date").to_string() + } else { + d.author.trim().to_string() + }; + row(tl!("Credit line"), credit); + let accent = + d.accent.map(|c| format!("#{:02X}{:02X}{:02X}", c.r(), c.g(), c.b())).unwrap_or_else(|| tl!("The style's own").to_string()); + row(tl!("Accent"), accent); + }); +} + +/// Shows the wizard while it is open; Create runs `layout.publication` as the menu does, and the +/// wizard stays open on a layout the command refuses. +pub fn show(app: &mut RustGisApp, ctx: &egui::Context) { + let Some(mut d) = app.dialogs.publication.take() else { + app.dialogs.open = None; + return; + }; + let t = Tokens::get(ctx); + let (mut open, mut close, mut create) = (true, false, false); + egui::Window::new(tl!("Publication Layout Wizard")) + .id(egui::Id::unique("publication_wizard")) + .open(&mut open) + .collapsible(false) + .resizable(false) + .auto_sized() + .pivot(egui::Align2::CENTER_CENTER) + .default_pos(ctx.content_rect().center()) + .show(ctx, |ui| { + ui.set_width(380.0); + let steps = d.steps(); + let at = steps.iter().position(|s| *s == d.step).unwrap_or(0); + let heading = i18n::fmt( + "Step {n} of {count}: {step}", + &[("n", &(at + 1).to_string()), ("count", &steps.len().to_string()), ("step", step_name(d.step))], + ); + ui.label(egui::RichText::new(heading).strong()); + ui.separator(); + match d.step { + Step::Size => size_step(ui, &mut d), + Step::Style => style_step(ui, &mut d), + Step::Texts => texts_step(ui, &mut d), + Step::Accent => accent_step(ui, &mut d, t.accent), + Step::Review => review_step(ui, &d), + } + ui.separator(); + let size = egui::vec2(84.0, 28.0); + ui.horizontal(|ui| { + ui.with_layout(egui::Layout::right_to_left(egui::Align::Min), |ui| { + match d.moved(1) { + Some(next) => { + if crate::widgets::dialog_button(ui, tl!("Next"), Some(t.accent), size).clicked() { + d.step = next; + } + } + None => create = crate::widgets::dialog_button(ui, tl!("Create"), Some(t.accent), size).clicked(), + } + let back = d.moved(-1); + if ui.add_enabled_ui(back.is_some(), |ui| crate::widgets::dialog_button(ui, tl!("Back"), None, size).clicked()).inner { + d.step = back.unwrap_or(d.step); + } + close = crate::widgets::dialog_button(ui, tl!("Cancel"), None, size).clicked(); + }); + }); + }); + // 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; + } + if !open || close { + app.dialogs.open = None; + } else { + app.dialogs.publication = Some(d); + } +} + +#[cfg(test)] +mod tests { + use super::*; + use egui::accesskit::Role; + use egui::vec2; + use egui_kittest::kittest::{NodeT, Queryable}; + + fn app() -> RustGisApp { + RustGisApp::with_sample() + } + + fn open(app: &mut RustGisApp) { + app.run("ui.dialog", json!({"name": "publicationWizard"})).unwrap(); + } + + fn harness(app: RustGisApp) -> egui_kittest::Harness<'static, RustGisApp> { + // The dialogs alone: the ribbon has a Next of its own (the next extent). + let mut fonts = false; + let mut h = egui_kittest::Harness::builder().with_size(vec2(1400.0, 1000.0)).with_max_steps(64).build_ui_state( + move |ui, app: &mut RustGisApp| { + if !fonts { + crate::theme::install_fonts(ui.ctx(), &[], None); + fonts = true; + return; + } + crate::dialogs::show(app, &ui.ctx().clone()); + }, + app, + ); + h.run_steps(4); + h + } + + fn click(h: &mut egui_kittest::Harness<'static, RustGisApp>, label: &str) { + h.get_by_role_and_label(Role::Button, label).click(); + h.run_steps(4); + } + + fn step(h: &egui_kittest::Harness<'static, RustGisApp>) -> Step { + h.state().dialogs.publication.as_ref().expect("the wizard is open").step + } + + /// It opens on its first step with the menu's defaults: an A4 sheet turned as the map comes + /// out larger, the classic style, the map's name as the title and nothing else set; opened + /// again while open, it keeps what was entered. + #[test] + fn opens_on_the_menus_defaults_and_keeps_its_draft() { + let mut app = app(); + open(&mut app); + let name = app.session.map().name.clone(); + let d = app.dialogs.publication.as_mut().expect("opened"); + assert_eq!((d.step, d.size.as_str(), d.orientation, d.style.as_str()), (Step::Size, "a4", Orientation::Auto, "classic")); + assert_eq!(d.title, name); + assert!(d.subtitle.is_empty() && d.note.is_empty() && d.sources.is_empty() && d.author.is_empty()); + assert!((d.accent, d.no_author) == (None, false)); + assert_eq!(app.dialogs.open, Some("publicationWizard")); + app.dialogs.publication.as_mut().unwrap().subtitle = "Kept".into(); + open(&mut app); + assert_eq!(app.dialogs.publication.as_ref().unwrap().subtitle, "Kept", "not started over"); + } + + /// What Create runs: the fields set, under the command's names; what is left empty is left to + /// the command's default, but for the title, which empty means none. + #[test] + fn create_sends_the_fields_set_and_nothing_else() { + let app = app(); + let mut d = Draft::new(&app.session); + d.title = "Rivers".into(); + assert_eq!(d.params(), json!({"profile": "a4", "style": "classic", "title": "Rivers"})); + d.orientation = Orientation::Landscape; + d.size = "letter".into(); + d.style = "panel".into(); + d.title.clear(); + d.subtitle = "2026".into(); + d.note = "A note".into(); + d.sources = "Natural Earth".into(); + d.author = "J. G.".into(); + d.accent = Some(egui::Color32::from_rgb(0x0B, 0x1B, 0x2B)); + assert_eq!( + d.params(), + json!({"profile": "letter-landscape", "style": "panel", "title": "", "subtitle": "2026", "note": "A note", + "sources": "Natural Earth", "author": "J. G.", "accent": "#0B1B2B"}) + ); + d.orientation = Orientation::Portrait; + d.no_author = true; + assert_eq!(d.params()["profile"], "letter-portrait"); + assert_eq!(d.params()["author"], "", "no credit line"); + // A figure takes no style, texts or accent: the engine draws none of them on it. + d.size = "figure-1col".into(); + 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 + /// Create on the last. + #[test] + fn a_sheet_takes_every_step_and_a_figure_skips_what_it_doesnt_draw() { + let mut app = app(); + 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] { + 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] { + 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); + } + + /// The style step lists every sheet style, by the names and descriptions the menu gives them. + #[test] + fn the_style_step_lists_every_style_as_the_menu_names_it() { + let mut app = app(); + open(&mut app); + app.dialogs.publication.as_mut().unwrap().step = Step::Style; + let h = harness(app); + for (id, _) in rustgis_engine::cmd::layout::PUBLICATION_STYLES { + let (name, about) = crate::ribbon::publication_style(id).unwrap(); + assert!(h.query_by_label(name).is_some(), "{id}"); + assert!(h.query_by_label(about).is_some(), "{id}"); + } + } + + /// Create makes the layout in one step, closes the wizard and opens the Publish tab, as the + /// menu does; Undo takes the layout away. + #[test] + fn create_makes_the_layout_and_undo_takes_it_away() { + let mut app = app(); + open(&mut app); + { + let d = app.dialogs.publication.as_mut().unwrap(); + d.style = "banner".into(); + d.subtitle = "From the wizard".into(); + d.step = Step::Review; + } + let before = app.session.project.layouts.len(); + let mut h = harness(app); + click(&mut h, "Create"); + let app = h.state(); + assert_eq!(app.session.project.layouts.len(), before + 1); + let l = app.session.project.layouts.last().unwrap(); + assert!( + l.elements.iter().any( + |e| matches!(&e.kind, rustgis_engine::map::layout::ElementKind::Text { text, .. } if text.contains("From the wizard")) + ), + "the subtitle given" + ); + assert_eq!((app.dialogs.open, app.ui.tab.as_str()), (None, "Publish")); + assert!(app.dialogs.publication.is_none()); + h.state_mut().run("edit.undo", Value::Null).unwrap(); + assert_eq!(h.state().session.project.layouts.len(), before); + } + + /// A layout the command refuses (here a style it doesn't know) is said, and the wizard stays + /// open on its review with nothing made. + #[test] + fn a_refused_layout_is_said_and_the_wizard_stays_open() { + let mut app = app(); + open(&mut app); + { + let d = app.dialogs.publication.as_mut().unwrap(); + d.style = "unknown".into(); + d.step = Step::Review; + } + let before = app.session.project.layouts.len(); + let mut h = harness(app); + let said = h.state().session.notices.len(); + click(&mut h, "Create"); + let app = h.state(); + assert_eq!(app.session.project.layouts.len(), before, "nothing made"); + assert!(app.session.notices[said..].iter().any(|n| n.text.contains("unknown")), "said"); + assert_eq!(app.dialogs.open, Some("publicationWizard")); + assert_eq!(app.dialogs.publication.as_ref().map(|d| d.step), Some(Step::Review)); + } + + /// Cancel closes the wizard with nothing made, and the next opening starts over. + #[test] + fn cancel_makes_nothing_and_the_next_opening_starts_over() { + let mut app = app(); + open(&mut app); + app.dialogs.publication.as_mut().unwrap().subtitle = "Dropped".into(); + let before = app.session.project.layouts.len(); + let mut h = harness(app); + click(&mut h, "Cancel"); + assert_eq!(h.state().dialogs.open, None); + assert_eq!(h.state().session.project.layouts.len(), before); + h.state_mut().run("ui.dialog", json!({"name": "publicationWizard"})).unwrap(); + assert!(h.state().dialogs.publication.as_ref().unwrap().subtitle.is_empty()); + } +} diff --git a/crates/ui-egui/src/ribbon.rs b/crates/ui-egui/src/ribbon.rs index e5a9f18d4d..8a9d8567c3 100644 --- a/crates/ui-egui/src/ribbon.rs +++ b/crates/ui-egui/src/ribbon.rs @@ -1192,6 +1192,12 @@ fn publication_layout(app: &mut RustGisApp, profile: &rustgis_engine::cmd::layou if let Some(style) = style { p["style"] = json!(style); } + make_publication(app, p); +} + +/// Runs `layout.publication` with `p`, as the menu and the wizard make a publication layout: its +/// warnings said and the Publish tab opened; true when the layout was made. +pub(crate) fn make_publication(app: &mut RustGisApp, p: Value) -> bool { // The view's extent may not be known (an empty map): said, and the tab stays. match app.run("layout.publication", p) { Ok(r) => { @@ -1201,14 +1207,18 @@ fn publication_layout(app: &mut RustGisApp, profile: &rustgis_engine::cmd::layou app.session.notify(said.join("\n"), false); } app.ui.tab = "Publish".into(); + true + } + Err(e) => { + app.session.notify(e, true); + false } - Err(e) => app.session.notify(e, true), } } /// A sheet style's name in the menu and what it looks like, `tl!` literals (as /// [`publication_label`]); `None` for a style added without them. -fn publication_style(id: &str) -> Option<(&'static str, &'static str)> { +pub(crate) fn publication_style(id: &str) -> Option<(&'static str, &'static str)> { Some(match id { "classic" => (tl!("Classic"), tl!("The title over the map, the sources and the reference in boxes under it.")), "banner" => (tl!("Banner"), tl!("The title and subtitle in a band of colour across the top.")), @@ -1223,7 +1233,7 @@ fn publication_style(id: &str) -> Option<(&'static str, &'static str)> { /// A publication figure's name in the menu: a `tl!` literal each, so the catalogs find it (the /// engine's labels, which it matches in English); `None` for a figure added without one. Sheets /// are named by their page size, as New Layout names it. -fn publication_label(id: &str) -> Option<&'static str> { +pub(crate) fn publication_label(id: &str) -> Option<&'static str> { Some(match id { "figure-1col" => tl!("Journal figure, 1 column (90 mm)"), "figure-1.5col" => tl!("Journal figure, 1.5 columns (140 mm)"), @@ -1241,7 +1251,7 @@ fn publication_sheet(size: &str, orientation: &str) -> Option<&'static rustgis_e } /// A page size as the menus name it: `A4 (210 × 297 mm)`, its name translated. -fn page_label(label: &str, w: f64, h: f64) -> String { +pub(crate) fn page_label(label: &str, w: f64, h: f64) -> String { format!("{} ({w:.0} × {h:.0} mm)", tl!(label)) } @@ -1292,6 +1302,12 @@ fn project_group(app: &mut RustGisApp, ui: &mut Ui) { ui.close(); } } + // The same layout asked step by step: its texts and accent too (#2850). + ui.separator(); + if ui.button(tl!("Publication Layout Wizard…")).clicked() { + let _ = app.run("ui.dialog", json!({"name": "publicationWizard"})); + ui.close(); + } }); ui.separator(); if ui.button(tl!("Blank Letter page")).clicked() { @@ -6869,6 +6885,36 @@ mod tests { assert!(l.elements.iter().all(|e| e.name != "Panel Box" && e.name != "Title"), "a figure, its title left to the caption"); } + /// New Layout › Publication Layout › Publication Layout Wizard… opens the wizard and closes + /// the menu, with nothing made yet (#2850). + #[test] + fn the_publication_menu_opens_the_wizard() { + let mut fonts = false; + let mut h = egui_kittest::Harness::builder().with_size(vec2(1600.0, 1000.0)).build_ui_state( + move |ui, app: &mut RustGisApp| { + if !fonts { + crate::theme::install_fonts(ui.ctx(), &[], None); + fonts = true; + return; + } + ui.horizontal(|ui| project_group(app, ui)); + }, + cities(), + ); + h.run(); + let before = h.state().session.project.layouts.len(); + h.get_by_label("New Layout").click(); + h.run(); + h.get_by_label("Publication Layout").hover(); + h.run(); + h.get_by_label("Publication Layout Wizard…").click(); + h.run(); + assert_eq!(h.state().dialogs.open, Some("publicationWizard")); + assert!(h.state().dialogs.publication.is_some()); + assert_eq!(h.state().session.project.layouts.len(), before, "nothing made yet"); + assert!(h.query_by_label("Publication Layout Wizard…").is_none(), "the menu closed"); + } + /// A submenu of short rows (a sheet's styles) opens at least SUBMENU_MIN_W wide, not as a /// strip, and the row opening it is as tall as the menu's other rows (#2398). #[test] diff --git a/docs/user-guide/layouts.md b/docs/user-guide/layouts.md index 52f5230145..5c696c04a4 100644 --- a/docs/user-guide/layouts.md +++ b/docs/user-guide/layouts.md @@ -37,6 +37,13 @@ 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, the texts (title, + 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 keeps the command's default, + but the title, which empty means none. A layout the command refuses is said, and the wizard + stays open. - **The map**: the `extent` given (or the view) fitted north-up, without tilt, at a round scale, two significant figures, rounded up so it still fits within the strips the graticule's labels take inside the frame. A graticule's step follows the extent (2° for a state, 15′ for a city), From 0b2bb639ec7ad3f7b677703ac761179ba857a951 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Tue, 24 Nov 2026 08:27:53 -0500 Subject: [PATCH 02/13] fix(layout): every wizard step is as tall as the tallest, so Next stays in place (#2850) --- crates/ui-egui/src/publicationwizard.rs | 38 ++++++++++++++++++++----- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/crates/ui-egui/src/publicationwizard.rs b/crates/ui-egui/src/publicationwizard.rs index 208d8faed9..5b61ad2924 100644 --- a/crates/ui-egui/src/publicationwizard.rs +++ b/crates/ui-egui/src/publicationwizard.rs @@ -259,6 +259,9 @@ fn review_step(ui: &mut egui::Ui, d: &Draft) { }); } +/// The height every step takes: the style step's six styles and their descriptions. +const STEP_HEIGHT: f32 = 300.0; + /// Shows the wizard while it is open; Create runs `layout.publication` as the menu does, and the /// wizard stays open on a layout the command refuses. pub fn show(app: &mut RustGisApp, ctx: &egui::Context) { @@ -286,13 +289,20 @@ pub fn show(app: &mut RustGisApp, ctx: &egui::Context) { ); ui.label(egui::RichText::new(heading).strong()); ui.separator(); - match d.step { - Step::Size => size_step(ui, &mut d), - Step::Style => style_step(ui, &mut d), - Step::Texts => texts_step(ui, &mut d), - Step::Accent => accent_step(ui, &mut d, t.accent), - Step::Review => review_step(ui, &d), - } + // Every step as tall as the tallest (the styles and their descriptions), so the + // window keeps its size and Next stays under the pointer from step to step. + // `set_min_height`, not `allocate_ui_with_layout`, which in egui 0.37 keeps only what + // was drawn. + ui.vertical(|ui| { + ui.set_min_height(STEP_HEIGHT); + match d.step { + Step::Size => size_step(ui, &mut d), + Step::Style => style_step(ui, &mut d), + Step::Texts => texts_step(ui, &mut d), + Step::Accent => accent_step(ui, &mut d, t.accent), + Step::Review => review_step(ui, &d), + } + }); ui.separator(); let size = egui::vec2(84.0, 28.0); ui.horizontal(|ui| { @@ -509,6 +519,20 @@ mod tests { assert_eq!(app.dialogs.publication.as_ref().map(|d| d.step), Some(Step::Review)); } + /// Next stays where it was from one step to the next: every step is as tall as the tallest. + #[test] + fn next_stays_under_the_pointer_from_step_to_step() { + let mut app = app(); + open(&mut app); + 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 { + click(&mut h, "Next"); + assert_eq!(at(&h), first, "{:?}", step(&h)); + } + } + /// Cancel closes the wizard with nothing made, and the next opening starts over. #[test] fn cancel_makes_nothing_and_the_next_opening_starts_over() { From 3ab75ff81baf003682e24a0ad5d0a1a5687923f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Tue, 24 Nov 2026 08:36:19 -0500 Subject: [PATCH 03/13] fix(layout): the wizard's title follows the active map until typed; its review says what will be drawn (#2850) --- crates/ui-egui/src/publicationwizard.rs | 84 ++++++++++++++++++++----- docs/user-guide/layouts.md | 3 +- 2 files changed, 71 insertions(+), 16 deletions(-) diff --git a/crates/ui-egui/src/publicationwizard.rs b/crates/ui-egui/src/publicationwizard.rs index 5b61ad2924..3debc98d62 100644 --- a/crates/ui-egui/src/publicationwizard.rs +++ b/crates/ui-egui/src/publicationwizard.rs @@ -32,6 +32,8 @@ pub struct Draft { pub orientation: Orientation, pub style: String, pub title: String, + /// Whether the title was typed; until then it is the active map's name, as the menu's. + pub title_typed: bool, pub subtitle: String, pub note: String, pub sources: String, @@ -52,6 +54,7 @@ impl Draft { orientation: Orientation::Auto, style: "classic".into(), title: s.map().name.clone(), + title_typed: false, subtitle: String::new(), note: String::new(), sources: String::new(), @@ -102,15 +105,15 @@ impl Draft { p["author"] = json!(""); } if let Some(c) = self.accent { - p["accent"] = json!(format!("#{:02X}{:02X}{:02X}", c.r(), c.g(), c.b())); + p["accent"] = json!(hex(c)); } p } +} - /// The size as the menu names it: `A4 (210 × 297 mm)`, or a figure's name. - fn size_label(&self) -> String { - size_label(&self.size) - } +/// A colour as `layout.publication` takes it: `#RRGGBB`. +fn hex(c: egui::Color32) -> String { + format!("#{:02X}{:02X}{:02X}", c.r(), c.g(), c.b()) } /// A page size's or a figure's name, as New Layout › Publication Layout lists it. @@ -141,7 +144,7 @@ fn size_step(ui: &mut egui::Ui, d: &mut Draft) { egui::Grid::new("publication_wizard_size").num_columns(2).spacing(egui::vec2(8.0, 8.0)).show(ui, |ui| { let label = ui.label(tl!("Size")); egui::ComboBox::from_id_salt("publication_wizard_size_pick") - .selected_text(d.size_label()) + .selected_text(size_label(&d.size)) .width(260.0) .show_ui(ui, |ui| { for (id, ..) in PAGES { @@ -166,10 +169,16 @@ fn size_step(ui: &mut egui::Ui, d: &mut Draft) { ui.end_row(); }); if d.figure() { - ui.label(egui::RichText::new(tl!("A figure is the map edge to edge: its title and sources go in its caption.")).small().weak()); + figure_note(ui); } } +/// What a figure leaves out, said where its size is picked and in the review: the texts and +/// accent typed for a sheet aren't drawn on it. +fn figure_note(ui: &mut egui::Ui) { + ui.label(egui::RichText::new(tl!("A figure is the map edge to edge: its title, texts and style go in its caption.")).small().weak()); +} + /// The style step: each sheet style, by the name and description the menu gives it. fn style_step(ui: &mut egui::Ui, d: &mut Draft) { for (id, name) in PUBLICATION_STYLES { @@ -187,7 +196,10 @@ fn texts_step(ui: &mut egui::Ui, d: &mut Draft) { ui.add(egui::TextEdit::singleline(text).hint_text(hint).desired_width(260.0)).labelled_by(label.id); ui.end_row(); }; - line(ui, tl!("Title"), &mut d.title, tl!("No title")); + let label = ui.label(tl!("Title")); + let title = ui.add(egui::TextEdit::singleline(&mut d.title).hint_text(tl!("No title")).desired_width(260.0)).labelled_by(label.id); + d.title_typed |= title.changed(); + ui.end_row(); line(ui, tl!("Subtitle"), &mut d.subtitle, ""); let label = ui.label(tl!("Note")); ui.add(egui::TextEdit::multiline(&mut d.note).desired_rows(3).desired_width(260.0)).labelled_by(label.id); @@ -196,7 +208,7 @@ fn texts_step(ui: &mut egui::Ui, d: &mut Draft) { let label = ui.label(tl!("Credit line")); ui.add_enabled( !d.no_author, - egui::TextEdit::singleline(&mut d.author).hint_text(tl!("Made with RustGIS and the date")).desired_width(260.0), + egui::TextEdit::singleline(&mut d.author).hint_text(tl!("Made with RustGIS · the date")).desired_width(260.0), ) .labelled_by(label.id); ui.end_row(); @@ -209,7 +221,7 @@ fn texts_step(ui: &mut egui::Ui, d: &mut Draft) { /// The accent step: the style's own colour, or one picked. fn accent_step(ui: &mut egui::Ui, d: &mut Draft, own: egui::Color32) { let mut picked = d.accent.is_some(); - if ui.checkbox(&mut picked, tl!("Pick the accent colour")).changed() { + if ui.checkbox(&mut picked, tl!("Pick a colour of your own")).changed() { d.accent = picked.then_some(own); } if let Some(c) = &mut d.accent { @@ -229,7 +241,7 @@ fn review_step(ui: &mut egui::Ui, d: &Draft) { ui.label(value); ui.end_row(); }; - row(tl!("Size"), d.size_label()); + row(tl!("Size"), size_label(&d.size)); if d.figure() { return; } @@ -248,15 +260,17 @@ fn review_step(ui: &mut egui::Ui, d: &Draft) { let credit = if d.no_author { none.to_string() } else if d.author.trim().is_empty() { - tl!("Made with RustGIS and the date").to_string() + tl!("Made with RustGIS · the date").to_string() } else { d.author.trim().to_string() }; row(tl!("Credit line"), credit); - let accent = - d.accent.map(|c| format!("#{:02X}{:02X}{:02X}", c.r(), c.g(), c.b())).unwrap_or_else(|| tl!("The style's own").to_string()); + let accent = d.accent.map(hex).unwrap_or_else(|| tl!("The style's own").to_string()); row(tl!("Accent"), accent); }); + if d.figure() { + figure_note(ui); + } } /// The height every step takes: the style step's six styles and their descriptions. @@ -269,6 +283,10 @@ pub fn show(app: &mut RustGisApp, ctx: &egui::Context) { app.dialogs.open = None; return; }; + // A map opened meanwhile titles its sheet, as the menu titles it at the click. + if !d.title_typed { + d.title.clone_from(&app.session.map().name); + } let t = Tokens::get(ctx); let (mut open, mut close, mut create) = (true, false, false); egui::Window::new(tl!("Publication Layout Wizard")) @@ -388,7 +406,7 @@ mod tests { assert_eq!((d.step, d.size.as_str(), d.orientation, d.style.as_str()), (Step::Size, "a4", Orientation::Auto, "classic")); assert_eq!(d.title, name); assert!(d.subtitle.is_empty() && d.note.is_empty() && d.sources.is_empty() && d.author.is_empty()); - assert!((d.accent, d.no_author) == (None, false)); + assert!(d.accent.is_none() && !d.no_author); assert_eq!(app.dialogs.open, Some("publicationWizard")); app.dialogs.publication.as_mut().unwrap().subtitle = "Kept".into(); open(&mut app); @@ -533,6 +551,42 @@ mod tests { } } + /// Until the title is edited, it is the active map's name, as the menu titles a sheet: a map + /// opened while the wizard is open titles its sheet; a title typed stays. + #[test] + fn the_title_follows_the_active_map_until_it_is_edited() { + let mut app = app(); + open(&mut app); + let mut h = harness(app); + 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"); + h.get_by_label("Title").focus(); + h.run_steps(1); + h.get_by_label("Title").type_text(" basins"); + h.run_steps(2); + assert_eq!(h.state().dialogs.publication.as_ref().unwrap().title, "Rivers basins"); + h.state_mut().run("map.new", json!({"name": "Lakes"})).unwrap(); + h.run_steps(2); + assert_eq!(h.state().dialogs.publication.as_ref().unwrap().title, "Rivers basins", "typed, so kept"); + } + + /// The review says what will be drawn: the default credit line as the sheet writes it, and for + /// a figure, that its texts and accent are left to the caption. + #[test] + fn the_review_says_what_will_be_drawn() { + let mut app = app(); + open(&mut app); + app.dialogs.publication.as_mut().unwrap().step = Step::Review; + let mut h = harness(app); + assert!(h.query_by_label("Made with RustGIS · the date").is_some()); + h.state_mut().dialogs.publication.as_mut().unwrap().size = "figure-1col".into(); + h.run_steps(2); + assert!(h.query_by_label_contains("its caption").is_some(), "a figure's texts aren't drawn"); + } + /// Cancel closes the wizard with nothing made, and the next opening starts over. #[test] fn cancel_makes_nothing_and_the_next_opening_starts_over() { diff --git a/docs/user-guide/layouts.md b/docs/user-guide/layouts.md index 5c696c04a4..4d88788724 100644 --- a/docs/user-guide/layouts.md +++ b/docs/user-guide/layouts.md @@ -39,7 +39,8 @@ Layouts open as tabs next to the maps; while one is open, its groups lead the Pu 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, the texts (title, - subtitle, note, sources and credit line, or none) and the accent colour, then shows what was + 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 keeps the command's default, but the title, which empty means none. A layout the command refuses is said, and the wizard From a9dac6144679fdab904680e570e9ee9f43240325 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Tue, 24 Nov 2026 09:27:02 -0500 Subject: [PATCH 04/13] fix(layout): the wizard keeps one size in every language and says what Auto turns by (#2850) --- crates/ui-egui/src/publicationwizard.rs | 52 +++++++++++++++++++------ 1 file changed, 40 insertions(+), 12 deletions(-) diff --git a/crates/ui-egui/src/publicationwizard.rs b/crates/ui-egui/src/publicationwizard.rs index 3debc98d62..06a27d7d5b 100644 --- a/crates/ui-egui/src/publicationwizard.rs +++ b/crates/ui-egui/src/publicationwizard.rs @@ -160,7 +160,7 @@ fn size_step(ui: &mut egui::Ui, d: &mut Draft) { ui.end_row(); ui.label(tl!("Orientation")); ui.add_enabled_ui(!d.figure(), |ui| { - ui.horizontal(|ui| { + ui.horizontal_wrapped(|ui| { ui.radio_value(&mut d.orientation, Orientation::Auto, tl!("Auto")).on_hover_text(tl!("The way the map comes out larger.")); ui.radio_value(&mut d.orientation, Orientation::Portrait, tl!("Portrait")); ui.radio_value(&mut d.orientation, Orientation::Landscape, tl!("Landscape")); @@ -246,7 +246,7 @@ fn review_step(ui: &mut egui::Ui, d: &Draft) { return; } let turned = match d.orientation { - Orientation::Auto => tl!("Auto"), + Orientation::Auto => tl!("Auto: the way the map comes out larger"), Orientation::Portrait => tl!("Portrait"), Orientation::Landscape => tl!("Landscape"), }; @@ -273,6 +273,9 @@ fn review_step(ui: &mut egui::Ui, d: &Draft) { } } +/// The wizard's width. +const WIDTH: f32 = 380.0; + /// The height every step takes: the style step's six styles and their descriptions. const STEP_HEIGHT: f32 = 300.0; @@ -295,10 +298,12 @@ pub fn show(app: &mut RustGisApp, ctx: &egui::Context) { .collapsible(false) .resizable(false) .auto_sized() + // One width on every step and in every language: a long row wraps instead of widening it. + .max_width(WIDTH) .pivot(egui::Align2::CENTER_CENTER) .default_pos(ctx.content_rect().center()) .show(ctx, |ui| { - ui.set_width(380.0); + ui.set_width(WIDTH); let steps = d.steps(); let at = steps.iter().position(|s| *s == d.step).unwrap_or(0); let heading = i18n::fmt( @@ -307,20 +312,20 @@ pub fn show(app: &mut RustGisApp, ctx: &egui::Context) { ); ui.label(egui::RichText::new(heading).strong()); ui.separator(); - // Every step as tall as the tallest (the styles and their descriptions), so the - // window keeps its size and Next stays under the pointer from step to step. - // `set_min_height`, not `allocate_ui_with_layout`, which in egui 0.37 keeps only what - // was drawn. - ui.vertical(|ui| { - ui.set_min_height(STEP_HEIGHT); - match d.step { + // Every step in a box of one size, so the window keeps its size and Next stays under + // the pointer from step to step: as tall as the tallest step (the styles and their + // descriptions) in English, a step that runs longer in another language scrolling + // inside it, its text wrapped to its width rather than widening the window. + egui::ScrollArea::vertical().id_salt("publication_wizard_step").max_height(STEP_HEIGHT).auto_shrink([false, false]).show( + ui, + |ui| match d.step { Step::Size => size_step(ui, &mut d), Step::Style => style_step(ui, &mut d), Step::Texts => texts_step(ui, &mut d), Step::Accent => accent_step(ui, &mut d, t.accent), Step::Review => review_step(ui, &d), - } - }); + }, + ); ui.separator(); let size = egui::vec2(84.0, 28.0); ui.horizontal(|ui| { @@ -582,11 +587,34 @@ mod tests { app.dialogs.publication.as_mut().unwrap().step = Step::Review; let mut h = harness(app); assert!(h.query_by_label("Made with RustGIS · the date").is_some()); + assert!(h.query_by_label("Auto: the way the map comes out larger").is_some(), "the turn, decided at Create"); h.state_mut().dialogs.publication.as_mut().unwrap().size = "figure-1col".into(); h.run_steps(2); assert!(h.query_by_label_contains("its caption").is_some(), "a figure's texts aren't drawn"); } + /// Next stays where it was in a language whose descriptions run longer: a step taller than + /// the others scrolls inside its height rather than growing the window. + #[test] + fn next_stays_in_place_in_a_longer_language() { + for code in ["de", "el"] { + let mut app = app(); + // As the app applies its language each frame (`chosen_lang`), which the harness skips. + crate::i18n::set_current(crate::i18n::Lang::from_code(code).unwrap()); + open(&mut app); + let mut h = harness(app); + let next = crate::i18n::t("Next").to_string(); + 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 { + h.get_by_role_and_label(Role::Button, &next).click(); + h.run_steps(4); + assert_eq!(at(&h), first, "{code}: {:?}", step(&h)); + } + } + } + /// Cancel closes the wizard with nothing made, and the next opening starts over. #[test] fn cancel_makes_nothing_and_the_next_opening_starts_over() { From 3f3062b8745f61aa1e5b7d299cea75c837bbc066 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Tue, 24 Nov 2026 09:48:36 -0500 Subject: [PATCH 05/13] refactor(layout): one name for a publication profile in the menu and the wizard; review wording (#2850) --- crates/ui-egui/src/publicationwizard.rs | 55 ++++++++++++++++++------- crates/ui-egui/src/ribbon.rs | 9 +++- 2 files changed, 47 insertions(+), 17 deletions(-) diff --git a/crates/ui-egui/src/publicationwizard.rs b/crates/ui-egui/src/publicationwizard.rs index 06a27d7d5b..d47b16ac5a 100644 --- a/crates/ui-egui/src/publicationwizard.rs +++ b/crates/ui-egui/src/publicationwizard.rs @@ -121,21 +121,18 @@ fn size_label(id: &str) -> String { if let Some((_, label, w, h)) = PAGES.iter().find(|p| p.0 == id) { return crate::ribbon::page_label(label, *w, *h); } - let profile = PUBLICATION_PROFILES.iter().find(|p| p.id == id); - crate::ribbon::publication_label(id) - .map(str::to_string) - .or_else(|| profile.map(|p| tl!(p.label).to_string())) - .unwrap_or_else(|| id.to_string()) + PUBLICATION_PROFILES.iter().find(|p| p.id == id).map_or_else(|| id.to_string(), |p| crate::ribbon::profile_label(p).to_string()) } -/// A step's name, as its heading and the review give it. +/// A step's name, as its heading gives it: in logical order (`tl_raw!`), as `i18n::fmt` takes +/// its arguments, converting the whole heading for display once. fn step_name(step: Step) -> &'static str { match step { - Step::Size => tl!("Size"), - Step::Style => tl!("Style"), - Step::Texts => tl!("Texts"), - Step::Accent => tl!("Accent"), - Step::Review => tl!("Review"), + Step::Size => tl_raw!("Size"), + Step::Style => tl_raw!("Style"), + Step::Texts => tl_raw!("Texts"), + Step::Accent => tl_raw!("Accent"), + Step::Review => tl_raw!("Review"), } } @@ -208,7 +205,7 @@ fn texts_step(ui: &mut egui::Ui, d: &mut Draft) { let label = ui.label(tl!("Credit line")); ui.add_enabled( !d.no_author, - egui::TextEdit::singleline(&mut d.author).hint_text(tl!("Made with RustGIS · the date")).desired_width(260.0), + egui::TextEdit::singleline(&mut d.author).hint_text(tl!("Made with RustGIS · today's date")).desired_width(260.0), ) .labelled_by(label.id); ui.end_row(); @@ -221,7 +218,11 @@ fn texts_step(ui: &mut egui::Ui, d: &mut Draft) { /// The accent step: the style's own colour, or one picked. fn accent_step(ui: &mut egui::Ui, d: &mut Draft, own: egui::Color32) { let mut picked = d.accent.is_some(); - if ui.checkbox(&mut picked, tl!("Pick a colour of your own")).changed() { + if ui + .checkbox(&mut picked, tl!("Pick a colour of your own")) + .on_hover_text(tl!("Starts from the app's accent colour; the swatch shows the colour the layout takes.")) + .changed() + { d.accent = picked.then_some(own); } if let Some(c) = &mut d.accent { @@ -260,7 +261,7 @@ fn review_step(ui: &mut egui::Ui, d: &Draft) { let credit = if d.no_author { none.to_string() } else if d.author.trim().is_empty() { - tl!("Made with RustGIS · the date").to_string() + tl!("Made with RustGIS · today's date").to_string() } else { d.author.trim().to_string() }; @@ -520,6 +521,28 @@ mod tests { assert_eq!(h.state().session.project.layouts.len(), before); } + /// A figure is made from its size alone, through the same command, and Undo takes it away. + #[test] + fn a_figure_is_made_from_its_size_alone() { + let mut app = app(); + open(&mut app); + { + let d = app.dialogs.publication.as_mut().unwrap(); + d.size = "figure-1col".into(); + d.subtitle = "Not drawn".into(); + d.step = Step::Review; + } + let before = app.session.project.layouts.len(); + let mut h = harness(app); + click(&mut h, "Create"); + let l = h.state().session.project.layouts.last().unwrap(); + assert_eq!(h.state().session.project.layouts.len(), before + 1); + assert!((l.width - 90.0).abs() < 0.01, "a 1-column figure: {} mm wide", l.width); + assert_eq!(h.state().dialogs.open, None); + h.state_mut().run("edit.undo", Value::Null).unwrap(); + assert_eq!(h.state().session.project.layouts.len(), before); + } + /// A layout the command refuses (here a style it doesn't know) is said, and the wizard stays /// open on its review with nothing made. #[test] @@ -586,7 +609,7 @@ mod tests { open(&mut app); app.dialogs.publication.as_mut().unwrap().step = Step::Review; let mut h = harness(app); - assert!(h.query_by_label("Made with RustGIS · the date").is_some()); + assert!(h.query_by_label("Made with RustGIS · today's date").is_some()); assert!(h.query_by_label("Auto: the way the map comes out larger").is_some(), "the turn, decided at Create"); h.state_mut().dialogs.publication.as_mut().unwrap().size = "figure-1col".into(); h.run_steps(2); @@ -597,6 +620,7 @@ mod tests { /// the others scrolls inside its height rather than growing the window. #[test] fn next_stays_in_place_in_a_longer_language() { + let previous = crate::i18n::current(); for code in ["de", "el"] { let mut app = app(); // As the app applies its language each frame (`chosen_lang`), which the harness skips. @@ -613,6 +637,7 @@ mod tests { assert_eq!(at(&h), first, "{code}: {:?}", step(&h)); } } + crate::i18n::set_current(previous); } /// Cancel closes the wizard with nothing made, and the next opening starts over. diff --git a/crates/ui-egui/src/ribbon.rs b/crates/ui-egui/src/ribbon.rs index 8a9d8567c3..8966e9f12d 100644 --- a/crates/ui-egui/src/ribbon.rs +++ b/crates/ui-egui/src/ribbon.rs @@ -1250,6 +1250,12 @@ fn publication_sheet(size: &str, orientation: &str) -> Option<&'static rustgis_e rustgis_engine::cmd::layout::PUBLICATION_PROFILES.iter().find(|p| p.sheet && p.id == id) } +/// A publication profile's name in the menu: its `tl!` literal, or the engine's label for a figure +/// added without one. The wizard names its sizes with it too. +pub(crate) fn profile_label(profile: &rustgis_engine::cmd::layout::PublicationProfile) -> &'static str { + publication_label(profile.id).unwrap_or_else(|| tl!(profile.label)) +} + /// A page size as the menus name it: `A4 (210 × 297 mm)`, its name translated. pub(crate) fn page_label(label: &str, w: f64, h: f64) -> String { format!("{} ({w:.0} × {h:.0} mm)", tl!(label)) @@ -1296,8 +1302,7 @@ fn project_group(app: &mut RustGisApp, ui: &mut Ui) { } ui.separator(); for profile in rustgis_engine::cmd::layout::PUBLICATION_PROFILES.iter().filter(|p| !p.sheet) { - let label = publication_label(profile.id).unwrap_or_else(|| tl!(profile.label)); - if ui.button(label).clicked() { + if ui.button(profile_label(profile)).clicked() { publication_layout(app, profile, None); ui.close(); } From 1981ca3e85eaf264704cdc1841485dd96828f5a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Tue, 24 Nov 2026 11:20:33 -0500 Subject: [PATCH 06/13] fix(layout): the wizard keeps a colour picked across a tick and scrolls each step on its own (#2850) --- crates/ui-egui/src/publicationwizard.rs | 66 ++++++++++++++++++------- 1 file changed, 49 insertions(+), 17 deletions(-) diff --git a/crates/ui-egui/src/publicationwizard.rs b/crates/ui-egui/src/publicationwizard.rs index d47b16ac5a..36e459a9f8 100644 --- a/crates/ui-egui/src/publicationwizard.rs +++ b/crates/ui-egui/src/publicationwizard.rs @@ -7,7 +7,7 @@ use rustgis_engine::map::layout::PAGES; use serde_json::{Value, json}; /// The wizard's steps, in order. -#[derive(Clone, Copy, Debug, PartialEq, Eq)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub enum Step { Size, Style, @@ -42,11 +42,14 @@ pub struct Draft { pub no_author: bool, /// 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. + picked: Option, } impl Draft { - /// What the menu makes: an A4 sheet turned as the map comes out larger, the classic style and - /// the map's name as the title. + /// Where the wizard starts: an A4 sheet turned Auto (as `layout.publication` turns a size + /// given alone, the way the map comes out larger; the menu lists Portrait and Landscape + /// instead), the classic style and the map's name as the title, as the menu titles a sheet. pub fn new(s: &Session) -> Self { Self { step: Step::Size, @@ -61,6 +64,7 @@ impl Draft { author: String::new(), no_author: false, accent: None, + picked: None, } } @@ -178,8 +182,8 @@ fn figure_note(ui: &mut egui::Ui) { /// The style step: each sheet style, by the name and description the menu gives it. fn style_step(ui: &mut egui::Ui, d: &mut Draft) { - for (id, name) in PUBLICATION_STYLES { - let (name, about) = crate::ribbon::publication_style(id).unwrap_or_else(|| (tl!(*name), "")); + for (id, english) in PUBLICATION_STYLES { + let (name, about) = crate::ribbon::publication_style(id).unwrap_or_else(|| (tl!(*english), "")); ui.radio_value(&mut d.style, (*id).to_string(), name); ui.indent(*id, |ui| ui.label(egui::RichText::new(about).small().weak())); } @@ -223,7 +227,11 @@ fn accent_step(ui: &mut egui::Ui, d: &mut Draft, own: egui::Color32) { .on_hover_text(tl!("Starts from the app's accent colour; the swatch shows the colour the layout takes.")) .changed() { - d.accent = picked.then_some(own); + // Unticked, the colour picked is kept for the next tick. + if !picked { + d.picked = d.accent; + } + d.accent = picked.then(|| d.picked.unwrap_or(own)); } if let Some(c) = &mut d.accent { egui::color_picker::color_edit_button_srgba(ui, c, egui::color_picker::Alpha::Opaque); @@ -316,17 +324,19 @@ pub fn show(app: &mut RustGisApp, ctx: &egui::Context) { // Every step in a box of one size, so the window keeps its size and Next stays under // the pointer from step to step: as tall as the tallest step (the styles and their // descriptions) in English, a step that runs longer in another language scrolling - // inside it, its text wrapped to its width rather than widening the window. - egui::ScrollArea::vertical().id_salt("publication_wizard_step").max_height(STEP_HEIGHT).auto_shrink([false, false]).show( - ui, - |ui| match d.step { + // inside it, its text wrapped to its width rather than widening the window. Each step + // scrolls on its own, so one scrolled down doesn't open the next partway down. + egui::ScrollArea::vertical() + .id_salt(("publication_wizard_step", d.step)) + .max_height(STEP_HEIGHT) + .auto_shrink([false, false]) + .show(ui, |ui| match d.step { Step::Size => size_step(ui, &mut d), Step::Style => style_step(ui, &mut d), Step::Texts => texts_step(ui, &mut d), Step::Accent => accent_step(ui, &mut d, t.accent), Step::Review => review_step(ui, &d), - }, - ); + }); ui.separator(); let size = egui::vec2(84.0, 28.0); ui.horizontal(|ui| { @@ -341,7 +351,9 @@ pub fn show(app: &mut RustGisApp, ctx: &egui::Context) { } let back = d.moved(-1); if ui.add_enabled_ui(back.is_some(), |ui| crate::widgets::dialog_button(ui, tl!("Back"), None, size).clicked()).inner { - d.step = back.unwrap_or(d.step); + if let Some(back) = back { + d.step = back; + } } close = crate::widgets::dialog_button(ui, tl!("Cancel"), None, size).clicked(); }); @@ -400,11 +412,10 @@ mod tests { h.state().dialogs.publication.as_ref().expect("the wizard is open").step } - /// It opens on its first step with the menu's defaults: an A4 sheet turned as the map comes - /// out larger, the classic style, the map's name as the title and nothing else set; opened - /// again while open, it keeps what was entered. + /// It opens on its first step: an A4 sheet turned Auto, the classic style, the map's name as + /// the title and nothing else set; opened again while open, it keeps what was entered. #[test] - fn opens_on_the_menus_defaults_and_keeps_its_draft() { + fn opens_on_its_defaults_and_keeps_its_draft() { let mut app = app(); open(&mut app); let name = app.session.map().name.clone(); @@ -640,6 +651,27 @@ mod tests { crate::i18n::set_current(previous); } + /// A colour picked stays picked: unticked, the style's own colour is sent; ticked again, the + /// swatch comes back with the colour picked before. + #[test] + fn a_colour_picked_comes_back_when_ticked_again() { + let mut app = app(); + open(&mut app); + let red = egui::Color32::from_rgb(0xC0, 0x30, 0x30); + { + let d = app.dialogs.publication.as_mut().unwrap(); + d.step = Step::Accent; + d.accent = Some(red); + } + let mut h = harness(app); + 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, "the style's own"); + 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(red), "the colour picked before"); + } + /// Cancel closes the wizard with nothing made, and the next opening starts over. #[test] fn cancel_makes_nothing_and_the_next_opening_starts_over() { From 3dbb2a6779a1b9d25b248df84506b2db35c7cb6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Tue, 24 Nov 2026 11:59:41 -0500 Subject: [PATCH 07/13] fix(layout): the wizard's Back collapses its check; the style step is pinned to fit in English (#2850) --- crates/ui-egui/src/publicationwizard.rs | 36 ++++++++++++++++++------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/crates/ui-egui/src/publicationwizard.rs b/crates/ui-egui/src/publicationwizard.rs index 36e459a9f8..0bbfea004c 100644 --- a/crates/ui-egui/src/publicationwizard.rs +++ b/crates/ui-egui/src/publicationwizard.rs @@ -221,17 +221,17 @@ fn texts_step(ui: &mut egui::Ui, d: &mut Draft) { /// The accent step: the style's own colour, or one picked. fn accent_step(ui: &mut egui::Ui, d: &mut Draft, own: egui::Color32) { - let mut picked = d.accent.is_some(); + let mut ticked = d.accent.is_some(); if ui - .checkbox(&mut picked, tl!("Pick a colour of your own")) - .on_hover_text(tl!("Starts from the app's accent colour; the swatch shows the colour the layout takes.")) + .checkbox(&mut ticked, tl!("Pick a colour of your own")) + .on_hover_text(tl!("Starts from the colour picked last, or the app's accent colour; the swatch shows the colour the layout takes.")) .changed() { // Unticked, the colour picked is kept for the next tick. - if !picked { + if !ticked { d.picked = d.accent; } - d.accent = picked.then(|| d.picked.unwrap_or(own)); + d.accent = ticked.then(|| d.picked.unwrap_or(own)); } if let Some(c) = &mut d.accent { egui::color_picker::color_edit_button_srgba(ui, c, egui::color_picker::Alpha::Opaque); @@ -350,10 +350,10 @@ pub fn show(app: &mut RustGisApp, ctx: &egui::Context) { None => create = crate::widgets::dialog_button(ui, tl!("Create"), Some(t.accent), size).clicked(), } let back = d.moved(-1); - if ui.add_enabled_ui(back.is_some(), |ui| crate::widgets::dialog_button(ui, tl!("Back"), None, size).clicked()).inner { - if let Some(back) = back { - d.step = back; - } + if ui.add_enabled_ui(back.is_some(), |ui| crate::widgets::dialog_button(ui, tl!("Back"), None, size).clicked()).inner + && let Some(back) = back + { + d.step = back; } close = crate::widgets::dialog_button(ui, tl!("Cancel"), None, size).clicked(); }); @@ -672,6 +672,24 @@ mod tests { assert_eq!(h.state().dialogs.publication.as_ref().unwrap().accent, Some(red), "the colour picked before"); } + /// In English the style step fits its box: the last style's description shows above the + /// buttons without scrolling. + #[test] + fn the_style_step_fits_without_scrolling_in_english() { + let mut app = app(); + open(&mut app); + app.dialogs.publication.as_mut().unwrap().step = Step::Style; + let h = harness(app); + let (_, about) = crate::ribbon::publication_style("poster").unwrap(); + let last = h.get_by_label(about).rect(); + let next = h.get_by_role_and_label(Role::Button, "Next").rect(); + assert!(last.bottom() < next.top(), "{last:?} runs under the buttons at {next:?}"); + assert!( + h.get_by_label("Classic").rect().top() > h.get_by_label_contains("Step 2 of").rect().bottom(), + "the first isn't scrolled away" + ); + } + /// Cancel closes the wizard with nothing made, and the next opening starts over. #[test] fn cancel_makes_nothing_and_the_next_opening_starts_over() { From 6609a632513ee44890dd1a1f6b524b17973207fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Tue, 24 Nov 2026 12:41:15 -0500 Subject: [PATCH 08/13] fix(layout): the wizard's style step fits on a high-density screen (#2850) --- crates/ui-egui/src/publicationwizard.rs | 57 ++++++++++++++----------- 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/crates/ui-egui/src/publicationwizard.rs b/crates/ui-egui/src/publicationwizard.rs index 0bbfea004c..6b452f4d38 100644 --- a/crates/ui-egui/src/publicationwizard.rs +++ b/crates/ui-egui/src/publicationwizard.rs @@ -285,8 +285,9 @@ fn review_step(ui: &mut egui::Ui, d: &Draft) { /// The wizard's width. const WIDTH: f32 = 380.0; -/// The height every step takes: the style step's six styles and their descriptions. -const STEP_HEIGHT: f32 = 300.0; +/// The height every step takes: the style step's six styles and their descriptions, with room +/// for the rounding a high-density screen adds to each line. +const STEP_HEIGHT: f32 = 320.0; /// Shows the wizard while it is open; Create runs `layout.publication` as the menu does, and the /// wizard stays open on a layout the command refuses. @@ -388,17 +389,22 @@ mod tests { fn harness(app: RustGisApp) -> egui_kittest::Harness<'static, RustGisApp> { // The dialogs alone: the ribbon has a Next of its own (the next extent). let mut fonts = false; - let mut h = egui_kittest::Harness::builder().with_size(vec2(1400.0, 1000.0)).with_max_steps(64).build_ui_state( - move |ui, app: &mut RustGisApp| { - if !fonts { - crate::theme::install_fonts(ui.ctx(), &[], None); - fonts = true; - return; - } - crate::dialogs::show(app, &ui.ctx().clone()); - }, - app, - ); + let mut h = + egui_kittest::Harness::builder().with_size(vec2(1400.0, 1000.0)).with_pixels_per_point(2.0).with_max_steps(64).build_ui_state( + move |ui, app: &mut RustGisApp| { + if !fonts { + // The app's fonts and theme at a high-density screen's scale, so sizes, spacing + // and the rounding of each line are the ones the app draws there. + crate::theme::install_fonts(ui.ctx(), &[], None); + let theme = app.current_theme(); + crate::theme::apply(ui.ctx(), &theme.tokens, &theme.metrics); + fonts = true; + return; + } + crate::dialogs::show(app, &ui.ctx().clone()); + }, + app, + ); h.run_steps(4); h } @@ -672,22 +678,25 @@ mod tests { assert_eq!(h.state().dialogs.publication.as_ref().unwrap().accent, Some(red), "the colour picked before"); } - /// In English the style step fits its box: the last style's description shows above the - /// buttons without scrolling. + /// In English the style step fits its box: the wheel over it scrolls nothing, so the last + /// style's description isn't cut at the bottom. #[test] fn the_style_step_fits_without_scrolling_in_english() { let mut app = app(); open(&mut app); app.dialogs.publication.as_mut().unwrap().step = Step::Style; - let h = harness(app); - let (_, about) = crate::ribbon::publication_style("poster").unwrap(); - let last = h.get_by_label(about).rect(); - let next = h.get_by_role_and_label(Role::Button, "Next").rect(); - assert!(last.bottom() < next.top(), "{last:?} runs under the buttons at {next:?}"); - assert!( - h.get_by_label("Classic").rect().top() > h.get_by_label_contains("Step 2 of").rect().bottom(), - "the first isn't scrolled away" - ); + let mut h = harness(app); + let before = h.get_by_label("Classic").rect(); + h.event(egui::Event::PointerMoved(before.center())); + h.event(egui::Event::MouseWheel { + unit: egui::MouseWheelUnit::Point, + delta: vec2(0.0, -400.0), + modifiers: egui::Modifiers::NONE, + phase: egui::TouchPhase::Move, + source: egui::MouseWheelSource::Wheel, + }); + h.run_steps(10); + assert_eq!(h.get_by_label("Classic").rect(), before, "the styles scroll: they don't fit the box"); } /// Cancel closes the wizard with nothing made, and the next opening starts over. From 5ca9afb5ba815e54c0fb68bc3b6f073c1c16be31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Tue, 24 Nov 2026 12:54:31 -0500 Subject: [PATCH 09/13] refactor(layout): the wizard's text rows name their caption apart from its text (#2850) --- crates/ui-egui/src/publicationwizard.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/publicationwizard.rs b/crates/ui-egui/src/publicationwizard.rs index 6b452f4d38..f76d7216ad 100644 --- a/crates/ui-egui/src/publicationwizard.rs +++ b/crates/ui-egui/src/publicationwizard.rs @@ -193,8 +193,8 @@ fn style_step(ui: &mut egui::Ui, d: &mut Draft) { fn texts_step(ui: &mut egui::Ui, d: &mut Draft) { 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, hint: &str| { - let label = ui.label(label); - ui.add(egui::TextEdit::singleline(text).hint_text(hint).desired_width(260.0)).labelled_by(label.id); + let caption = ui.label(label); + ui.add(egui::TextEdit::singleline(text).hint_text(hint).desired_width(260.0)).labelled_by(caption.id); ui.end_row(); }; let label = ui.label(tl!("Title")); From cbfe7f20212b2cbb51669586ee1ae9f89c15a093 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Tue, 24 Nov 2026 13:21:52 -0500 Subject: [PATCH 10/13] docs(layout): the wizard's empty fields as the command takes them; one name for the default credit line (#2850) --- crates/ui-egui/src/publicationwizard.rs | 15 +++++++++------ docs/user-guide/layouts.md | 8 ++++---- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/crates/ui-egui/src/publicationwizard.rs b/crates/ui-egui/src/publicationwizard.rs index f76d7216ad..a77a30039d 100644 --- a/crates/ui-egui/src/publicationwizard.rs +++ b/crates/ui-egui/src/publicationwizard.rs @@ -207,11 +207,8 @@ fn texts_step(ui: &mut egui::Ui, d: &mut Draft) { 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(tl!("Made with RustGIS · today's date")).desired_width(260.0), - ) - .labelled_by(label.id); + ui.add_enabled(!d.no_author, egui::TextEdit::singleline(&mut d.author).hint_text(default_credit()).desired_width(260.0)) + .labelled_by(label.id); ui.end_row(); ui.label(""); ui.checkbox(&mut d.no_author, tl!("No credit line")); @@ -269,7 +266,7 @@ fn review_step(ui: &mut egui::Ui, d: &Draft) { let credit = if d.no_author { none.to_string() } else if d.author.trim().is_empty() { - tl!("Made with RustGIS · today's date").to_string() + default_credit().to_string() } else { d.author.trim().to_string() }; @@ -282,6 +279,12 @@ fn review_step(ui: &mut egui::Ui, d: &Draft) { } } +/// How the wizard names the credit line `layout.publication` writes when none is given +/// ("Made with RustGIS · {date}", dated when the layout is made). +fn default_credit() -> &'static str { + tl!("Made with RustGIS · today's date") +} + /// The wizard's width. const WIDTH: f32 = 380.0; diff --git a/docs/user-guide/layouts.md b/docs/user-guide/layouts.md index 4d88788724..6d3b761707 100644 --- a/docs/user-guide/layouts.md +++ b/docs/user-guide/layouts.md @@ -40,10 +40,10 @@ Layouts open as tabs next to the maps; while one is open, its groups lead the Pu - **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, 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 keeps the command's default, - but the title, which empty means none. A layout the command refuses is said, and the wizard + and the accent colour, then shows what was picked; **Create** makes the layout as the menu + does. A figure goes from its size to the review, as it takes no style, texts or accent. A + field left empty is left out (for the credit line, the dated default applies); the title is + the exception: empty, it means no title. A layout the command refuses is said, and the wizard stays open. - **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 From 651f9f2b41e8150907a62a96b580d8d16cf3bd8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Tue, 24 Nov 2026 13:47:35 -0500 Subject: [PATCH 11/13] refactor(layout): the wizard's text rows drop an unused hint; the app's accent named as such (#2850) --- crates/ui-egui/src/publicationwizard.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/crates/ui-egui/src/publicationwizard.rs b/crates/ui-egui/src/publicationwizard.rs index a77a30039d..569b8a4cd3 100644 --- a/crates/ui-egui/src/publicationwizard.rs +++ b/crates/ui-egui/src/publicationwizard.rs @@ -192,20 +192,20 @@ fn style_step(ui: &mut egui::Ui, d: &mut Draft) { /// The texts step: the title, subtitle, note, sources and credit line. fn texts_step(ui: &mut egui::Ui, d: &mut Draft) { 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, hint: &str| { + let line = |ui: &mut egui::Ui, label: &str, text: &mut String| { let caption = ui.label(label); - ui.add(egui::TextEdit::singleline(text).hint_text(hint).desired_width(260.0)).labelled_by(caption.id); + ui.add(egui::TextEdit::singleline(text).desired_width(260.0)).labelled_by(caption.id); ui.end_row(); }; let label = ui.label(tl!("Title")); let title = ui.add(egui::TextEdit::singleline(&mut d.title).hint_text(tl!("No title")).desired_width(260.0)).labelled_by(label.id); d.title_typed |= title.changed(); ui.end_row(); - line(ui, tl!("Subtitle"), &mut d.subtitle, ""); + line(ui, tl!("Subtitle"), &mut d.subtitle); let label = ui.label(tl!("Note")); ui.add(egui::TextEdit::multiline(&mut d.note).desired_rows(3).desired_width(260.0)).labelled_by(label.id); ui.end_row(); - line(ui, tl!("Sources"), &mut d.sources, ""); + 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()).desired_width(260.0)) .labelled_by(label.id); @@ -217,7 +217,7 @@ fn texts_step(ui: &mut egui::Ui, d: &mut Draft) { } /// The accent step: the style's own colour, or one picked. -fn accent_step(ui: &mut egui::Ui, d: &mut Draft, own: egui::Color32) { +fn accent_step(ui: &mut egui::Ui, d: &mut Draft, app_accent: egui::Color32) { let mut ticked = d.accent.is_some(); if ui .checkbox(&mut ticked, tl!("Pick a colour of your own")) @@ -228,7 +228,7 @@ fn accent_step(ui: &mut egui::Ui, d: &mut Draft, own: egui::Color32) { if !ticked { d.picked = d.accent; } - d.accent = ticked.then(|| d.picked.unwrap_or(own)); + d.accent = ticked.then(|| d.picked.unwrap_or(app_accent)); } if let Some(c) = &mut d.accent { egui::color_picker::color_edit_button_srgba(ui, c, egui::color_picker::Alpha::Opaque); @@ -621,7 +621,7 @@ mod tests { assert_eq!(h.state().dialogs.publication.as_ref().unwrap().title, "Rivers basins", "typed, so kept"); } - /// The review says what will be drawn: the default credit line as the sheet writes it, and for + /// The review says what will be drawn: the default credit line, dated when the layout is made, and for /// a figure, that its texts and accent are left to the caption. #[test] fn the_review_says_what_will_be_drawn() { From fcc56fcefa5a281df36e59477683de29da6e681a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Tue, 24 Nov 2026 14:53:19 -0500 Subject: [PATCH 12/13] fix(layout): the wizard's fields fit beside a longer label, so its window keeps one width (#2850) --- crates/ui-egui/src/publicationwizard.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/crates/ui-egui/src/publicationwizard.rs b/crates/ui-egui/src/publicationwizard.rs index 569b8a4cd3..eedc1d0e96 100644 --- a/crates/ui-egui/src/publicationwizard.rs +++ b/crates/ui-egui/src/publicationwizard.rs @@ -146,7 +146,7 @@ fn size_step(ui: &mut egui::Ui, d: &mut Draft) { let label = ui.label(tl!("Size")); egui::ComboBox::from_id_salt("publication_wizard_size_pick") .selected_text(size_label(&d.size)) - .width(260.0) + .width(field_width(ui)) .show_ui(ui, |ui| { for (id, ..) in PAGES { ui.selectable_value(&mut d.size, (*id).to_string(), size_label(id)); @@ -194,20 +194,22 @@ fn texts_step(ui: &mut egui::Ui, d: &mut Draft) { 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 caption = ui.label(label); - ui.add(egui::TextEdit::singleline(text).desired_width(260.0)).labelled_by(caption.id); + ui.add(egui::TextEdit::singleline(text).desired_width(field_width(ui))).labelled_by(caption.id); ui.end_row(); }; let label = ui.label(tl!("Title")); - let title = ui.add(egui::TextEdit::singleline(&mut d.title).hint_text(tl!("No title")).desired_width(260.0)).labelled_by(label.id); + let title = ui + .add(egui::TextEdit::singleline(&mut d.title).hint_text(tl!("No title")).desired_width(field_width(ui))) + .labelled_by(label.id); d.title_typed |= title.changed(); ui.end_row(); line(ui, tl!("Subtitle"), &mut d.subtitle); let label = ui.label(tl!("Note")); - ui.add(egui::TextEdit::multiline(&mut d.note).desired_rows(3).desired_width(260.0)).labelled_by(label.id); + ui.add(egui::TextEdit::multiline(&mut d.note).desired_rows(3).desired_width(field_width(ui))).labelled_by(label.id); 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()).desired_width(260.0)) + ui.add_enabled(!d.no_author, egui::TextEdit::singleline(&mut d.author).hint_text(default_credit()).desired_width(field_width(ui))) .labelled_by(label.id); ui.end_row(); ui.label(""); @@ -285,6 +287,13 @@ fn default_credit() -> &'static str { tl!("Made with RustGIS · today's date") } +/// A field's width beside its label: 260 points, or what the row leaves once a longer label +/// (Greek "Orientation", in a wider interface font) takes its share, so the row never widens the +/// window. +fn field_width(ui: &egui::Ui) -> f32 { + ui.available_width().min(260.0) +} + /// The wizard's width. const WIDTH: f32 = 380.0; From 70fddc0cb26f7694bc223e9036895f0dac303198 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Tue, 24 Nov 2026 15:01:51 -0500 Subject: [PATCH 13/13] fix(layout): the wizard narrows to a narrow screen, as the other dialogs do (#2850) --- crates/ui-egui/src/publicationwizard.rs | 60 +++++++++++++++++-------- 1 file changed, 41 insertions(+), 19 deletions(-) diff --git a/crates/ui-egui/src/publicationwizard.rs b/crates/ui-egui/src/publicationwizard.rs index eedc1d0e96..f095e8369e 100644 --- a/crates/ui-egui/src/publicationwizard.rs +++ b/crates/ui-egui/src/publicationwizard.rs @@ -294,7 +294,7 @@ fn field_width(ui: &egui::Ui) -> f32 { ui.available_width().min(260.0) } -/// The wizard's width. +/// The wizard's width, where the screen has room for it. const WIDTH: f32 = 380.0; /// The height every step takes: the style step's six styles and their descriptions, with room @@ -314,18 +314,22 @@ pub fn show(app: &mut RustGisApp, ctx: &egui::Context) { } let t = Tokens::get(ctx); let (mut open, mut close, mut create) = (true, false, false); + // Narrower on a screen too narrow for it, as the other dialogs are. + let frame = egui::Frame::window(&ctx.global_style()); + let width = crate::widgets::dialog_width(ctx, WIDTH, frame); egui::Window::new(tl!("Publication Layout Wizard")) .id(egui::Id::unique("publication_wizard")) + .frame(frame) .open(&mut open) .collapsible(false) .resizable(false) .auto_sized() // One width on every step and in every language: a long row wraps instead of widening it. - .max_width(WIDTH) + .max_width(width) .pivot(egui::Align2::CENTER_CENTER) .default_pos(ctx.content_rect().center()) .show(ctx, |ui| { - ui.set_width(WIDTH); + ui.set_width(width); let steps = d.steps(); let at = steps.iter().position(|s| *s == d.step).unwrap_or(0); let heading = i18n::fmt( @@ -399,24 +403,27 @@ mod tests { } fn harness(app: RustGisApp) -> egui_kittest::Harness<'static, RustGisApp> { + harness_sized(app, vec2(1400.0, 1000.0)) + } + + fn harness_sized(app: RustGisApp, size: egui::Vec2) -> egui_kittest::Harness<'static, RustGisApp> { // The dialogs alone: the ribbon has a Next of its own (the next extent). let mut fonts = false; - let mut h = - egui_kittest::Harness::builder().with_size(vec2(1400.0, 1000.0)).with_pixels_per_point(2.0).with_max_steps(64).build_ui_state( - move |ui, app: &mut RustGisApp| { - if !fonts { - // The app's fonts and theme at a high-density screen's scale, so sizes, spacing - // and the rounding of each line are the ones the app draws there. - crate::theme::install_fonts(ui.ctx(), &[], None); - let theme = app.current_theme(); - crate::theme::apply(ui.ctx(), &theme.tokens, &theme.metrics); - fonts = true; - return; - } - crate::dialogs::show(app, &ui.ctx().clone()); - }, - app, - ); + let mut h = egui_kittest::Harness::builder().with_size(size).with_pixels_per_point(2.0).with_max_steps(64).build_ui_state( + move |ui, app: &mut RustGisApp| { + if !fonts { + // The app's fonts and theme at a high-density screen's scale, so sizes, spacing + // and the rounding of each line are the ones the app draws there. + crate::theme::install_fonts(ui.ctx(), &[], None); + let theme = app.current_theme(); + crate::theme::apply(ui.ctx(), &theme.tokens, &theme.metrics); + fonts = true; + return; + } + crate::dialogs::show(app, &ui.ctx().clone()); + }, + app, + ); h.run_steps(4); h } @@ -711,6 +718,21 @@ mod tests { assert_eq!(h.get_by_label("Classic").rect(), before, "the styles scroll: they don't fit the box"); } + /// On a screen narrower than the wizard, it narrows to fit, as the other dialogs do: Next and + /// the step's text stay on the screen. + #[test] + fn a_narrow_screen_keeps_the_wizard_on_it() { + let mut app = app(); + open(&mut app); + app.dialogs.publication.as_mut().unwrap().step = Step::Style; + let h = harness_sized(app, vec2(320.0, 900.0)); + let next = h.get_by_role_and_label(Role::Button, "Next").rect(); + assert!(next.left() >= 0.0 && next.right() <= 320.0, "Next at {next:?} on a screen 320 wide"); + let (_, about) = crate::ribbon::publication_style("panel").unwrap(); + let text = h.get_by_label(about).rect(); + assert!(text.right() <= 320.0, "{text:?} runs off a screen 320 wide"); + } + /// Cancel closes the wizard with nothing made, and the next opening starts over. #[test] fn cancel_makes_nothing_and_the_next_opening_starts_over() {