From 36c0b5b20b3cad400561ca8278434912ff587a6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Sat, 28 Nov 2026 07:57:52 -0500 Subject: [PATCH 1/3] feat(ui): the Publication Layout Wizard asks how the north arrow, scale bar and legend look --- .../ui-egui/src/publicationwizard/elements.rs | 378 +++++++++++++++++- docs/user-guide/layouts.md | 6 +- 2 files changed, 368 insertions(+), 16 deletions(-) diff --git a/crates/ui-egui/src/publicationwizard/elements.rs b/crates/ui-egui/src/publicationwizard/elements.rs index ffe577eadf..d5cd429950 100644 --- a/crates/ui-egui/src/publicationwizard/elements.rs +++ b/crates/ui-egui/src/publicationwizard/elements.rs @@ -2,7 +2,11 @@ use super::arrange::{LOCATOR, NORTH_ARROW, SCALE_BAR, surround_labels}; use super::*; use rustgis_engine::cmd::layout::{publication_style_cards, publication_style_has_column}; -use rustgis_engine::map::layout::colorbar_layer; +use rustgis_engine::map::layout::{ArrowStyle, MAX_LEGEND_COLUMNS, ScaleBarStyle, ScaleUnits, colorbar_layer}; +use rustgis_engine::render::layout::legend_lists; + +/// The longest legend title `layout.publication` takes, in characters. +const MAX_LEGEND_TITLE: usize = 200; /// The locator asked for; `Default` leaves it to `layout.publication`. #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] @@ -23,7 +27,7 @@ pub enum NorthChoice { None, } -/// What the step asks. A box the sheet can't use keeps its tick, and isn't sent. +/// What the step asks. A control the sheet can't use keeps its answer, which isn't sent. #[derive(Clone, Debug, PartialEq, Eq)] pub struct Elements { pub locator: LocatorChoice, @@ -39,6 +43,13 @@ pub struct Elements { pub veil: bool, /// A decimal comma rather than a point. pub comma: bool, + pub north_style: ArrowStyle, + pub scale_units: ScaleUnits, + pub scale_style: ScaleBarStyle, + /// The legend's title; blank, it has none. + pub legend_title: String, + /// The legend's columns, or `None` for the placement's pick. + pub legend_columns: Option, } impl Default for Elements { @@ -53,6 +64,11 @@ impl Default for Elements { scale_bar: true, veil: true, comma: false, + north_style: ArrowStyle::default(), + scale_units: ScaleUnits::default(), + scale_style: ScaleBarStyle::default(), + legend_title: String::new(), + legend_columns: None, } } } @@ -65,6 +81,11 @@ pub(super) enum Control { Colorbar, ScaleBar, Veil, + NorthStyle, + /// The scale bar's units and style. + ScaleLook, + /// The legend's title and columns. + LegendLook, } /// What `layout.publication` may put over or beside the map, as far as the wizard can tell @@ -144,7 +165,34 @@ impl Draft { Control::ScaleBar => !self.whole_globe(s), // The command veils only what is under surrounds over the map. Control::Veil => !self.column() && self.draws_legend_place(s), + Control::NorthStyle => self.draws_arrow(s), + Control::ScaleLook => self.draws_scale_bar(s), + Control::LegendLook => self.elements.legend && legend_lists_rows(s), + } + } + + /// The north arrow's style, when one other than the default is picked for an arrow drawn. + fn north_look(&self, s: &Session) -> Option { + let style = self.elements.north_style; + (style != ArrowStyle::default() && self.usable(Control::NorthStyle, s)).then_some(style) + } + + /// The scale bar's units and style, each when picked for a bar drawn. + fn scale_look(&self, s: &Session) -> (Option, Option) { + if !self.usable(Control::ScaleLook, s) { + return (None, None); + } + let (units, style) = (self.elements.scale_units, self.elements.scale_style); + ((units != ScaleUnits::default()).then_some(units), (style != ScaleBarStyle::default()).then_some(style)) + } + + /// The legend's title and columns, each when given for a legend with rows. + fn legend_look(&self, s: &Session) -> (Option<&str>, Option) { + if !self.usable(Control::LegendLook, s) { + return (None, None); } + let title = self.elements.legend_title.trim(); + ((!title.is_empty()).then_some(title), self.elements.legend_columns) } /// What Create sends: [`Draft::params`] and the elements step's answers, a choice left to the @@ -158,19 +206,34 @@ impl Draft { LocatorChoice::Inset => Some("inset"), LocatorChoice::None => Some("none"), }; - let north = match e.north { - NorthChoice::Auto => None, - NorthChoice::Always => Some("always"), - NorthChoice::None => Some("none"), + // A look makes its element an object; without one it goes as its mode alone. + let north = match (e.north, self.north_look(s)) { + (NorthChoice::None, _) => Some("none".into()), + (NorthChoice::Always, None) => Some("always".into()), + (NorthChoice::Auto, None) => None, + (NorthChoice::Always, Some(style)) => Some(json!({"show": "always", "style": style.code()})), + (NorthChoice::Auto, Some(style)) => Some(json!({"show": "auto", "style": style.code()})), + }; + let (units, style) = self.scale_look(s); + let scale_bar = if !e.scale_bar && self.usable(Control::ScaleBar, s) { + Some("none".into()) + } else { + object([("units", units.map(|u| u.code().into())), ("style", style.map(|v| v.code().into()))]) + }; + let (title, columns) = self.legend_look(s); + let legend = if !e.legend { + Some("none".into()) + } else { + object([("title", title.map(Value::from)), ("columns", columns.map(Value::from))]) }; for (key, value) in [ ("locator", locator.map(Value::from)), - ("northArrow", north.map(Value::from)), - ("legend", (!e.legend).then(|| "none".into())), + ("northArrow", north), + ("legend", legend), ("legendBox", (e.legend_box && self.usable(Control::LegendBox, s)).then(|| "always".into())), ("contextInLegend", (e.context && self.usable(Control::Context, s)).then(|| true.into())), ("colorbar", (!e.colorbar && self.usable(Control::Colorbar, s)).then(|| "none".into())), - ("scaleBar", (!e.scale_bar && self.usable(Control::ScaleBar, s)).then(|| "none".into())), + ("scaleBar", scale_bar), ("veil", (!e.veil && self.usable(Control::Veil, s)).then(|| false.into())), ("decimal", e.comma.then(|| ",".into())), ] { @@ -182,6 +245,20 @@ impl Draft { } } +/// The object of the options given, or `None` with none. +fn object(options: [(&str, Option); N]) -> Option { + let given: serde_json::Map = options.into_iter().filter_map(|(k, v)| Some((k.to_string(), v?))).collect(); + (!given.is_empty()).then(|| given.into()) +} + +/// Whether the active map has a layer a legend gives rows to: one it shows and can list, as the +/// command picks them, or a web layer drawn with a legend picture. +fn legend_lists_rows(s: &Session) -> bool { + let map = s.map(); + map.layers.iter().any(|l| map.shows(l) && legend_lists(l)) + || map.tiles.iter().any(|t| t.draws() && t.opacity > 0.0 && !t.legends.is_empty()) +} + /// Why the colorbar's box is off: [`colorbar_layer`] also gives a raster whose pixels, and so /// colour scale, aren't here, still on their way or failed. fn colorbar_off_reason(s: &Session) -> &'static str { @@ -192,6 +269,11 @@ fn colorbar_off_reason(s: &Session) -> &'static str { } } +/// The parts there are, on one line. +fn joined(parts: [Option<&str>; 2]) -> String { + parts.into_iter().flatten().collect::>().join(" · ") +} + /// What is on, a line each, as the review lists it. pub(super) fn elements_value(s: &Session, d: &Draft) -> String { let e = &d.elements; @@ -207,18 +289,32 @@ pub(super) fn elements_value(s: &Session, d: &Draft) -> String { if d.draws_arrow(s) { // Left to the extent, the command leaves it out from a span only Create measures. let when = if e.north == NorthChoice::Always { tl_raw!("Always") } else { tl_raw!("Auto (none from 20°)") }; - on.push(i18n::fmt("{surround}: {choice}", &[("surround", surround_labels()[NORTH_ARROW]), ("choice", when)])); - } + let style = d.north_look(s).map(|v| tl_raw!(v.label())); + let choice = joined([Some(when), style]); + on.push(i18n::fmt("{surround}: {choice}", &[("surround", surround_labels()[NORTH_ARROW]), ("choice", &choice)])); + } + // The legend and scale bar by name, and the looks sent with them. + let looked = |name: &str, look: String| match look.is_empty() { + true => name.to_string(), + false => i18n::fmt("{surround}: {choice}", &[("surround", name), ("choice", &look)]), + }; + let (title, columns) = d.legend_look(s); + let title = title.map(|t| i18n::fmt("“{title}”", &[("title", t)])); + let columns = columns.map(|n| i18n::fmt("Columns: {count}", &[("count", &n.to_string())])); + let legend = looked(tl_raw!("Legend"), joined([title.as_deref(), columns.as_deref()])); + let (units, style) = d.scale_look(s); + let scale = joined([units.map(|u| tl_raw!(u.label())), style.map(|v| tl_raw!(v.label()))]); + let scale = looked(tl_raw!("Scale bar"), scale); let mut push_if = |is: bool, line: &str| { if is { on.push(line.to_string()); } }; - push_if(e.legend, tl!("Legend")); + push_if(e.legend, &legend); push_if(e.legend_box && d.usable(Control::LegendBox, s), tl!("Always on a box")); push_if(e.context && d.usable(Control::Context, s), tl!("Context layers listed")); push_if(d.draws_colorbar(s), tl!("Colorbar")); - push_if(d.draws_scale_bar(s), tl!("Scale bar")); + push_if(d.draws_scale_bar(s), &scale); push_if(!e.veil && d.usable(Control::Veil, s), tl!("No veil")); push_if(true, if e.comma { tl!("Decimal comma") } else { tl!("Decimal point") }); on.join("\n") @@ -242,6 +338,12 @@ pub(super) fn elements_step(ui: &mut egui::Ui, s: &Session, d: &mut Draft) { ui.radio_value(choice, NorthChoice::Always, tl!("Always")); ui.radio_value(choice, NorthChoice::None, tl!("None")); }); + let usable = d.usable(Control::NorthStyle, s); + ui.indent("publication_wizard_north", |ui| { + let why = tl!("No north arrow is drawn."); + let style = &mut d.elements.north_style; + pick_list(ui, "publication_wizard_north_style", tl!("Style"), (usable, why), style, &ArrowStyle::ALL, |v| tl!(v.label())); + }); ui.add_space(4.0); // A box the sheet has no use for is off, its tick kept for one that has. let tick = |ui: &mut egui::Ui, usable: bool, on: &mut bool, label: &str, why: &str| { @@ -259,6 +361,7 @@ pub(super) fn elements_step(ui: &mut egui::Ui, s: &Session, d: &mut Draft) { if own_box { ui.label(egui::RichText::new(own_note).small().weak()); } + legend_look_rows(ui, s, d); }); let usable = d.usable(Control::Colorbar, s); let why = colorbar_off_reason(s); @@ -270,6 +373,17 @@ pub(super) fn elements_step(ui: &mut egui::Ui, s: &Session, d: &mut Draft) { if !usable { ui.label(egui::RichText::new(why).small().weak()); } + let usable = d.usable(Control::ScaleLook, s); + ui.indent("publication_wizard_scale", |ui| { + let why = tl!("No scale bar is drawn."); + let e = &mut d.elements; + pick_list(ui, "publication_wizard_scale_units", tl!("Units"), (usable, why), &mut e.scale_units, &ScaleUnits::ALL, |v| { + tl!(v.label()) + }); + pick_list(ui, "publication_wizard_scale_style", tl!("Style"), (usable, why), &mut e.scale_style, &ScaleBarStyle::ALL, |v| { + tl!(v.label()) + }); + }); let usable = d.usable(Control::Veil, s); let why = if d.column() { tl!("In this style the map isn't veiled.") } else { tl!("There is no legend or colorbar to make room for.") }; tick(ui, usable, &mut d.elements.veil, tl!("Veil the map outside the extent if the legend needs room"), why); @@ -281,15 +395,74 @@ pub(super) fn elements_step(ui: &mut egui::Ui, s: &Session, d: &mut Draft) { }); } +/// A caption and the list of `all` that picks `value`, off with its reason. +fn pick_list( + ui: &mut egui::Ui, + id: &str, + caption: &str, + (usable, why): (bool, &str), + value: &mut T, + all: &[T], + name: impl Fn(T) -> &'static str, +) { + ui.horizontal_wrapped(|ui| { + let caption = ui.label(caption); + ui.add_enabled_ui(usable, |ui| { + egui::ComboBox::from_id_salt(id) + .selected_text(name(*value)) + .show_ui(ui, |ui| { + for &v in all { + ui.selectable_value(value, v, name(v)); + } + }) + .response + .labelled_by(caption.id) + .on_disabled_hover_text(why); + }); + }); +} + +/// The legend's title and columns. +fn legend_look_rows(ui: &mut egui::Ui, s: &Session, d: &mut Draft) { + let usable = d.usable(Control::LegendLook, s); + let why = if d.elements.legend { tl!("The map has no layer the legend lists.") } else { tl!("There is no legend to title or split.") }; + ui.horizontal_wrapped(|ui| { + let caption = ui.label(tl!("Title")); + let edit = egui::TextEdit::singleline(&mut d.elements.legend_title).char_limit(MAX_LEGEND_TITLE).desired_width(field_width(ui)); + ui.add_enabled(usable, edit).labelled_by(caption.id).on_disabled_hover_text(why); + }); + let columns: Vec> = std::iter::once(None).chain((1..=MAX_LEGEND_COLUMNS).map(Some)).collect(); + ui.horizontal_wrapped(|ui| { + let caption = ui.label(tl!("Columns")); + ui.add_enabled_ui(usable, |ui| { + let name = |n: Option| n.map_or_else(|| tl!("Auto").to_string(), |n| n.to_string()); + egui::ComboBox::from_id_salt("publication_wizard_legend_columns") + .selected_text(name(d.elements.legend_columns)) + .show_ui(ui, |ui| { + for n in columns { + ui.selectable_value(&mut d.elements.legend_columns, n, name(n)); + } + }) + .response + .labelled_by(caption.id) + .on_disabled_hover_text(why); + }); + }); + if d.elements.legend && !usable { + ui.label(egui::RichText::new(why).small().weak()); + } +} + #[cfg(test)] mod tests { use super::super::harness::*; use super::*; use egui::accesskit::Role; use egui_kittest::kittest::{NodeT, Queryable}; + use rustgis_engine::data::ogc::Legend; use rustgis_engine::data::raster::{ColorHint, Crs, GeoTransform, Raster}; use rustgis_engine::map::layout::ElementKind; - use rustgis_engine::map::{Projection, RasterLayer}; + use rustgis_engine::map::{Projection, RasterLayer, TileKind, TileLayer}; type Wizard = egui_kittest::Harness<'static, RustGisApp>; @@ -330,6 +503,8 @@ mod tests { } fn click_box(h: &mut Wizard, label: &str) { + ticked_box(h, label).scroll_to_me(); + h.run_steps(4); ticked_box(h, label).click(); h.run_steps(4); } @@ -337,6 +512,9 @@ mod tests { /// The `nth` radio button called `label`, top to bottom: None is both the locator's and the /// north arrow's. fn pick(h: &mut Wizard, label: &str, nth: usize) { + // The step scrolls: one below the window is brought into view first. + h.get_all_by_role_and_label(Role::RadioButton, label).nth(nth).expect("the radio").scroll_to_me(); + h.run_steps(4); h.get_all_by_role_and_label(Role::RadioButton, label).nth(nth).expect("the radio").click(); h.run_steps(4); } @@ -469,6 +647,173 @@ mod tests { assert_eq!(added(&app.session, &d), json!({"scaleBar": "none"})); } + /// Elements with a look picked for each of the three. + fn looks() -> Elements { + Elements { + north_style: ArrowStyle::Compass, + scale_units: ScaleUnits::Kilometers, + scale_style: ScaleBarStyle::Line, + legend_title: " Key ".into(), + legend_columns: Some(3), + ..Elements::default() + } + } + + /// A look picked sends its element as an object, the title trimmed, on a sheet and a figure. + #[test] + fn a_look_picked_is_sent_with_its_element() { + let app = app(); + for size in ["a4", "figure-1col"] { + let mut d = Draft::new(&app.session); + d.size = size.into(); + d.elements = looks(); + let want = json!({ + "northArrow": {"show": "auto", "style": "compass"}, + "scaleBar": {"units": "kilometers", "style": "line"}, + "legend": {"title": "Key", "columns": 3}, + }); + assert_eq!(added(&app.session, &d), want, "{size}"); + d.elements = Elements { north: NorthChoice::Always, north_style: ArrowStyle::Star, ..Elements::default() }; + assert_eq!(added(&app.session, &d), json!({"northArrow": {"show": "always", "style": "star"}}), "{size}"); + } + } + + /// Only what differs from the default is sent: a default style, a blank title and Auto columns + /// are left to the command. + #[test] + fn only_what_differs_from_the_default_is_sent() { + let app = app(); + let mut d = Draft::new(&app.session); + d.elements = Elements { north: NorthChoice::Always, legend_title: " ".into(), ..Elements::default() }; + assert_eq!(added(&app.session, &d), json!({"northArrow": "always"})); + d.elements = Elements { scale_style: ScaleBarStyle::Stepped, legend_columns: Some(1), ..Elements::default() }; + assert_eq!(added(&app.session, &d), json!({"scaleBar": {"style": "stepped"}, "legend": {"columns": 1}})); + d.elements = Elements { scale_units: ScaleUnits::Feet, legend_title: "Key".into(), ..Elements::default() }; + assert_eq!(added(&app.session, &d), json!({"scaleBar": {"units": "feet"}, "legend": {"title": "Key"}})); + } + + /// The look of an element left out isn't sent: the element goes as before. + #[test] + fn the_look_of_an_element_left_out_isnt_sent() { + let mut app = app(); + let mut d = Draft::new(&app.session); + d.elements = Elements { north: NorthChoice::None, legend: false, scale_bar: false, ..looks() }; + assert_eq!(added(&app.session, &d), json!({"northArrow": "none", "legend": "none", "scaleBar": "none"})); + globe(&mut app); + d.elements = looks(); + assert_eq!(added(&app.session, &d), json!({"legend": {"title": "Key", "columns": 3}}), "a whole globe"); + } + + /// With no layer for the legend to list, its title and columns aren't sent: a raster on a + /// ramp is keyed by the colorbar, a hidden layer by nothing. A web layer with a legend + /// picture is one to list. + #[test] + fn with_nothing_to_list_the_legend_has_no_look() { + let mut app = app(); + let mut d = Draft::new(&app.session); + d.elements = Elements { legend_title: "Key".into(), legend_columns: Some(2), ..Elements::default() }; + for l in &mut app.session.map_mut().layers { + l.visible = false; + } + assert_eq!(added(&app.session, &d), json!({}), "all hidden"); + raster(&mut app); + assert_eq!(added(&app.session, &d), json!({}), "a raster on a ramp"); + let mut tile = TileLayer::new("Parcels", TileKind::Raster, "https://tiles.invalid/{z}/{x}/{y}.png"); + tile.legends = vec![Legend { url: "https://tiles.invalid/legend.png".into(), ..Default::default() }]; + app.session.map_mut().tiles.push(tile); + assert_eq!(added(&app.session, &d), json!({"legend": {"title": "Key", "columns": 2}}), "a web layer's picture"); + } + + /// The `nth` combo box captioned `caption`, top to bottom: Style is both the north arrow's + /// and the scale bar's. + fn combo<'a>(h: &'a Wizard, caption: &'a str, nth: usize) -> egui_kittest::Node<'a> { + h.get_all_by_role_and_label(Role::ComboBox, caption).nth(nth).expect("the list") + } + + fn choose(h: &mut Wizard, caption: &str, nth: usize, value: &str) { + combo(h, caption, nth).click(); + h.run_steps(4); + h.get_by_label(value).click(); + h.run_steps(4); + } + + /// Each list and the title box set their answer. + #[test] + fn the_look_controls_set_the_answers() { + let mut h = step_of(|_| {}); + choose(&mut h, "Style", 0, "Compass rose"); + choose(&mut h, "Units", 0, "Kilometers"); + choose(&mut h, "Style", 1, "Single line"); + choose(&mut h, "Columns", 0, "3"); + h.get_by_role_and_label(Role::TextInput, "Title").focus(); + h.run_steps(4); + h.get_by_role_and_label(Role::TextInput, "Title").type_text(" Key "); + h.run_steps(4); + assert_eq!(draft(&h).elements, looks()); + } + + /// A look with no element to take it is off; its answer is kept. + #[test] + fn a_look_with_no_element_is_off() { + let off_combo = |h: &Wizard, caption: &str, nth| combo(h, caption, nth).accesskit_node().is_disabled(); + let title_off = |h: &Wizard| h.get_by_role_and_label(Role::TextInput, "Title").accesskit_node().is_disabled(); + let h = step_of(|_| {}); + assert!(!off_combo(&h, "Style", 0) && !off_combo(&h, "Style", 1) && !off_combo(&h, "Units", 0)); + assert!(!off_combo(&h, "Columns", 0) && !title_off(&h)); + let h = step_of(|app| { + let e = &mut app.dialogs.publication.as_mut().unwrap().elements; + *e = Elements { north: NorthChoice::None, legend: false, scale_bar: false, ..looks() }; + }); + assert!(off_combo(&h, "Style", 0) && off_combo(&h, "Style", 1) && off_combo(&h, "Units", 0)); + assert!(off_combo(&h, "Columns", 0) && title_off(&h)); + assert_eq!(draft(&h).elements.legend_title, " Key ", "kept"); + let h = step_of(|app| { + for l in &mut app.session.map_mut().layers { + l.visible = false; + } + }); + assert!(off_combo(&h, "Columns", 0) && title_off(&h), "nothing to list"); + assert!(h.query_by_label_contains("no layer the legend lists").is_some(), "said"); + } + + /// The review names the looks that are sent, and no default one. + #[test] + fn the_review_names_the_looks() { + let review = |e: Elements| { + step_of(|app| { + let d = app.dialogs.publication.as_mut().unwrap(); + (d.step, d.elements) = (Step::Review, e); + }) + }; + let h = review(looks()); + let want = "Locator: Default (globe)\nNorth arrow: Auto (none from 20°) · Compass rose\n\ + Legend: “Key” · Columns: 3\nScale bar: Kilometers · Single line\nDecimal point"; + assert!(h.query_by_label(want).is_some()); + let h = review(Elements { legend: false, ..looks() }); + assert!(h.query_by_label_contains("Key").is_none(), "no legend, no title"); + } + + /// Create draws the looks picked; Undo takes the layout away. + #[test] + fn create_draws_the_looks_picked() { + let mut app = app(); + open(&mut app); + let d = app.dialogs.publication.as_mut().unwrap(); + d.step = Step::Review; + d.elements = Elements { north: NorthChoice::Always, ..looks() }; + 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(); + let find = |f: &dyn Fn(&ElementKind) -> bool| l.elements.iter().any(|e| f(&e.kind)); + assert!(find(&|k| matches!(k, ElementKind::NorthArrow { style: ArrowStyle::Compass, .. })), "the arrow"); + let bar = |k: &ElementKind| matches!(k, ElementKind::ScaleBar { units: ScaleUnits::Kilometers, style: ScaleBarStyle::Line, .. }); + assert!(find(&bar), "the scale bar"); + assert!(find(&|k| matches!(k, ElementKind::Legend { title, columns: 3, .. } if title == "Key")), "the legend"); + h.state_mut().run("edit.undo", Value::Null).unwrap(); + assert_eq!(h.state().session.project.layouts.len(), before); + } + /// A raster on a colour scale on top of the map. fn raster(app: &mut RustGisApp) { let values: Vec = (0..16).map(|v| v as f32).collect(); @@ -513,6 +858,7 @@ mod tests { scale_bar: false, veil: false, comma: true, + ..Elements::default() }; assert_eq!(draft(&h).elements, want); click_box(&mut h, "Legend"); @@ -551,6 +897,10 @@ mod tests { } let rect = ticked_box(&h, "Veil the map outside the extent if the legend needs room").rect(); assert!(rect.right() <= 320.0, "{rect:?}"); + for (caption, nth) in [("Style", 0), ("Units", 0), ("Style", 1), ("Columns", 0)] { + let rect = combo(&h, caption, nth).rect(); + assert!(rect.left() >= 0.0 && rect.right() <= 320.0, "{caption} {nth} at {rect:?}"); + } } /// The review lists what is on, on a sheet and on a figure. diff --git a/docs/user-guide/layouts.md b/docs/user-guide/layouts.md index 4a621cd16a..16ae930b2c 100644 --- a/docs/user-guide/layouts.md +++ b/docs/user-guide/layouts.md @@ -59,8 +59,10 @@ Layouts open as tabs next to the maps; while one is open, its groups lead the Pu be, a globe, an inset or none), the north arrow (auto, always or none), the legend or not, which can be set always on a box and to list the context layers, the colorbar and the scale bar or not, whether the map may be veiled for the legend's room, and the decimal mark; a choice the - sheet can't use is off and isn't sent. 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 + sheet can't use is off and isn't sent. Under them, the north arrow's style, the scale bar's + units and style, and the legend's title and columns (Auto, or 1 to 6) can be picked. 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 surround left out in the elements takes none, as a figure's locator unless asked for); a chosen one can be made the favourite, once the layout is From 8cd9f6caaac81854f93cb8f68e6b81d043aa762e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Sat, 28 Nov 2026 08:08:02 -0500 Subject: [PATCH 2/3] refactor(ui): ask the renderer which web layers a legend lists --- crates/render/src/layout/legend.rs | 2 +- crates/ui-egui/src/publicationwizard/elements.rs | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/render/src/layout/legend.rs b/crates/render/src/layout/legend.rs index 7c9bac3122..d0c00f2a73 100644 --- a/crates/render/src/layout/legend.rs +++ b/crates/render/src/layout/legend.rs @@ -423,7 +423,7 @@ pub(super) fn picture_size(p: &rustgis_tiles::cache::Payload) -> (f32, f32) { } /// Whether a legend lists a WMS or WMTS layer: drawn, and with a legend. -pub(super) fn tile_listed(t: &rustgis_map::TileLayer) -> bool { +pub fn tile_listed(t: &rustgis_map::TileLayer) -> bool { t.draws() && t.opacity > 0.0 && !t.legends.is_empty() } diff --git a/crates/ui-egui/src/publicationwizard/elements.rs b/crates/ui-egui/src/publicationwizard/elements.rs index d5cd429950..1f4258149e 100644 --- a/crates/ui-egui/src/publicationwizard/elements.rs +++ b/crates/ui-egui/src/publicationwizard/elements.rs @@ -3,7 +3,7 @@ use super::arrange::{LOCATOR, NORTH_ARROW, SCALE_BAR, surround_labels}; use super::*; use rustgis_engine::cmd::layout::{publication_style_cards, publication_style_has_column}; use rustgis_engine::map::layout::{ArrowStyle, MAX_LEGEND_COLUMNS, ScaleBarStyle, ScaleUnits, colorbar_layer}; -use rustgis_engine::render::layout::legend_lists; +use rustgis_engine::render::layout::{legend_lists, tile_listed}; /// The longest legend title `layout.publication` takes, in characters. const MAX_LEGEND_TITLE: usize = 200; @@ -251,12 +251,12 @@ fn object(options: [(&str, Option); N]) -> Option (!given.is_empty()).then(|| given.into()) } -/// Whether the active map has a layer a legend gives rows to: one it shows and can list, as the -/// command picks them, or a web layer drawn with a legend picture. +/// Whether the active map has a layer a legend can give rows to: one it shows and can list, or a +/// web layer it lists by its picture. The sheet's scale and context layers, which can still leave +/// the legend empty, are known only to the command. fn legend_lists_rows(s: &Session) -> bool { let map = s.map(); - map.layers.iter().any(|l| map.shows(l) && legend_lists(l)) - || map.tiles.iter().any(|t| t.draws() && t.opacity > 0.0 && !t.legends.is_empty()) + map.layers.iter().any(|l| map.shows(l) && legend_lists(l)) || map.tiles.iter().any(tile_listed) } /// Why the colorbar's box is off: [`colorbar_layer`] also gives a raster whose pixels, and so From bd210e88d6b78a8def69f2092066e7a62757245e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Sat, 28 Nov 2026 08:12:39 -0500 Subject: [PATCH 3/3] fix(ui): put the wizard's legend and scale bar review lines in display form once --- .../ui-egui/src/publicationwizard/elements.rs | 32 ++++++++++++++++--- docs/user-guide/layouts.md | 8 ++--- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/crates/ui-egui/src/publicationwizard/elements.rs b/crates/ui-egui/src/publicationwizard/elements.rs index 1f4258149e..3a7b11d08b 100644 --- a/crates/ui-egui/src/publicationwizard/elements.rs +++ b/crates/ui-egui/src/publicationwizard/elements.rs @@ -293,14 +293,15 @@ pub(super) fn elements_value(s: &Session, d: &Draft) -> String { let choice = joined([Some(when), style]); on.push(i18n::fmt("{surround}: {choice}", &[("surround", surround_labels()[NORTH_ARROW]), ("choice", &choice)])); } - // The legend and scale bar by name, and the looks sent with them. + // The legend and scale bar by name, and the looks sent with them: the parts in logical order, + // each line put in display form once, as a whole. let looked = |name: &str, look: String| match look.is_empty() { - true => name.to_string(), + true => i18n::display(name), false => i18n::fmt("{surround}: {choice}", &[("surround", name), ("choice", &look)]), }; let (title, columns) = d.legend_look(s); - let title = title.map(|t| i18n::fmt("“{title}”", &[("title", t)])); - let columns = columns.map(|n| i18n::fmt("Columns: {count}", &[("count", &n.to_string())])); + let title = title.map(|t| i18n::fmt_raw("“{title}”", &[("title", t)])); + let columns = columns.map(|n| i18n::fmt_raw("Columns: {count}", &[("count", &n.to_string())])); let legend = looked(tl_raw!("Legend"), joined([title.as_deref(), columns.as_deref()])); let (units, style) = d.scale_look(s); let scale = joined([units.map(|u| tl_raw!(u.label())), style.map(|v| tl_raw!(v.label()))]); @@ -793,6 +794,29 @@ mod tests { assert!(h.query_by_label_contains("Key").is_none(), "no legend, no title"); } + /// In a right-to-left language the legend's and scale bar's lines are put in display form once, + /// as a whole, with a look and without one. + #[test] + fn the_review_shows_the_looks_right_to_left() { + let app = app(); + let previous = i18n::current(); + i18n::set_current(i18n::lang_from_tag("fa").unwrap()); + let mut d = Draft::new(&app.session); + let title = "نقشه GIS 2026"; + d.elements = Elements { legend_title: title.into(), legend_columns: Some(2), ..Elements::default() }; + let looked = elements_value(&app.session, &d); + let parts = + format!("{} · {}", i18n::fmt_raw("“{title}”", &[("title", title)]), i18n::fmt_raw("Columns: {count}", &[("count", "2")])); + let legend = i18n::fmt("{surround}: {choice}", &[("surround", tl_raw!("Legend")), ("choice", &parts)]); + let bare = [i18n::display(tl_raw!("Legend")), i18n::display(tl_raw!("Scale bar"))]; + d.elements = Elements::default(); + let plain = elements_value(&app.session, &d); + i18n::set_current(previous); + assert!(looked.lines().any(|l| l == legend), "{looked}"); + assert!(looked.lines().any(|l| l == bare[1]), "{looked}"); + assert!(plain.lines().any(|l| l == bare[0]), "{plain}"); + } + /// Create draws the looks picked; Undo takes the layout away. #[test] fn create_draws_the_looks_picked() { diff --git a/docs/user-guide/layouts.md b/docs/user-guide/layouts.md index 16ae930b2c..dcbecad388 100644 --- a/docs/user-guide/layouts.md +++ b/docs/user-guide/layouts.md @@ -62,10 +62,10 @@ Layouts open as tabs next to the maps; while one is open, its groups lead the Pu sheet can't use is off and isn't sent. Under them, the north arrow's style, the scale bar's units and style, and the legend's title and columns (Auto, or 1 to 6) can be picked. 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 surround left out in the elements takes none, as - a figure's locator unless asked for); a chosen one can be made the favourite, once the layout is + **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 surround left out in the elements takes none, as a figure's locator unless asked for); + 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 elements, 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.