diff --git a/crates/engine/src/cmd/layout/publication/mod.rs b/crates/engine/src/cmd/layout/publication/mod.rs index 0c72077341..8d5dd4f22e 100644 --- a/crates/engine/src/cmd/layout/publication/mod.rs +++ b/crates/engine/src/cmd/layout/publication/mod.rs @@ -188,7 +188,7 @@ pub(in crate::cmd::layout) fn publication(s: &mut Session, p: &Value) -> CmdResu ); } let panels = match panels? { - None if mosaic => return Err(PANELS_WANTED.into()), + None if mosaic => return Err(panels_wanted()), panels => panels.unwrap_or_default(), }; // White is the page's own colour, kept as none, as `layout.page` keeps it. diff --git a/crates/engine/src/cmd/layout/publication/mosaic.rs b/crates/engine/src/cmd/layout/publication/mosaic.rs index 5ec2422e8f..0dc276b6d7 100644 --- a/crates/engine/src/cmd/layout/publication/mosaic.rs +++ b/crates/engine/src/cmd/layout/publication/mosaic.rs @@ -4,17 +4,15 @@ use super::*; use rustgis_map::layout::ExtentIndicator; -/// The most panels a mosaic takes: past six, A4's cells are too small to read. -const MAX_PANELS: usize = 6; - /// The share of the map area's longer side the key map takes. pub(super) const KEY_MAP_SHARE: f64 = 0.55; /// What a mosaic sheet given no list of panels, or one of the wrong length, is told. -pub(super) const PANELS_WANTED: &str = "a mosaic sheet takes panels: a list of 1 to 6 extents, each [west, south, east, north] in degrees, or an object with an \"extent\" or a \"bookmark\""; - -/// The most characters a panel's label takes. -const MAX_LABEL: usize = 80; +pub(super) fn panels_wanted() -> String { + format!( + "a mosaic sheet takes panels: a list of 1 to {PUBLICATION_MAX_PANELS} extents, each [west, south, east, north] in degrees, or an object with an \"extent\" or a \"bookmark\"" + ) +} /// One detail map of a mosaic: what it shows, its label, and the scale it is drawn at when given /// (#3579). @@ -29,7 +27,7 @@ pub(super) struct Panel { /// `"scale"` if it has them. pub(super) fn publication_panels(s: &Session, p: &Value) -> Result>, String> { let Some(v) = p.get("panels").filter(|v| !v.is_null()) else { return Ok(None) }; - let list = v.as_array().filter(|a| (1..=MAX_PANELS).contains(&a.len())).ok_or(PANELS_WANTED)?; + let list = v.as_array().filter(|a| (1..=PUBLICATION_MAX_PANELS).contains(&a.len())).ok_or_else(panels_wanted)?; list.iter().enumerate().map(|(i, v)| panel_of(s, i, v)).collect::>().map(Some) } @@ -51,7 +49,7 @@ fn panel_of(s: &Session, i: usize, v: &Value) -> Result { let text = l.as_str().ok_or_else(|| format!("panels[{i}].label is text"))?; // Whitespace, line breaks included, is one space: a break would make the label two lines. let text = text.split_whitespace().collect::>().join(" "); - let text = crate::cmd::within(&format!("panels[{i}].label"), "a panel's label", &text, MAX_LABEL)?; + let text = crate::cmd::within(&format!("panels[{i}].label"), "a panel's label", &text, PUBLICATION_MAX_PANEL_LABEL)?; (!text.is_empty()).then_some(text) } }; diff --git a/crates/engine/src/cmd/layout/publication/sheet.rs b/crates/engine/src/cmd/layout/publication/sheet.rs index baef58e8f9..922d0196ae 100644 --- a/crates/engine/src/cmd/layout/publication/sheet.rs +++ b/crates/engine/src/cmd/layout/publication/sheet.rs @@ -55,6 +55,17 @@ pub const PUBLICATION_STYLES: &[(&str, &str)] = &[ ("edge", "Edge"), ]; +/// The mosaic style, which `"style"` takes with a list of `"panels"`: not in [`PUBLICATION_STYLES`], +/// which lists the styles that need no more than their name (the one-click menu makes those), and +/// listed by the layout wizard, which asks for the panels. +pub const PUBLICATION_MOSAIC: (&str, &str) = ("mosaic", "Mosaic"); + +/// The most panels a mosaic takes: past six, A4's cells are too small to read. +pub const PUBLICATION_MAX_PANELS: usize = 6; + +/// The most characters a mosaic panel's label takes. +pub const PUBLICATION_MAX_PANEL_LABEL: usize = 80; + /// The credit line `layout.publication` writes when `"author"` isn't given (`{date}` is filled /// with today's date when the layout is drawn). pub const PUBLICATION_DEFAULT_CREDIT: &str = "Made with RustGIS · {date}"; @@ -119,7 +130,7 @@ pub(in crate::cmd::layout) enum Style { /// rule. Edge, /// A classic sheet whose map area holds a key map and detail frames numbered on it (#3513). - /// Not in [`PUBLICATION_STYLES`], which lists the styles that need no more than their name: + /// Not in [`PUBLICATION_STYLES`], which lists the styles that need no more than their name (see [`PUBLICATION_MOSAIC`]): /// this one takes `"panels"`. Mosaic, } diff --git a/crates/engine/src/tests/layout_publication_parts.rs b/crates/engine/src/tests/layout_publication_parts.rs index f3da4378aa..f3b954b6c6 100644 --- a/crates/engine/src/tests/layout_publication_parts.rs +++ b/crates/engine/src/tests/layout_publication_parts.rs @@ -666,6 +666,19 @@ fn only_modular_and_poster_put_their_surrounds_on_cards() { assert!(!publication_style_cards("unknown")); } +/// The mosaic is a style `"style"` takes that the one-click menu's list leaves out, as it needs +/// `"panels"`; the limits the wizard reads are the command's (#3599). +#[test] +fn the_mosaic_is_a_style_the_command_takes_that_the_menu_list_leaves_out() { + use crate::cmd::layout::{PUBLICATION_MAX_PANELS, PUBLICATION_MOSAIC, PUBLICATION_STYLES}; + assert!(PUBLICATION_STYLES.iter().all(|(id, _)| *id != PUBLICATION_MOSAIC.0)); + let mut s = world(); + let none = s.run("layout.publication", &serde_json::json!({"style": PUBLICATION_MOSAIC.0})).unwrap_err(); + assert!(none.contains(&format!("1 to {PUBLICATION_MAX_PANELS} extents")), "{none}"); + let many = vec![serde_json::json!([0.0, 0.0, 1.0, 1.0]); PUBLICATION_MAX_PANELS + 1]; + assert!(s.run("layout.publication", &serde_json::json!({"style": "mosaic", "panels": many})).is_err()); +} + /// A name is found as it is spelled first, so one with edge spaces is left out, not the layer of /// the trimmed name (#3234); a name no layer spells that way is still trimmed. #[test] diff --git a/crates/ui-egui/src/publicationwizard/elements.rs b/crates/ui-egui/src/publicationwizard/elements.rs index 0cfdd77017..6198e13ccc 100644 --- a/crates/ui-egui/src/publicationwizard/elements.rs +++ b/crates/ui-egui/src/publicationwizard/elements.rs @@ -124,7 +124,8 @@ impl Draft { /// Whether the map frame shows the globe seen whole: on the globe, with no extent sent. fn whole_globe(&self, s: &Session) -> bool { - s.map().projection.is_globe() && self.area == Area::View + // A mosaic's panels say what its key map shows, as an extent does (the command's own rule). + s.map().projection.is_globe() && self.area == Area::View && !self.mosaic() } /// Whether the command draws a locator none is asked for: a sheet's, but of a whole globe. @@ -824,6 +825,20 @@ mod tests { assert_eq!(added(&app.session, &d), json!({"scaleBar": "none"})); } + /// A mosaic on the globe is not the globe seen whole, as the command has it (its panels say + /// what the key map shows): the scale bar's choice is sent, as for an extent. + #[test] + fn a_mosaic_on_the_globe_is_not_the_whole_globe() { + let mut app = app(); + globe(&mut app); + let mut d = Draft::new(&app.session); + d.style = "mosaic".into(); + d.elements.scale_bar = false; + assert_eq!(added(&app.session, &d), json!({"scaleBar": "none"})); + d.style = "classic".into(); + assert_eq!(added(&app.session, &d), json!({}), "a sheet of the whole globe draws none"); + } + /// Elements with a look picked for each of the three. fn looks() -> Elements { Elements { diff --git a/crates/ui-egui/src/publicationwizard/map.rs b/crates/ui-egui/src/publicationwizard/map.rs index dc47b485d3..9f5259eef5 100644 --- a/crates/ui-egui/src/publicationwizard/map.rs +++ b/crates/ui-egui/src/publicationwizard/map.rs @@ -111,7 +111,7 @@ fn held<'a>(s: &'a Session, area: &Area, coords: Option<&Coords>) -> Result bool { +pub(super) fn ordered([w, s, e, n]: [f64; 4]) -> bool { w < e && s < n } @@ -132,7 +132,7 @@ fn from_view(s: &Session) -> Coords { } /// `sides` in degrees as the fields start on them, kept to the Earth. -fn in_degrees(sides: [f64; 4]) -> [f64; 4] { +pub(super) fn in_degrees(sides: [f64; 4]) -> [f64; 4] { let [w, s, e, n] = outward(sides, false); [w.max(-180.0), s.max(-90.0), e.min(180.0), n.min(90.0)] } @@ -243,11 +243,16 @@ fn number(text: &str) -> Option { /// The four fields of the coordinates, written to the draft as they change: no command runs, so a /// value holds even when Next is pressed while it is being typed. -fn coordinate_fields(ui: &mut egui::Ui, coords: &mut Coords, unit: &'static str, res: f64) { +pub(super) fn coordinate_fields(ui: &mut egui::Ui, coords: &mut Coords, unit: &'static str, res: f64, owner: Option<&str>) { let projected = coords.crs.is_some(); egui::Grid::new("publication_wizard_coordinates").num_columns(2).spacing(egui::vec2(8.0, 4.0)).show(ui, |ui| { for (text, at, most) in [(tl!("West"), 0, 180.0), (tl!("East"), 2, 180.0), (tl!("South"), 1, 90.0), (tl!("North"), 3, 90.0)] { let label = ui.label(text); + // Fields of the same name in several places (a mosaic's panels) say whose they are. + if let Some(owner) = owner { + let name = i18n::fmt("{owner}: {field}", &[("owner", owner), ("field", text)]); + label.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Label, true, &name)); + } if let Some(v) = coords.sides.get_mut(at) { // A decimal comma too, which egui's own parser reads as no number. Finite numbers // only: the range would take NaN as a limit. @@ -291,7 +296,12 @@ pub(super) fn map_step(ui: &mut egui::Ui, s: &Session, d: &mut Draft) -> Vec<&'s egui::Grid::new("publication_wizard_map").num_columns(2).spacing(egui::vec2(8.0, 8.0)).show(ui, |ui| { // A row for each choice, so the label sits beside the first one. ui.label(tl!("Map extent")); - if ui.radio(d.area == Area::View, tl!("View")).on_hover_text(tl!("What the map view shows.")).clicked() { + // A mosaic's key map holds its panels, unless an area is picked. + let (name, about) = match d.mosaic() { + true => (tl!("Around the panels"), tl!("The key map holds every panel.")), + false => (tl!("View"), tl!("What the map view shows.")), + }; + if ui.radio(d.area == Area::View, name).on_hover_text(about).clicked() { picked_area = Some(Area::View); } ui.end_row(); @@ -379,7 +389,7 @@ pub(super) fn map_step(ui: &mut egui::Ui, s: &Session, d: &mut Draft) -> Vec<&'s }; } let unit = system.as_ref().map_or("", |s| crate::coordreadout::unit_of(s.1)); - coordinate_fields(ui, coords, unit, map.camera.res); + coordinate_fields(ui, coords, unit, map.camera.res, None); if let Some((crs, _)) = &system { let line = match unit { "" => i18n::fmt("Easting and northing in {crs}", &[("crs", crs)]), @@ -441,7 +451,7 @@ pub(super) fn area_label(s: &Session, area: &Area, coords: Option<&Coords>) -> S /// `e` as `layout.publication` takes it: cut to ±180 and ±90, a side of no length widened to /// [`MIN_SIDE`]; none when nothing is left to frame. -fn framed(e: Extent) -> Option<[f64; 4]> { +pub(super) fn framed(e: Extent) -> Option<[f64; 4]> { if e.is_empty() { return None; } diff --git a/crates/ui-egui/src/publicationwizard/mod.rs b/crates/ui-egui/src/publicationwizard/mod.rs index 7f42c857f0..418b033f17 100644 --- a/crates/ui-egui/src/publicationwizard/mod.rs +++ b/crates/ui-egui/src/publicationwizard/mod.rs @@ -5,6 +5,7 @@ mod accent; mod arrange; mod elements; mod map; +mod panels; mod review; mod size; mod sources; @@ -17,13 +18,14 @@ use accent::accent_step; use arrange::{Arrangement, arrange_step}; use elements::{Elements, elements_step}; use map::{Area, Coords, area_extent, map_step}; +use panels::{PanelDraft, panels_held, panels_step}; #[cfg(not(target_arch = "wasm32"))] pub(crate) use review::land_left; use review::{Preview, drop_stale_preview, review_step}; use rustgis_engine::Session; use rustgis_engine::cmd::layout::{ - MAX_PUBLICATION_LINES, MAX_PUBLICATION_TEXT, PUBLICATION_HEADINGS, PUBLICATION_PROFILES, publication_default_reference, - publication_style_accent, + MAX_PUBLICATION_LINES, MAX_PUBLICATION_TEXT, PUBLICATION_HEADINGS, PUBLICATION_MAX_PANEL_LABEL, PUBLICATION_MAX_PANELS, + PUBLICATION_MOSAIC, PUBLICATION_PROFILES, publication_default_reference, publication_style_accent, }; use rustgis_engine::geom::Extent; use rustgis_engine::map::Map; @@ -40,6 +42,8 @@ pub enum Step { Size, Map, Style, + /// A mosaic sheet's detail maps. + Panels, /// What is drawn around the map. Elements, Placement, @@ -119,6 +123,10 @@ pub struct Draft { /// The layout's name; empty leaves it to the command. pub name: String, pub style: String, + /// A mosaic sheet's detail maps, from 1 to [`PUBLICATION_MAX_PANELS`]; sent only with the mosaic style. + pub panels: Vec, + /// The identity the next panel added takes ([`PanelDraft::id`]). + pub next_panel: u64, 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, @@ -176,6 +184,8 @@ impl Draft { coords: None, name: String::new(), style: "classic".into(), + panels: vec![PanelDraft::from_view(s, 0)], + next_panel: 1, title: s.map().name.clone(), title_typed: false, kicker: String::new(), @@ -220,6 +230,20 @@ impl Draft { if self.figure() { return &[Step::Size, Step::Map, Step::Elements, Step::Placement, Step::Reference, Step::Review]; } + if self.mosaic() { + return &[ + Step::Size, + Step::Map, + Step::Style, + Step::Panels, + Step::Elements, + Step::Placement, + Step::Texts, + Step::Sources, + Step::Accent, + Step::Review, + ]; + } &[Step::Size, Step::Map, Step::Style, Step::Elements, Step::Placement, Step::Texts, Step::Sources, Step::Accent, Step::Review] } @@ -265,6 +289,9 @@ impl Draft { return p; } p["style"] = json!(self.style); + if self.mosaic() { + p["panels"] = json!(self.panels.iter().map(PanelDraft::value).collect::>()); + } p["title"] = json!(self.title.trim()); for (key, text) in [("subtitle", &self.subtitle), ("note", &self.note), ("author", &self.author)] { if !text.trim().is_empty() { @@ -312,6 +339,11 @@ impl Draft { .collect() } + /// A sheet in the mosaic style, the one that takes panels. + fn mosaic(&self) -> bool { + !self.figure() && self.style == PUBLICATION_MOSAIC.0 + } + fn editorial(&self) -> bool { self.style == "editorial" } @@ -449,6 +481,7 @@ fn step_name(step: Step) -> &'static str { Step::Size => tl_raw!("Size"), Step::Map => tl_raw!("Map"), Step::Style => tl_raw!("Style"), + Step::Panels => tl_raw!("Panels"), Step::Elements => tl_raw!("Elements"), Step::Placement => tl_raw!("Placement"), Step::Texts => tl_raw!("Texts"), @@ -465,6 +498,7 @@ fn step_label(step: Step) -> &'static str { Step::Size => tl!("Size"), Step::Map => tl!("Map"), Step::Style => tl!("Style"), + Step::Panels => tl!("Panels"), Step::Elements => tl!("Elements"), Step::Placement => tl!("Placement"), Step::Texts => tl!("Texts"), @@ -501,7 +535,7 @@ fn field_width(ui: &egui::Ui) -> f32 { } /// The size the window opens at, tall enough for the tallest step in English (the style step's -/// seven styles, their outlines and descriptions), with room for the rounding a high-density +/// eight styles, in two columns, with their outlines and descriptions), with room for the rounding a high-density /// screen adds to each line. A narrower screen narrows it (`dialog_width`); on a shorter one /// egui's window limits its height to the screen. const SIZE: egui::Vec2 = egui::vec2(600.0, 515.0); @@ -545,6 +579,9 @@ fn step_list(ui: &mut egui::Ui, d: &mut Draft, height: f32) -> Option { /// resolves the area, which may walk a whole layer, so it runs only on those two. fn create_params(s: &Session, d: &Draft) -> Result { d.arrangement.held(s)?; + if d.mosaic() { + panels_held(&d.panels)?; + } let extent = area_extent(s, &d.area, d.coords.as_ref())?; let mut params = d.sent(s); if let Some(Coords { sides, crs }) = extent { @@ -626,6 +663,7 @@ pub fn show(app: &mut RustGisApp, ctx: &egui::Context) { Step::Size => size_step(ui, &mut d), Step::Map => lost = map_step(ui, &app.session, &mut d), Step::Style => style_step(ui, &mut d, t.accent), + Step::Panels => panels_step(ui, &app.session, &mut d), Step::Elements => elements_step(ui, &app.session, &mut d), Step::Placement => arrange_step(ui, &app.session, &mut d), Step::Texts => texts_step(ui, &mut d, app.session.map()), diff --git a/crates/ui-egui/src/publicationwizard/panels.rs b/crates/ui-egui/src/publicationwizard/panels.rs new file mode 100644 index 0000000000..0bf89c9665 --- /dev/null +++ b/crates/ui-egui/src/publicationwizard/panels.rs @@ -0,0 +1,542 @@ +//! The wizard's panels step: the detail maps of a mosaic sheet. +use super::map::{Coords, coordinate_fields, framed, in_degrees, ordered}; +use super::*; +use rustgis_engine::cmd::workspace::view_extent; +use rustgis_engine::map::layout::{MAX_FRAME_SCALE, MIN_FRAME_SCALE}; + +/// What a panel's scale starts on once checked, in the denominator of 1:N. +const START_SCALE: f64 = 25_000.0; + +/// One detail map of a mosaic: the area it shows, in degrees (longitude and latitude, whatever +/// the map's system, as `layout.publication` takes `panels`), its label, and the scale it is drawn +/// at when `scale_on`. `coords` is the map step's own type, with no system: the fields are shared. +#[derive(Clone, Debug, PartialEq)] +pub struct PanelDraft { + /// Its identity while the wizard is open: the widgets of a panel are scoped by it, not by its + /// place, so what egui keeps for them (a label's undo history) doesn't pass to the next panel + /// when one above is removed. + pub id: u64, + pub coords: Coords, + pub label: String, + pub scale_on: bool, + pub scale: f64, +} + +impl PanelDraft { + /// A panel on the view, in degrees, rounded outward as the map step's fields start; the whole + /// Earth where the view has no box to frame (the globe's view means nothing in degrees). + pub fn from_view(s: &Session, id: u64) -> Self { + let whole = [-180.0, -90.0, 180.0, 90.0]; + let sides = if s.map().projection.is_globe() { whole } else { framed(view_extent(s)).map_or(whole, in_degrees) }; + PanelDraft { id, coords: sides.into(), label: String::new(), scale_on: false, scale: START_SCALE } + } + + /// The label as the command keeps it: its white space, line breaks included, as one space. + fn label_sent(&self) -> Option { + Some(self.label.split_whitespace().collect::>().join(" ")).filter(|l| !l.is_empty()) + } + + /// The panel as `layout.publication` takes it. + pub fn value(&self) -> Value { + let mut p = json!({"extent": self.coords.sides}); + if let Some(label) = self.label_sent() { + p["label"] = json!(label); + } + if self.scale_on { + p["scale"] = json!(self.scale.round()); + } + p + } + + /// The panel's line in the review, the number counted from 1; none when its sides are out of + /// order, which the command refuses. + pub(super) fn line(&self, n: usize) -> String { + let number = n.to_string(); + if !ordered(self.coords.sides) { + return i18n::fmt("{n}. {none}", &[("n", &number), ("none", tl!("(none)"))]); + } + let [west, south, east, north] = self.coords.sides.map(|v| v.to_string()); + // The sides as the Map step's review says them: one catalogue key for both. + let sides = i18n::fmt( + "West {west}, South {south}, East {east}, North {north}", + &[("west", &west), ("south", &south), ("east", &east), ("north", &north)], + ); + let mut line = i18n::fmt("{n}. {sides}", &[("n", &number), ("sides", &sides)]); + if let Some(label) = self.label_sent() { + line = i18n::fmt("{line} · {label}", &[("line", &line), ("label", &label)]); + } + if self.scale_on { + line = i18n::fmt("{line} · 1:{scale}", &[("line", &line), ("scale", &self.scale.round().to_string())]); + } + line + } +} + +/// Whether every panel is one `layout.publication` takes, or what the first that isn't lacks. +pub(super) fn panels_held(panels: &[PanelDraft]) -> Result<(), String> { + match panels.iter().position(|p| !ordered(p.coords.sides)) { + None => Ok(()), + Some(at) => Err(i18n::fmt( + "Panel {n}: {reason}", + &[("n", &(at + 1).to_string()), ("reason", tl!("West must be less than East, and South less than North."))], + )), + } +} + +/// The review's Panels row: one line a panel. +pub(super) fn panels_value(d: &Draft) -> String { + d.panels.iter().enumerate().map(|(at, p)| p.line(at + 1)).collect::>().join("\n") +} + +/// The panels step: each panel's area in degrees, its label and its scale, with a button to add a +/// panel (up to the most the command takes) and one to remove each. +pub(super) fn panels_step(ui: &mut egui::Ui, s: &Session, d: &mut Draft) { + ui.add( + egui::Label::new(tl!( + "Each panel is a detail map, numbered on the key map. Areas are in degrees (longitude and latitude), on any map." + )) + .wrap(), + ); + // Above the panels, where it is in reach however many there are. + let full = d.panels.len() >= PUBLICATION_MAX_PANELS; + let add = ui + .add_enabled(!full, egui::Button::new(tl!("Add panel"))) + .on_disabled_hover_text(i18n::fmt("A mosaic takes at most {max} panels.", &[("max", &PUBLICATION_MAX_PANELS.to_string())])); + if add.clicked() { + d.panels.push(PanelDraft::from_view(s, d.next_panel)); + d.next_panel += 1; + } + ui.add_space(4.0); + let count = d.panels.len(); + let mut remove = None; + for (at, p) in d.panels.iter_mut().enumerate() { + // Its own id, so the fields of one panel are not the fields of another. + ui.push_id(p.id, |ui| { + let n = (at + 1).to_string(); + // What a screen reader says of each of the panel's fields, as the Remove button does. + let panel = i18n::fmt("Panel {n}", &[("n", &n)]); + let named = |field: &str| i18n::fmt("{owner}: {field}", &[("owner", &panel), ("field", field)]); + ui.horizontal_wrapped(|ui| { + ui.label(egui::RichText::new(i18n::fmt("Panel {n}", &[("n", &n)])).strong()); + let button = egui::Button::new(tl!("Remove")); + let name = i18n::fmt("Remove panel {n}", &[("n", &n)]); + let r = ui.add_enabled(count > 1, button).on_disabled_hover_text(tl!("A mosaic takes at least one panel.")); + r.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Button, r.enabled(), &name)); + if r.clicked() { + remove = Some(at); + } + }); + coordinate_fields(ui, &mut p.coords, "", 1.0, Some(&panel)); + if !ordered(p.coords.sides) { + ui.add( + egui::Label::new( + egui::RichText::new(tl!("West must be less than East, and South less than North.")) + .color(ui.visuals().warn_fg_color), + ) + .wrap(), + ); + } + egui::Grid::new("publication_wizard_panel_texts").num_columns(2).spacing(egui::vec2(8.0, 4.0)).show(ui, |ui| { + let label = ui.label(tl!("Label")); + let name = named(tl!("Label")); + label.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Label, true, &name)); + ui.add( + egui::TextEdit::singleline(&mut p.label) + .id_salt("panel_label") + .char_limit(PUBLICATION_MAX_PANEL_LABEL) + .desired_width(field_width(ui)), + ) + .labelled_by(label.id); + ui.end_row(); + // The field refuses what is past its limit without a word, so it says it as the + // Texts step does, once the limit is reached. + if p.label.chars().count() >= PUBLICATION_MAX_PANEL_LABEL { + ui.label(""); + let max = PUBLICATION_MAX_PANEL_LABEL.to_string(); + let note = i18n::fmt("Each field takes at most {limit} characters.", &[("limit", &max)]); + ui.add(egui::Label::new(egui::RichText::new(note).small().weak()).wrap()); + ui.end_row(); + } + ui.label(""); + ui.horizontal(|ui| { + let on = ui.checkbox(&mut p.scale_on, tl!("Scale")); + let name = named(tl!("Scale")); + let selected = p.scale_on; + on.widget_info(|| egui::WidgetInfo::selected(egui::Role::CheckBox, true, selected, &name)); + ui.add_enabled_ui(p.scale_on, |ui| { + let r = ui + .add( + egui::DragValue::new(&mut p.scale) + .prefix("1:") + .range(MIN_FRAME_SCALE..=MAX_FRAME_SCALE) + .speed(100.0) + .max_decimals(0), + ) + .labelled_by(on.id); + // Dragging rounds the value, typing doesn't: whole denominators, as the field shows them and the + // review and the command take them. + if r.changed() { + p.scale = p.scale.round(); + } + }); + }); + ui.end_row(); + }); + ui.add_space(6.0); + }); + } + if let Some(at) = remove { + d.panels.remove(at); + } +} + +#[cfg(test)] +mod tests { + use super::super::harness::*; + use super::*; + use egui::accesskit::Role; + use egui_kittest::kittest::{NodeT, Queryable}; + use rustgis_engine::map::layout::{ElementKind, MAX_FRAME_SCALE, MIN_FRAME_SCALE}; + + type Wizard = egui_kittest::Harness<'static, RustGisApp>; + + /// The wizard on `step`, in a mosaic, after `prepare`. + fn wizard_on(step: Step, prepare: impl FnOnce(&mut RustGisApp)) -> Wizard { + let mut app = app(); + open(&mut app); + prepare(&mut app); + let d = app.dialogs.publication.as_mut().unwrap(); + d.style = "mosaic".into(); + d.step = step; + harness(app) + } + + /// The window dragged taller, so more than one panel is in view. + fn taller(h: &mut Wizard) { + let corner = h.get_by_role_and_label(Role::Window, "Layout Wizard").rect().right_bottom() - egui::vec2(1.0, 1.0); + let by = egui::vec2(0.0, 450.0); + h.hover_at(corner); + h.run_steps(2); + h.drag_at(corner); + h.run_steps(2); + h.hover_at(corner + by); + h.run_steps(2); + h.drop_at(corner + by); + h.run_steps(4); + } + + fn draft(h: &Wizard) -> &Draft { + h.state().dialogs.publication.as_ref().expect("the wizard is open") + } + + fn panels_of(h: &Wizard) -> &[PanelDraft] { + &draft(h).panels + } + + fn panel(sides: [f64; 4]) -> PanelDraft { + PanelDraft { id: 0, coords: sides.into(), label: String::new(), scale_on: false, scale: 25_000.0 } + } + + /// The panels step comes after the style step on a mosaic sheet only, and a figure never has it. + #[test] + fn only_a_mosaic_sheet_has_the_panels_step() { + let app = app(); + let mut d = Draft::new(&app.session); + assert!(!d.steps().contains(&Step::Panels), "classic"); + d.style = "mosaic".into(); + let steps = d.steps(); + let at = steps.iter().position(|s| *s == Step::Style).unwrap(); + assert_eq!(steps[at + 1], Step::Panels); + assert_eq!(steps.len(), 10); + d.size = "figure-1col".into(); + assert!(!d.steps().contains(&Step::Panels), "a figure takes no style"); + } + + /// Next and Back go Style → Panels → Elements and back on a mosaic sheet. + #[test] + fn next_and_back_walk_through_the_panels_step() { + let mut h = wizard_on(Step::Style, |_| {}); + for want in [Step::Panels, Step::Elements] { + click(&mut h, "Next"); + assert_eq!(step(&h), want); + } + for want in [Step::Panels, Step::Style] { + click(&mut h, "Back"); + assert_eq!(step(&h), want); + } + } + + /// A panel keeps its own identity as others are added and removed, so what egui keeps for its + /// widgets (the label's undo history) stays with it: the ids are distinct, and a panel that + /// survives a removal above it keeps its id. + #[test] + fn a_panel_keeps_its_id_as_others_come_and_go() { + let mut h = wizard_on(Step::Panels, |_| {}); + taller(&mut h); + for _ in 0..2 { + h.get_by_role_and_label(Role::Button, "Add panel").click(); + h.run_steps(4); + } + let ids = |h: &Wizard| panels_of(h).iter().map(|p| p.id).collect::>(); + let before = ids(&h); + assert_eq!(before.len(), 3); + assert!(before.iter().enumerate().all(|(at, id)| !before[..at].contains(id)), "{before:?}"); + h.get_by_role_and_label(Role::Button, "Remove panel 1").click(); + h.run_steps(4); + assert_eq!(ids(&h), before[1..], "the survivors keep theirs"); + h.get_by_role_and_label(Role::Button, "Add panel").click(); + h.run_steps(4); + let after = ids(&h); + assert_eq!(after.len(), 3); + assert!(!before.contains(&after[2]), "a new panel takes an id no panel had: {after:?}"); + } + + /// What egui keeps of a label (its undo history) follows its panel when a panel above is + /// removed: Undo takes back what was typed in it, not nothing, and not another panel's text. + #[test] + fn a_labels_undo_follows_its_panel_when_one_above_is_removed() { + let mut h = wizard_on(Step::Panels, |_| {}); + taller(&mut h); + h.get_by_role_and_label(Role::Button, "Add panel").click(); + h.run_steps(4); + h.get_by_role_and_label(Role::TextInput, "Panel 2: Label").click(); + h.run_steps(4); + h.event(egui::Event::Text("abc".into())); + h.run_steps(12); + assert_eq!(panels_of(&h)[1].label, "abc"); + h.get_by_role_and_label(Role::Button, "Remove panel 1").click(); + h.run_steps(4); + let only = h.get_by_role_and_label(Role::TextInput, "Panel 1: Label"); + only.click(); + h.run_steps(4); + h.key_press_modifiers(egui::Modifiers::COMMAND, egui::Key::Z); + h.run_steps(4); + assert_eq!(panels_of(&h)[0].label, "", "Undo takes back what was typed in this label"); + } + + /// What is sent: `panels` on a mosaic only, each panel an `extent`, a label with its spaces + /// joined and a scale when they are set; a draft that keeps panels sends none on another style. + #[test] + fn a_mosaic_sends_its_panels_and_another_style_sends_none() { + let app = app(); + let mut d = Draft::new(&app.session); + d.panels = vec![panel([-10.0, 40.0, 5.0, 50.0]), panel([1.0, 2.0, 3.0, 4.0])]; + d.panels[1].label = " Old \n town ".into(); + d.panels[1].scale_on = true; + d.panels[1].scale = 50_000.0; + assert!(d.params().get("panels").is_none(), "classic"); + d.style = "mosaic".into(); + assert_eq!( + d.params()["panels"], + json!([{"extent": [-10.0, 40.0, 5.0, 50.0]}, {"extent": [1.0, 2.0, 3.0, 4.0], "label": "Old town", "scale": 50_000.0}]) + ); + d.panels[1].label = " \n ".into(); + d.panels[1].scale_on = false; + assert_eq!(d.params()["panels"][1], json!({"extent": [1.0, 2.0, 3.0, 4.0]}), "blank label and unchecked scale"); + d.style = "poster".into(); + assert!(d.params().get("panels").is_none()); + d.style = "mosaic".into(); + d.size = "figure-1col".into(); + assert!(d.params().get("panels").is_none(), "a figure"); + } + + /// The first panel starts on the view in degrees: also on a map in a projected system (the + /// command takes `panels` in degrees), and the whole Earth on the globe, which has no view box. + #[test] + fn the_first_panel_starts_on_the_view_in_degrees() { + let app = app(); + let view = super::super::map::framed(rustgis_engine::cmd::workspace::view_extent(&app.session)).unwrap(); + let d = Draft::new(&app.session); + assert_eq!(d.panels.len(), 1); + let got = d.panels[0].coords.sides; + assert!(d.panels[0].coords.crs.is_none()); + assert!(got.iter().zip(view).all(|(a, b)| (a - b).abs() <= 1e-5), "{got:?} {view:?}"); + let mut utm = self::app(); + utm.run("map.projection", json!({"type": "EPSG:32630"})).unwrap(); + let d = Draft::new(&utm.session); + let got = d.panels[0].coords.sides; + // The view's box in degrees, not the map's metres cut to the Earth: those would sit on + // the ±180 edge, out of order. + let view = super::super::map::framed(rustgis_engine::cmd::workspace::view_extent(&utm.session)).unwrap(); + assert!(got.iter().zip(view).all(|(a, b)| (a - b).abs() <= 1e-5), "{got:?} {view:?}"); + assert!(got[0] > -180.0 && got[2] < 180.0 && super::super::map::ordered(got), "{got:?}"); + let mut globe = self::app(); + globe.session.map_mut().projection = rustgis_engine::map::Projection::Globe; + assert_eq!(Draft::new(&globe.session).panels[0].coords.sides, [-180.0, -90.0, 180.0, 90.0]); + } + + /// The step shows each panel's four sides, its label and its scale, with Add and Remove. + #[test] + fn the_step_has_each_panels_fields_and_adds_and_removes_panels() { + let mut h = wizard_on(Step::Panels, |_| {}); + for field in ["West", "East", "South", "North"] { + h.get_by_role_and_label(Role::SpinButton, &format!("Panel 1: {field}")); + } + h.get_by_role_and_label(Role::TextInput, "Panel 1: Label"); + h.get_by_role_and_label(Role::CheckBox, "Panel 1: Scale"); + taller(&mut h); + assert!(h.get_by_role_and_label(Role::Button, "Remove panel 1").accesskit_node().is_disabled(), "the only one stays"); + for n in 2..=PUBLICATION_MAX_PANELS { + h.get_by_role_and_label(Role::Button, "Add panel").click(); + h.run_steps(4); + assert_eq!(panels_of(&h).len(), n); + } + assert!(h.get_by_role_and_label(Role::Button, "Add panel").accesskit_node().is_disabled(), "six at most"); + for n in 1..=PUBLICATION_MAX_PANELS { + h.get_by_role_and_label(Role::SpinButton, &format!("Panel {n}: West")); + } + h.get_by_role_and_label(Role::Button, "Remove panel 1").click(); + h.run_steps(4); + assert_eq!(panels_of(&h).len(), 5); + assert!(!h.get_by_role_and_label(Role::Button, "Add panel").accesskit_node().is_disabled()); + } + + /// Each panel's fields are its own: a label typed in the second is not the first's. + #[test] + fn a_panels_fields_are_its_own() { + let mut h = wizard_on(Step::Panels, |a| { + let d = a.dialogs.publication.as_mut().unwrap(); + d.panels = vec![panel([0.0, 0.0, 1.0, 1.0]), panel([2.0, 2.0, 3.0, 3.0])]; + d.panels[1].id = 1; + d.next_panel = 2; + }); + taller(&mut h); + h.get_by_role_and_label(Role::TextInput, "Panel 2: Label").click(); + h.run_steps(4); + h.event(egui::Event::Text("Harbour".into())); + h.run_steps(4); + assert_eq!((panels_of(&h)[0].label.as_str(), panels_of(&h)[1].label.as_str()), ("", "Harbour")); + } + + /// A label that reaches its most characters says so, as the Texts step's fields do, and a + /// shorter one says nothing. + #[test] + fn a_label_at_its_limit_says_so() { + let said = format!("Each field takes at most {PUBLICATION_MAX_PANEL_LABEL} characters."); + let mut h = wizard_on(Step::Panels, |_| {}); + assert!(h.query_by_label(&said).is_none()); + h.state_mut().dialogs.publication.as_mut().unwrap().panels[0].label = "x".repeat(PUBLICATION_MAX_PANEL_LABEL); + h.run_steps(4); + assert!(h.query_by_label(&said).is_some()); + } + + /// The scale sent is the one the review shows: a fraction typed is rounded in both. + #[test] + fn the_scale_sent_is_the_one_the_review_shows() { + let app = app(); + let mut d = Draft::new(&app.session); + d.style = "mosaic".into(); + d.panels[0].scale_on = true; + d.panels[0].scale = 25_000.6; + assert_eq!(d.params()["panels"][0]["scale"], json!(25_001.0)); + assert!(d.panels[0].line(1).ends_with(" · 1:25001")); + } + + /// A scale typed with a fraction is kept whole, as the step shows it and the review and the + /// command take it. + #[test] + fn a_scale_typed_with_a_fraction_is_kept_whole() { + let mut h = wizard_on(Step::Panels, |a| a.dialogs.publication.as_mut().unwrap().panels[0].scale_on = true); + h.get_by_role_and_label(Role::SpinButton, "Panel 1: Scale").click(); + h.run_steps(4); + h.key_press_modifiers(egui::Modifiers::COMMAND, egui::Key::A); + h.event(egui::Event::Text("25000.5".into())); + h.run_steps(4); + h.key_press(egui::Key::Enter); + h.run_steps(4); + assert_eq!(panels_of(&h)[0].scale, 25_001.0); + } + + /// A label takes the engine's most characters, and a scale is checked to be set, then holds a + /// value the command takes. + #[test] + fn the_label_and_the_scale_stay_within_what_the_command_takes() { + let mut h = wizard_on(Step::Panels, |_| {}); + let label = h.get_by_role_and_label(Role::TextInput, "Panel 1: Label"); + label.click(); + h.run_steps(4); + h.event(egui::Event::Text("x".repeat(PUBLICATION_MAX_PANEL_LABEL + 20))); + h.run_steps(4); + assert_eq!(panels_of(&h)[0].label.chars().count(), PUBLICATION_MAX_PANEL_LABEL); + assert!(!panels_of(&h)[0].scale_on); + h.get_by_role_and_label(Role::CheckBox, "Panel 1: Scale").click(); + h.run_steps(4); + assert!(panels_of(&h)[0].scale_on && (MIN_FRAME_SCALE..=MAX_FRAME_SCALE).contains(&panels_of(&h)[0].scale)); + h.get_by_role_and_label(Role::SpinButton, "Panel 1: Scale").click(); + h.run_steps(4); + h.event(egui::Event::Text("999999999999999".into())); + h.run_steps(4); + let scale = panels_of(&h)[0].scale; + assert!((MIN_FRAME_SCALE..=MAX_FRAME_SCALE).contains(&scale), "{scale}"); + } + + /// A panel whose sides are out of order is said in its step, is none in the review and stops + /// Create, saying which; the others are left as they are. + #[test] + fn a_panel_out_of_order_is_said_in_the_step_the_review_and_create() { + let wrong = |a: &mut RustGisApp| { + let d = a.dialogs.publication.as_mut().unwrap(); + d.panels = vec![panel([0.0, 0.0, 1.0, 1.0]), panel([5.0, 0.0, 3.0, 1.0])]; + }; + let h = wizard_on(Step::Panels, wrong); + assert_eq!(h.get_all_by_label("West must be less than East, and South less than North.").count(), 1, "only the second"); + let mut h = wizard_on(Step::Review, wrong); + assert!(h.query_by_label_contains("2. (none)").is_some(), "the review"); + let before = h.state().session.project.layouts.len(); + let said = h.state().session.notice_mark(); + click(&mut h, "Create"); + let app = h.state(); + assert_eq!(app.session.project.layouts.len(), before); + assert_eq!(app.session.notice_mark(), said + 1); + assert_eq!(app.dialogs.open, Some("publicationWizard")); + assert_eq!(panels_held(&draft(&h).panels), Err("Panel 2: West must be less than East, and South less than North.".to_string())); + } + + /// On a mosaic the map step's View is the area around the panels, and the review says so; on + /// another style, or with another pick, it reads as it did. + #[test] + fn the_view_is_around_the_panels_on_a_mosaic() { + let h = wizard_on(Step::Map, |_| {}); + assert!(h.query_by_role_and_label(Role::RadioButton, "Around the panels").is_some()); + assert!(h.query_by_role_and_label(Role::RadioButton, "View").is_none()); + let mut h = wizard_on(Step::Review, |_| {}); + assert!(h.query_by_label("Around the panels").is_some()); + h.state_mut().dialogs.publication.as_mut().unwrap().style = "classic".into(); + h.run_steps(4); + assert!(h.query_by_label("The view").is_some()); + assert!(h.query_by_label("Around the panels").is_none()); + let mut h = wizard_on(Step::Review, |a| a.dialogs.publication.as_mut().unwrap().area = Area::Coordinates); + h.state_mut().dialogs.publication.as_mut().unwrap().coords = Some([0.0, 0.0, 1.0, 1.0].into()); + h.run_steps(4); + assert!(h.query_by_label("Around the panels").is_none(), "an area picked is not the panels'"); + } + + /// The review lists each panel on its line: its sides, its label and its scale. + #[test] + fn the_review_lists_the_panels() { + let h = wizard_on(Step::Review, |a| { + let d = a.dialogs.publication.as_mut().unwrap(); + d.panels = vec![panel([0.0, 1.0, 2.0, 3.0]), panel([4.0, 5.0, 6.0, 7.0])]; + d.panels[1].label = "Old town".into(); + d.panels[1].scale_on = true; + d.panels[1].scale = 25_000.0; + }); + assert_eq!(h.get_all_by_label("Panels").count(), 2, "the step's name and the row's"); + h.get_by_label("1. West 0, South 1, East 2, North 3\n2. West 4, South 5, East 6, North 7 · Old town · 1:25000"); + } + + /// Create makes the mosaic: a key map and a frame for each panel. + #[test] + fn create_makes_a_mosaic_with_a_frame_for_each_panel() { + let mut h = wizard_on(Step::Review, |a| { + let d = a.dialogs.publication.as_mut().unwrap(); + d.panels = vec![panel([-10.0, 35.0, 0.0, 45.0]), panel([100.0, 10.0, 120.0, 30.0])]; + }); + click(&mut h, "Create"); + let l = h.state().session.project.layouts.last().expect("a layout is made"); + let panel_frames = + l.elements.iter().filter(|e| matches!(e.kind, ElementKind::MapFrame { .. }) && e.name.starts_with("Panel ")).count(); + assert_eq!(panel_frames, 2, "a frame for each panel"); + assert_eq!(h.state().dialogs.open, None); + } +} diff --git a/crates/ui-egui/src/publicationwizard/review.rs b/crates/ui-egui/src/publicationwizard/review.rs index 2b1adc699c..1a39ae2edc 100644 --- a/crates/ui-egui/src/publicationwizard/review.rs +++ b/crates/ui-egui/src/publicationwizard/review.rs @@ -1,6 +1,7 @@ //! The wizard's review step. use super::elements::elements_value; use super::map::{area_label, name_label}; +use super::panels::panels_value; use super::*; use rustgis_engine::analysis::control::Control; use rustgis_engine::cmd::layout::{PublicationPreview, publication_preview_work}; @@ -29,7 +30,13 @@ fn picked_rows(ui: &mut egui::Ui, s: &Session, d: &Draft) { ui.end_row(); }; row(tl!("Size"), size_label(&d.size)); - row(tl!("Map extent"), area_label(s, &d.area, d.coords.as_ref())); + // A mosaic's key map holds the panels when no area is picked. + let extent = if d.mosaic() && d.area == Area::View { + tl!("Around the panels").to_string() + } else { + area_label(s, &d.area, d.coords.as_ref()) + }; + row(tl!("Map extent"), extent); row(tl!("Name"), name_label(s, &d.name)); if d.figure() { row(tl!("Elements"), elements_value(s, d)); @@ -45,6 +52,9 @@ fn picked_rows(ui: &mut egui::Ui, s: &Session, d: &Draft) { row(tl!("Orientation"), turned.to_string()); let style = crate::ribbon::publication_style(&d.style).map(|s| s.0.to_string()).unwrap_or_else(|| d.style.clone()); row(tl!("Style"), style); + if d.mosaic() { + row(tl!("Panels"), panels_value(d)); + } row(tl!("Elements"), elements_value(s, d)); placement_rows(&mut row, s, d); kicker_row(&mut row, d); diff --git a/crates/ui-egui/src/publicationwizard/style.rs b/crates/ui-egui/src/publicationwizard/style.rs index 121c2b03c4..085ae3eb3e 100644 --- a/crates/ui-egui/src/publicationwizard/style.rs +++ b/crates/ui-egui/src/publicationwizard/style.rs @@ -1,6 +1,12 @@ //! The wizard's style step. use super::*; -use rustgis_engine::cmd::layout::PUBLICATION_STYLES; +use rustgis_engine::cmd::layout::{PUBLICATION_MOSAIC, PUBLICATION_STYLES}; + +/// Every style the wizard offers: those the menu makes from their name, and the mosaic, which the +/// wizard asks the panels of. +fn styles() -> impl Iterator { + PUBLICATION_STYLES.iter().copied().chain([PUBLICATION_MOSAIC]) +} /// The style step: each sheet style's outline, with the accent its sheet would show, by the name /// and description the menu gives it; a click on the outline picks the style, as on its name. @@ -9,26 +15,35 @@ pub(super) fn style_step(ui: &mut egui::Ui, d: &mut Draft, app_accent: egui::Col let chosen = d.chosen_accent(app_accent); // Room for the picked style's frame, which the box the step scrolls in would cut. ui.add_space(4.0); - for (id, english) in PUBLICATION_STYLES { - let (name, about) = crate::ribbon::publication_style(id).unwrap_or_else(|| (tl!(*english), "")); - ui.horizontal(|ui| { - // Not focusable: it shows no focus, and the radio button is the keyboard's way. - let (rect, response) = ui.allocate_exact_size(OUTLINE, egui::Sense::CLICK); - // In logical order, as a screen reader reads it. - let label = i18n::fmt_raw("{style}: outline", &[("style", tl_raw!(*english))]); - response.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Image, true, &label)); - ui.painter().extend(outline(id, rect, chosen.unwrap_or_else(|| style_accent(id, app_accent)))); - if d.style == *id { - let stroke = egui::Stroke::new(1.5, ui.visuals().selection.stroke.color); - ui.painter().rect_stroke(rect.expand(2.0), egui::CornerRadius::same(2), stroke, egui::StrokeKind::Outside); - } - if response.on_hover_cursor(egui::CursorIcon::PointingHand).clicked() { - d.style = (*id).to_string(); + // Two columns, a row of two styles after another: eight outlines, each with its description, + // don't fit the window's height in one (#3599). Each row is its own pair of columns, so a + // description that wraps to more lines in one leaves the next row level (a column of its own + // would let the rows drift apart), and Tab and a screen reader go along the rows. + let all: Vec<_> = styles().collect(); + for row in all.chunks(2) { + ui.columns(2, |columns| { + for (ui, &(id, english)) in columns.iter_mut().zip(row) { + let (name, about) = crate::ribbon::publication_style(id).unwrap_or_else(|| (tl!(english), "")); + ui.horizontal(|ui| { + // Not focusable: it shows no focus, and the radio button is the keyboard's way. + let (rect, response) = ui.allocate_exact_size(OUTLINE, egui::Sense::CLICK); + // In logical order, as a screen reader reads it. + let label = i18n::fmt_raw("{style}: outline", &[("style", tl_raw!(english))]); + response.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Image, true, &label)); + ui.painter().extend(outline(id, rect, chosen.unwrap_or_else(|| style_accent(id, app_accent)))); + if d.style == id { + let stroke = egui::Stroke::new(1.5, ui.visuals().selection.stroke.color); + ui.painter().rect_stroke(rect.expand(2.0), egui::CornerRadius::same(2), stroke, egui::StrokeKind::Outside); + } + if response.on_hover_cursor(egui::CursorIcon::PointingHand).clicked() { + d.style = id.to_string(); + } + ui.vertical(|ui| { + ui.radio_value(&mut d.style, id.to_string(), name); + ui.label(egui::RichText::new(about).small().weak()); + }); + }); } - ui.vertical(|ui| { - ui.radio_value(&mut d.style, (*id).to_string(), name); - ui.label(egui::RichText::new(about).small().weak()); - }); }); } // If the swatch was only seeded from the previous style's default (never customised), follow @@ -134,6 +149,24 @@ fn outline(style: &str, page: egui::Rect, accent: egui::Color32) -> Vec { + s.push(fill(at(0.3, 0.04, 0.4, 0.04), ink)); + s.push(fill(at(0.38, 0.09, 0.24, 0.025), ink)); + s.push(fill(at(0.06, 0.13, 0.4, 0.66), map)); + for (x, y) in [(0.1, 0.2), (0.28, 0.45)] { + s.push(Shape::rect_stroke(at(x, y, 0.12, 0.1), CornerRadius::ZERO, Stroke::new(0.75, accent), StrokeKind::Inside)); + } + for row in 0..3 { + for col in 0..2 { + let (x, y) = (0.49 + 0.23 * col as f32, 0.13 + 0.225 * row as f32); + s.push(fill(at(x, y, 0.21, 0.2), map)); + s.push(fill(at(x, y, 0.06, 0.04), accent)); + } + } + s.extend(foot(0.83)); + } // Classic, which takes the accent nowhere, and a style added without an outline of its own. _ => { s.push(fill(at(0.3, 0.04, 0.4, 0.04), ink)); @@ -162,7 +195,7 @@ mod tests { 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 { + for (id, _) in 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}"); @@ -201,7 +234,7 @@ mod tests { #[test] fn every_style_has_an_outline_of_its_own_inside_its_page() { let mut seen: Vec = Vec::new(); - for (id, _) in PUBLICATION_STYLES { + for (id, _) in styles() { let shapes = outline(id, page(), RED); assert!(!shapes.is_empty(), "{id}"); for s in &shapes { @@ -216,7 +249,7 @@ mod tests { /// The styles whose sheets are drawn in the accent: every one but Classic. fn accented() -> impl Iterator { - PUBLICATION_STYLES.iter().map(|(id, _)| *id).filter(|id| *id != "classic") + styles().map(|(id, _)| id).filter(|id| *id != "classic") } /// An outline's filled rectangles, in fractions of its page, and their colours. @@ -294,7 +327,7 @@ mod tests { /// least (the strokes are the sheet's edge and its boxes'). #[test] fn every_filled_mark_of_an_outline_is_at_least_a_point_thick() { - for (id, _) in PUBLICATION_STYLES { + for (id, _) in styles() { for (r, c) in boxes(id) { let thick = (r.width() * OUTLINE.x).min(r.height() * OUTLINE.y); assert!(thick >= 1.0, "{id}: {c:?} {thick} pt thick"); @@ -371,7 +404,7 @@ mod tests { #[test] fn a_click_on_a_styles_outline_picks_it() { let mut h = at_the_style_step(|_| {}); - for (id, _) in PUBLICATION_STYLES { + for (id, _) in styles() { let (name, _) = crate::ribbon::publication_style(id).unwrap(); assert!(h.query_by_role_and_label(Role::Image, &format!("{name}: outline")).is_some(), "{id}"); } @@ -401,10 +434,10 @@ mod tests { #[test] fn tab_never_stops_at_an_outline() { let mut h = at_the_style_step(|_| {}); - for _ in 0..3 * PUBLICATION_STYLES.len() { + for _ in 0..3 * styles().count() { h.key_press(egui::Key::Tab); h.run_steps(2); - for (id, _) in PUBLICATION_STYLES { + for (id, _) in styles() { let (name, _) = crate::ribbon::publication_style(id).unwrap(); let label = format!("{name}: outline"); let outline = h.get_by_role_and_label(Role::Image, &label); diff --git a/crates/ui-egui/src/ribbon.rs b/crates/ui-egui/src/ribbon.rs index e2b83c4176..2146434d5e 100644 --- a/crates/ui-egui/src/ribbon.rs +++ b/crates/ui-egui/src/ribbon.rs @@ -1281,6 +1281,7 @@ pub(crate) fn publication_style(id: &str) -> Option<(&'static str, &'static str) "modular" => (tl!("Modular"), tl!("Cards on a light page: the map, the locator and the legend each in one.")), "poster" => (tl!("Poster"), tl!("The page in colour, the title in light text and the map in a light card.")), "edge" => (tl!("Edge"), tl!("The map from side to side of the page; a kicker and title over it, the footer under a thin rule.")), + "mosaic" => (tl!("Mosaic"), tl!("A key map and up to six detail maps, each numbered on it.")), _ => return None, }) } @@ -7194,13 +7195,25 @@ mod tests { /// says what it looks like. #[test] fn every_publication_style_is_named_by_a_literal() { - for (id, name) in rustgis_engine::cmd::layout::PUBLICATION_STYLES { + for (id, name) in rustgis_engine::cmd::layout::PUBLICATION_STYLES.iter().chain([&rustgis_engine::cmd::layout::PUBLICATION_MOSAIC]) { let (label, about) = publication_style(id).unwrap_or_else(|| panic!("{id}")); assert_eq!(label, *name, "{id}"); assert!(!about.is_empty(), "{id}"); } } + /// The Mosaic description names the most panels a mosaic takes in words, as a `tl!` literal + /// can't take the constant: it fails when the limit changes, saying where to edit. + #[test] + fn the_mosaic_description_names_the_panel_limit() { + use rustgis_engine::cmd::layout::PUBLICATION_MAX_PANELS; + let word = match PUBLICATION_MAX_PANELS { + 6 => "six", + n => panic!("a mosaic takes {n} panels now: edit the Mosaic description in `publication_style`, and this test"), + }; + assert!(publication_style("mosaic").unwrap().1.contains(word)); + } + /// Publish › Text › Dynamic Text › Layer statistic adds a text holding the token picked, from /// the layers of the first frame's map (#3036); a layout with no frame has no such section. #[test] diff --git a/docs/user-guide/layouts.md b/docs/user-guide/layouts.md index 59c441766d..6cefac54a1 100644 --- a/docs/user-guide/layouts.md +++ b/docs/user-guide/layouts.md @@ -99,7 +99,8 @@ Layouts open as tabs next to the maps; while one is open, its groups lead the Pu no heading, and it can be left out) and the review, as it takes no style, accent or other text. A field left empty is left out (for the credit line, the reference and the headings, the command's default applies); the title is the exception: empty, it means no title. A layout the - command refuses is said, and the wizard stays open. The window can be resized. Its steps are + command refuses is said, and the wizard stays open. A mosaic sheet has a **Panels** step after + the style (below). The window can be resized. Its steps are listed on the left, and a click goes to one; a narrow screen leaves the list out, and the heading still says which step this is. - **The map**: the `extent` given (or the view) fitted north-up, without tilt, at a round scale, @@ -285,7 +286,7 @@ Layouts open as tabs next to the maps; while one is open, its groups lead the Pu A figure leaves the style to its caption. In the menu, each sheet opens a list of those seven styles, each saying what it looks like, in its default accent (`"accent"` in the command picks another). - - **A mosaic** (`"style": "mosaic"`, from a script or the assistant; not in the menu) is a + - **A mosaic** (`"style": "mosaic"`, from a script or the Layout Wizard; not in the one-click menu) is a classic sheet whose map area holds a key map and 1 to 6 detail maps of the same map, listed in `"panels"` as `[west, south, east, north]` in degrees. The key map takes the left of a wide area, or the top of a tall one, with the grid, legend, scale bar, north arrow and locator; the @@ -294,6 +295,11 @@ Layouts open as tabs next to the maps; while one is open, its groups lead the Pu **Extent indicators**). Without `"extent"` the key map holds every panel with a little room around them; the panels whose middle lies outside what the key map shows, which it can't number, are named in one warning. Panels stay in degrees where `"extent"` is given with `"crs"`. + The Layout Wizard offers it as the eighth style, with a **Panels** step after it: 1 to 6 panels, + each its west, south, east and north in degrees (on any map), an optional label and an optional + scale. On a mosaic its Map step's first choice reads **Around the panels**, and the review lists + the panels; one whose sides are out of order is said in its step, and Create says which and makes + nothing. A panel may also be an object: `{"extent": [w, s, e, n]}` or `{"bookmark": "name"}` (what that bookmark of the map covers, as a map view of the app's size shows it: the sheet can differ where the view's size does), with a `"label"` and a `"scale"` if it