diff --git a/crates/engine/src/cmd/layout/publication/sheet.rs b/crates/engine/src/cmd/layout/publication/sheet.rs index e49a7bbe3f..6430cd7733 100644 --- a/crates/engine/src/cmd/layout/publication/sheet.rs +++ b/crates/engine/src/cmd/layout/publication/sheet.rs @@ -85,6 +85,11 @@ pub fn publication_style_has_column(style: &str) -> bool { Style::parse(style).is_some_and(Style::has_column) } +/// Whether a [`PUBLICATION_STYLES`] style id sets its surrounds on cards, each with its own box. +pub fn publication_style_cards(style: &str) -> bool { + Style::parse(style).is_some_and(Style::cards) +} + /// How a publication sheet is arranged around its map. #[derive(Clone, Copy, PartialEq, Debug)] pub(in crate::cmd::layout) enum Style { diff --git a/crates/engine/src/tests/layout_publication_parts.rs b/crates/engine/src/tests/layout_publication_parts.rs index 28407ece7c..9a1ef1d3d4 100644 --- a/crates/engine/src/tests/layout_publication_parts.rs +++ b/crates/engine/src/tests/layout_publication_parts.rs @@ -565,3 +565,12 @@ fn a_publication_legend_says_nothing_of_a_raster_it_does_not_key() { assert!(!w.contains("have no key in the legend"), "{legend}: {w}"); } } + +/// The styles whose surrounds sit on cards, as the wizard is told them (#3172). +#[test] +fn only_modular_and_poster_put_their_surrounds_on_cards() { + use crate::cmd::layout::{PUBLICATION_STYLES, publication_style_cards}; + let cards: Vec<&str> = PUBLICATION_STYLES.iter().map(|(id, _)| *id).filter(|id| publication_style_cards(id)).collect(); + assert_eq!(cards, ["modular", "poster"]); + assert!(!publication_style_cards("unknown")); +} diff --git a/crates/ui-egui/src/publicationwizard/accent.rs b/crates/ui-egui/src/publicationwizard/accent.rs index a1b1c5680f..97fb0458aa 100644 --- a/crates/ui-egui/src/publicationwizard/accent.rs +++ b/crates/ui-egui/src/publicationwizard/accent.rs @@ -114,6 +114,7 @@ mod tests { click(&mut h, "Back"); click(&mut h, "Back"); click(&mut h, "Back"); + click(&mut h, "Back"); h.get_by_label("Poster").click(); h.run_steps(2); assert_eq!(h.state().dialogs.publication.as_ref().unwrap().accent, Some(poster), "re-seeded to Poster"); @@ -122,6 +123,7 @@ mod tests { click(&mut h, "Next"); click(&mut h, "Next"); click(&mut h, "Next"); + click(&mut h, "Next"); h.get_by_label("Pick a colour of your own").click(); h.run_steps(2); assert_eq!(h.state().dialogs.publication.as_ref().unwrap().accent, None); @@ -129,12 +131,14 @@ mod tests { click(&mut h, "Back"); click(&mut h, "Back"); click(&mut h, "Back"); + click(&mut h, "Back"); h.get_by_label("Editorial").click(); h.run_steps(2); click(&mut h, "Next"); click(&mut h, "Next"); click(&mut h, "Next"); click(&mut h, "Next"); + click(&mut h, "Next"); h.get_by_label("Pick a colour of your own").click(); h.run_steps(2); assert_eq!(h.state().dialogs.publication.as_ref().unwrap().accent, Some(editorial), "starts from Editorial"); @@ -145,6 +149,7 @@ mod tests { click(&mut h, "Back"); click(&mut h, "Back"); click(&mut h, "Back"); + click(&mut h, "Back"); h.get_by_label("Banner").click(); h.run_steps(2); assert_eq!(h.state().dialogs.publication.as_ref().unwrap().accent, Some(red), "custom colour kept"); diff --git a/crates/ui-egui/src/publicationwizard/arrange.rs b/crates/ui-egui/src/publicationwizard/arrange.rs index 688366712d..b18b7e3c4b 100644 --- a/crates/ui-egui/src/publicationwizard/arrange.rs +++ b/crates/ui-egui/src/publicationwizard/arrange.rs @@ -1,8 +1,6 @@ //! The wizard's placement step: which corner each surround takes. use super::*; -use rustgis_engine::cmd::layout::{ - ARRANGEMENTS, Homes, corners_of, parse_arrangement, publication_style_has_column, usable_saved_arrangement, -}; +use rustgis_engine::cmd::layout::{ARRANGEMENTS, Homes, corners_of, parse_arrangement, usable_saved_arrangement}; /// The arrangement `layout.publication` is asked for. #[derive(Clone, Debug, PartialEq, Eq)] @@ -83,14 +81,20 @@ fn corner_labels() -> [&'static str; 4] { } /// The locator's place in [`Homes`]. -const LOCATOR: usize = 0; +pub(super) const LOCATOR: usize = 0; + +/// The north arrow's. +pub(super) const NORTH_ARROW: usize = 1; + +/// The scale bar's. +pub(super) const SCALE_BAR: usize = 3; /// The locator and the legend, by their place in [`Homes`]: what a column style keeps in its /// column. const IN_COLUMN: [usize; 2] = [LOCATOR, 2]; /// The surrounds' names, in [`Homes`]'s order. -fn surround_labels() -> [&'static str; 4] { +pub(super) fn surround_labels() -> [&'static str; 4] { [tl_raw!("Locator"), tl_raw!("North arrow"), tl_raw!("Legend"), tl_raw!("Scale bar")] } @@ -123,12 +127,13 @@ pub(super) fn arrange_step(ui: &mut egui::Ui, s: &Session, d: &mut Draft) { let from = d.arrangement.held(s).ok().flatten().unwrap_or_else(|| favourite_homes(s)); d.arrangement = Arrangement::Custom(from); } - // What `cmd/layout/publication` puts in no corner, whatever the arrangement: the locator and - // legend of a style with a column, which sit in it, and a figure's locator, which it doesn't - // draw unless asked (the wizard doesn't ask). - let figure = d.figure(); - let column = !figure && publication_style_has_column(&d.style); - let cornered = |surround: usize| !(column && IN_COLUMN.contains(&surround) || figure && surround == LOCATOR); + // A surround takes no corner where the sheet doesn't draw it, nor where a style with a column + // keeps it there. + let column = d.column(); + let free: [bool; 4] = std::array::from_fn(|at| d.draws(at, s) && !(column && IN_COLUMN.contains(&at))); + let cornered = |surround: usize| free[surround]; + // A figure draws a locator only when asked. + let no_locator = d.figure() && !d.draws_locator(s); if let Arrangement::Custom(homes) = &mut d.arrangement { corner_pickers(ui, homes, cornered); } @@ -152,7 +157,7 @@ pub(super) fn arrange_step(ui: &mut egui::Ui, s: &Session, d: &mut Draft) { } }); } - let note = if figure { + let note = if no_locator { Some(tl!("A figure draws no locator.")) } else { column.then(|| tl!("The locator and legend sit in this style's column: only the north arrow and scale bar take these corners.")) @@ -408,6 +413,54 @@ mod tests { } } + /// A surround the sheet won't draw takes no corner: one the elements step left out, a north + /// arrow left to the extent on a whole globe, and a legend with no colorbar to keep its place. + #[test] + fn a_surround_left_out_takes_no_corner() { + use super::super::elements::{LocatorChoice, NorthChoice}; + type Set = fn(&mut RustGisApp); + fn draft_of(app: &mut RustGisApp) -> &mut Draft { + app.dialogs.publication.as_mut().unwrap() + } + let cases: [(&str, Set, [bool; 4]); 7] = [ + ("no locator", |a| draft_of(a).elements.locator = LocatorChoice::None, [false, true, true, true]), + ("no north arrow", |a| draft_of(a).elements.north = NorthChoice::None, [true, false, true, true]), + ("no scale bar", |a| draft_of(a).elements.scale_bar = false, [true, true, true, false]), + ("no legend", |a| draft_of(a).elements.legend = false, [true, true, false, true]), + ( + "a figure with a locator", + |a| (draft_of(a).size, draft_of(a).elements.locator) = ("figure-1col".into(), LocatorChoice::Inset), + [true, true, true, true], + ), + ("a whole globe", |a| a.session.map_mut().projection = rustgis_engine::map::Projection::Globe, [false, false, true, false]), + ( + "a whole globe with an arrow asked for", + |a| { + a.session.map_mut().projection = rustgis_engine::map::Projection::Globe; + draft_of(a).elements.north = NorthChoice::Always; + }, + [false, true, true, false], + ), + ]; + for (case, set, free) in cases { + let h = placement(|app| { + draft_of(app).arrangement = Arrangement::Custom([0, 1, 2, 3]); + set(app); + }); + for ((surround, corner), free) in + [("Locator", "Top left"), ("North arrow", "Top right"), ("Legend", "Bottom left"), ("Scale bar", "Bottom right")] + .into_iter() + .zip(free) + { + assert_eq!(shown(&h, &format!("{corner}: {surround}")), free, "{case}: {surround} in the grid"); + let off = h.get_by_role_and_label(Role::ComboBox, surround).accesskit_node().is_disabled(); + assert_eq!(off, !free, "{case}: {surround}'s picker"); + } + let figure = h.query_by_label("A figure draws no locator.").is_some(); + assert!(!figure, "{case}: no figure note"); + } + } + /// The review says the placement, of a sheet and of a figure. #[test] fn the_review_says_the_placement() { diff --git a/crates/ui-egui/src/publicationwizard/elements.rs b/crates/ui-egui/src/publicationwizard/elements.rs new file mode 100644 index 0000000000..ffe577eadf --- /dev/null +++ b/crates/ui-egui/src/publicationwizard/elements.rs @@ -0,0 +1,608 @@ +//! The wizard's elements step: what is drawn around the map, and in which mode. +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; + +/// The locator asked for; `Default` leaves it to `layout.publication`. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] +pub enum LocatorChoice { + #[default] + Default, + Globe, + Inset, + None, +} + +/// When the north arrow is drawn; `Auto` leaves it to the extent. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] +pub enum NorthChoice { + #[default] + Auto, + Always, + None, +} + +/// What the step asks. A box the sheet can't use keeps its tick, and isn't sent. +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct Elements { + pub locator: LocatorChoice, + pub north: NorthChoice, + pub legend: bool, + /// The legend's box even where the map under it is plain. + pub legend_box: bool, + /// The context layers listed in the legend. + pub context: bool, + pub colorbar: bool, + pub scale_bar: bool, + /// Whether the map outside the extent may be veiled for the legend's room. + pub veil: bool, + /// A decimal comma rather than a point. + pub comma: bool, +} + +impl Default for Elements { + fn default() -> Self { + Self { + locator: LocatorChoice::Default, + north: NorthChoice::Auto, + legend: true, + legend_box: false, + context: false, + colorbar: true, + scale_bar: true, + veil: true, + comma: false, + } + } +} + +/// A control of the step a sheet may have no use for. +#[derive(Clone, Copy, PartialEq, Eq)] +pub(super) enum Control { + LegendBox, + Context, + Colorbar, + ScaleBar, + Veil, +} + +/// What `layout.publication` may put over or beside the map, as far as the wizard can tell +/// without placing it: the one account of it that the step, what Create sends, the placement and +/// the review share. +impl Draft { + /// Whether the style keeps the locator and legend beside the map; a figure takes no style. + pub(super) fn column(&self) -> bool { + !self.figure() && publication_style_has_column(&self.style) + } + + /// Whether the style sets its surrounds on cards; a figure takes no style. + fn cards(&self) -> bool { + !self.figure() && publication_style_cards(&self.style) + } + + /// 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 + } + + /// Whether the command draws a locator none is asked for: a sheet's, but of a whole globe. + fn default_locator(&self, s: &Session) -> bool { + !self.figure() && !self.whole_globe(s) + } + + /// Whether a locator is drawn: the one asked for, or the command's default. + pub(super) fn draws_locator(&self, s: &Session) -> bool { + match self.elements.locator { + LocatorChoice::Default => self.default_locator(s), + LocatorChoice::None => false, + LocatorChoice::Globe | LocatorChoice::Inset => true, + } + } + + /// Whether a north arrow may be drawn. Left to the extent, a whole globe has none; any other + /// extent's span is known only to the command. + fn draws_arrow(&self, s: &Session) -> bool { + match self.elements.north { + NorthChoice::Auto => !self.whole_globe(s), + NorthChoice::Always => true, + NorthChoice::None => false, + } + } + + fn draws_colorbar(&self, s: &Session) -> bool { + self.elements.colorbar && self.usable(Control::Colorbar, s) + } + + fn draws_scale_bar(&self, s: &Session) -> bool { + self.elements.scale_bar && self.usable(Control::ScaleBar, s) + } + + /// Whether the legend's place is taken, by its rows or by the colorbar boxed there. + fn draws_legend_place(&self, s: &Session) -> bool { + self.elements.legend || self.draws_colorbar(s) + } + + /// Whether the surround at `at` (a place in `Homes`) is drawn. + pub(super) fn draws(&self, at: usize, s: &Session) -> bool { + match at { + LOCATOR => self.draws_locator(s), + NORTH_ARROW => self.draws_arrow(s), + SCALE_BAR => self.draws_scale_bar(s), + _ => self.draws_legend_place(s), + } + } + + /// Whether this sheet has a use for `control`: one without it is off in the step and isn't sent. + pub(super) fn usable(&self, control: Control, s: &Session) -> bool { + match control { + Control::LegendBox => !self.column() && !self.cards() && self.draws_legend_place(s), + Control::Context => self.elements.legend, + // A raster still reading has no scale to show yet. With pixels, [`colorbar_layer`] + // only gives a raster with one. + Control::Colorbar => colorbar_layer(s.map(), None).is_some_and(|l| l.raster.as_ref().is_some_and(|r| r.data.is_some())), + 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), + } + } + + /// What Create sends: [`Draft::params`] and the elements step's answers, a choice left to the + /// command not among them. + pub fn sent(&self, s: &Session) -> Value { + let e = &self.elements; + let mut p = self.params(); + let locator = match e.locator { + LocatorChoice::Default => None, + LocatorChoice::Globe => Some("globe"), + LocatorChoice::Inset => Some("inset"), + LocatorChoice::None => Some("none"), + }; + let north = match e.north { + NorthChoice::Auto => None, + NorthChoice::Always => Some("always"), + NorthChoice::None => Some("none"), + }; + for (key, value) in [ + ("locator", locator.map(Value::from)), + ("northArrow", north.map(Value::from)), + ("legend", (!e.legend).then(|| "none".into())), + ("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())), + ("veil", (!e.veil && self.usable(Control::Veil, s)).then(|| false.into())), + ("decimal", e.comma.then(|| ",".into())), + ] { + if let Some(value) = value { + p[key] = value; + } + } + p + } +} + +/// 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 { + match colorbar_layer(s.map(), None).and_then(|l| l.raster.as_ref()) { + Some(r) if r.error.is_some() => tl!("The top raster couldn't be read."), + Some(_) => tl!("The top raster is still being read."), + None => tl!("The map has no raster with a colour scale."), + } +} + +/// 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; + let mut on: Vec = Vec::new(); + if d.draws_locator(s) { + let which = match e.locator { + LocatorChoice::Globe => tl_raw!("Globe"), + LocatorChoice::Inset => tl_raw!("Inset"), + _ => tl_raw!("Default (globe)"), + }; + on.push(i18n::fmt("{surround}: {choice}", &[("surround", surround_labels()[LOCATOR]), ("choice", which)])); + } + 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 mut push_if = |is: bool, line: &str| { + if is { + on.push(line.to_string()); + } + }; + push_if(e.legend, tl!("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(!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") +} + +/// The elements step: what is drawn around the map, and how. +pub(super) fn elements_step(ui: &mut egui::Ui, s: &Session, d: &mut Draft) { + let default_locator = if d.default_locator(s) { tl!("Default: Globe") } else { tl!("Default: None") }; + ui.label(tl!("Locator")); + ui.horizontal_wrapped(|ui| { + let choice = &mut d.elements.locator; + ui.radio_value(choice, LocatorChoice::Default, default_locator); + ui.radio_value(choice, LocatorChoice::Globe, tl!("Globe")); + ui.radio_value(choice, LocatorChoice::Inset, tl!("Inset")); + ui.radio_value(choice, LocatorChoice::None, tl!("None")); + }); + ui.label(tl!("North arrow")); + ui.horizontal_wrapped(|ui| { + let choice = &mut d.elements.north; + ui.radio_value(choice, NorthChoice::Auto, tl!("Auto")).on_hover_text(tl!("None when the extent spans 20° or more.")); + ui.radio_value(choice, NorthChoice::Always, tl!("Always")); + ui.radio_value(choice, NorthChoice::None, tl!("None")); + }); + 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| { + ui.add_enabled(usable, egui::Checkbox::new(on, label)).on_disabled_hover_text(why) + }; + ui.checkbox(&mut d.elements.legend, tl!("Legend")); + ui.indent("publication_wizard_legend", |ui| { + let own_box = d.column() || d.cards(); + let usable = d.usable(Control::LegendBox, s); + let own_note = tl!("In this style the legend has a box of its own."); + let why = if own_box { own_note } else { tl!("There is no legend or colorbar to box.") }; + tick(ui, usable, &mut d.elements.legend_box, tl!("Always on a box"), why); + let usable = d.usable(Control::Context, s); + tick(ui, usable, &mut d.elements.context, tl!("List the context layers"), tl!("There is no legend to list them in.")); + if own_box { + ui.label(egui::RichText::new(own_note).small().weak()); + } + }); + let usable = d.usable(Control::Colorbar, s); + let why = colorbar_off_reason(s); + tick(ui, usable, &mut d.elements.colorbar, tl!("Colorbar"), why) + .on_hover_text(tl!("Drawn when the map's top raster has a colour scale.")); + let usable = d.usable(Control::ScaleBar, s); + let why = tl!("A map of the whole globe draws no scale bar."); + tick(ui, usable, &mut d.elements.scale_bar, tl!("Scale bar"), why); + if !usable { + ui.label(egui::RichText::new(why).small().weak()); + } + 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); + ui.add_space(4.0); + ui.label(tl!("Decimal mark")); + ui.horizontal_wrapped(|ui| { + ui.radio_value(&mut d.elements.comma, false, tl!("Point (1.5)")); + ui.radio_value(&mut d.elements.comma, true, tl!("Comma (1,5)")); + }); +} + +#[cfg(test)] +mod tests { + use super::super::harness::*; + use super::*; + use egui::accesskit::Role; + use egui_kittest::kittest::{NodeT, Queryable}; + use rustgis_engine::data::raster::{ColorHint, Crs, GeoTransform, Raster}; + use rustgis_engine::map::layout::ElementKind; + use rustgis_engine::map::{Projection, RasterLayer}; + + type Wizard = egui_kittest::Harness<'static, RustGisApp>; + + /// The keys the step may send. + const KEYS: [&str; 9] = ["locator", "northArrow", "legend", "legendBox", "contextInLegend", "colorbar", "scaleBar", "veil", "decimal"]; + + /// What the step adds to the command's parameters, by key. + fn added(s: &Session, d: &Draft) -> Value { + let sent = d.sent(s); + let kept = KEYS.iter().filter_map(|k| sent.get(*k).map(|v| (k.to_string(), v.clone()))); + Value::Object(kept.collect()) + } + + fn globe(app: &mut RustGisApp) { + app.session.map_mut().projection = Projection::Globe; + assert!(app.session.map().projection.is_globe()); + } + + /// The elements step of a wizard prepared by `prepare`. + fn step_of(prepare: impl FnOnce(&mut RustGisApp)) -> Wizard { + let mut app = app(); + open(&mut app); + app.dialogs.publication.as_mut().unwrap().step = Step::Elements; + prepare(&mut app); + harness(app) + } + + fn draft(h: &Wizard) -> &Draft { + h.state().dialogs.publication.as_ref().expect("the wizard is open") + } + + fn ticked_box<'a>(h: &'a Wizard, label: &'a str) -> egui_kittest::Node<'a> { + h.get_by_role_and_label(Role::CheckBox, label) + } + + fn off(h: &Wizard, label: &str) -> bool { + ticked_box(h, label).accesskit_node().is_disabled() + } + + fn click_box(h: &mut Wizard, label: &str) { + ticked_box(h, label).click(); + h.run_steps(4); + } + + /// 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) { + h.get_all_by_role_and_label(Role::RadioButton, label).nth(nth).expect("the radio").click(); + h.run_steps(4); + } + + /// A new draft sends what it sent before the step. + #[test] + fn a_new_draft_adds_nothing() { + let app = app(); + for size in ["a4", "figure-1col"] { + let mut d = Draft::new(&app.session); + d.size = size.into(); + assert_eq!(d.sent(&app.session), d.params(), "{size}"); + } + } + + /// Each choice sends its own key, on a sheet and on a figure. + #[test] + fn each_choice_is_sent() { + let mut app = app(); + raster(&mut app); + type Set = fn(&mut Elements); + let cases: [(Set, Value); 12] = [ + (|e| e.locator = LocatorChoice::Globe, json!({"locator": "globe"})), + (|e| e.locator = LocatorChoice::Inset, json!({"locator": "inset"})), + (|e| e.locator = LocatorChoice::None, json!({"locator": "none"})), + (|e| e.north = NorthChoice::Always, json!({"northArrow": "always"})), + (|e| e.north = NorthChoice::None, json!({"northArrow": "none"})), + (|e| e.legend = false, json!({"legend": "none"})), + (|e| e.legend_box = true, json!({"legendBox": "always"})), + (|e| e.context = true, json!({"contextInLegend": true})), + (|e| e.colorbar = false, json!({"colorbar": "none"})), + (|e| e.scale_bar = false, json!({"scaleBar": "none"})), + (|e| e.veil = false, json!({"veil": false})), + (|e| e.comma = true, json!({"decimal": ","})), + ]; + for size in ["a4", "figure-1col"] { + for (set, want) in &cases { + let mut d = Draft::new(&app.session); + d.size = size.into(); + set(&mut d.elements); + assert_eq!(&added(&app.session, &d), want, "{size}"); + } + } + } + + /// With no legend its context box isn't sent; its box still is while there is a colorbar to + /// box, and isn't once there is none. + #[test] + fn without_a_legend_the_box_follows_the_colorbar() { + let mut app = app(); + let mut d = Draft::new(&app.session); + d.elements = Elements { legend: false, legend_box: true, context: true, ..Elements::default() }; + assert_eq!(added(&app.session, &d), json!({"legend": "none"}), "a map of vectors has no colorbar"); + raster(&mut app); + assert_eq!(added(&app.session, &d), json!({"legend": "none", "legendBox": "always"}), "the colorbar's box"); + app.session.map_mut().layers.retain(|l| l.raster.is_none()); + assert_eq!(added(&app.session, &d), json!({"legend": "none"}), "the raster removed meanwhile"); + } + + /// A style with a column or cards keeps its own box, and one with a column is never veiled; a + /// figure after such a style has neither. + #[test] + fn a_style_with_a_column_or_cards_takes_neither() { + let app = app(); + for (style, boxed, veiled) in [ + ("classic", true, true), + ("banner", true, true), + ("edge", true, true), + ("panel", false, false), + ("editorial", false, false), + ("modular", false, false), + ("poster", false, true), + ] { + let mut d = Draft::new(&app.session); + d.style = style.into(); + d.elements = Elements { legend_box: true, veil: false, ..Elements::default() }; + let sent = added(&app.session, &d); + assert_eq!(sent.get("legendBox").is_some(), boxed, "{style}: the box"); + assert_eq!(sent.get("veil").is_some(), veiled, "{style}: the veil"); + d.size = "figure-1col".into(); + assert_eq!(added(&app.session, &d), json!({"legendBox": "always", "veil": false}), "{style}: a figure"); + } + } + + /// With no raster colour scale to show, the colorbar is off and its answer isn't sent; the tick + /// is kept, and counts again once there is a raster. + #[test] + fn without_a_colour_scale_the_colorbar_is_off_and_not_sent() { + let mut h = step_of(|app| app.dialogs.publication.as_mut().unwrap().elements.colorbar = false); + assert!(off(&h, "Colorbar"), "a map of vectors"); + assert_eq!(added(&h.state().session, draft(&h)), json!({})); + raster(h.state_mut()); + h.run_steps(4); + assert!(!off(&h, "Colorbar"), "a raster added meanwhile"); + assert_eq!(added(&h.state().session, draft(&h)), json!({"colorbar": "none"})); + } + + /// The off colorbar says whether the map has no colour scale, or its top raster's isn't read: + /// still on its way, or failed. + #[test] + fn the_off_colorbar_says_why() { + let mut app = app(); + assert_eq!(colorbar_off_reason(&app.session), "The map has no raster with a colour scale."); + let id = app.session.map_mut().add_raster("Scene", RasterLayer::unread_in_place("https://example.com/scene.tif")); + assert_eq!(colorbar_off_reason(&app.session), "The top raster is still being read."); + app.session.map_mut().layer_mut(id).unwrap().raster.as_mut().unwrap().fail("gone"); + assert_eq!(colorbar_off_reason(&app.session), "The top raster couldn't be read."); + } + + /// With nothing to make room for, the veil isn't sent. + #[test] + fn without_a_legend_or_colorbar_the_veil_isnt_sent() { + let app = app(); + let mut d = Draft::new(&app.session); + d.elements = Elements { legend: false, veil: false, ..Elements::default() }; + assert_eq!(added(&app.session, &d), json!({"legend": "none"})); + } + + /// The whole globe in view draws no scale bar, so none is sent; a layer's extent on the same + /// globe does. + #[test] + fn a_whole_globe_sends_no_scale_bar() { + let mut app = app(); + globe(&mut app); + let mut d = Draft::new(&app.session); + d.elements.scale_bar = false; + assert_eq!(added(&app.session, &d), json!({})); + let layer = app.session.map().layers[0].instance_id(); + d.area = Area::Layer { map: crate::dialogs::MapOwner::of(&app.session), layer }; + assert_eq!(added(&app.session, &d), json!({"scaleBar": "none"})); + } + + /// 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(); + let at = GeoTransform { origin_x: -20.0, origin_y: 10.0, pixel_width: 10.0, pixel_height: -5.0 }; + let r = Raster::new("dem", 4, 4, vec![values], at, Crs::LonLat, None, ColorHint::Gray, "Float32").unwrap(); + app.session.map_mut().add_raster("Heights", RasterLayer::from_path(r, "dem.tif")); + } + + /// The default locator is named as what it will be. + #[test] + fn the_default_locator_says_what_it_draws() { + let said = |h: &Wizard, label: &str| h.query_by_role_and_label(Role::RadioButton, label).is_some(); + assert!(said(&step_of(|_| {}), "Default: Globe"), "a sheet"); + let figure = step_of(|app| app.dialogs.publication.as_mut().unwrap().size = "figure-1col".into()); + assert!(said(&figure, "Default: None"), "a figure"); + assert!(said(&step_of(globe), "Default: None"), "a whole globe"); + } + + /// Each control sets its answer. + #[test] + fn the_controls_set_the_answers() { + let mut h = step_of(raster); + pick(&mut h, "Inset", 0); + pick(&mut h, "None", 1); + pick(&mut h, "Comma (1,5)", 0); + for label in [ + "Always on a box", + "List the context layers", + "Colorbar", + "Scale bar", + "Veil the map outside the extent if the legend needs room", + ] { + click_box(&mut h, label); + } + let want = Elements { + locator: LocatorChoice::Inset, + north: NorthChoice::None, + legend: true, + legend_box: true, + context: true, + colorbar: false, + scale_bar: false, + veil: false, + comma: true, + }; + assert_eq!(draft(&h).elements, want); + click_box(&mut h, "Legend"); + assert!(!draft(&h).elements.legend); + } + + /// What the sheet can't use is off, and says why. + #[test] + fn what_the_sheet_cant_use_is_off() { + let h = step_of(|_| {}); + for label in ["Always on a box", "List the context layers", "Scale bar", "Veil the map outside the extent if the legend needs room"] + { + assert!(!off(&h, label), "classic: {label}"); + } + let h = step_of(|app| app.dialogs.publication.as_mut().unwrap().style = "panel".into()); + assert!(off(&h, "Always on a box") && off(&h, "Veil the map outside the extent if the legend needs room")); + assert!(h.query_by_label_contains("a box of its own").is_some(), "said"); + let h = step_of(|app| app.dialogs.publication.as_mut().unwrap().elements.legend = false); + assert!(off(&h, "List the context layers") && off(&h, "Always on a box")); + let h = step_of(globe); + assert!(off(&h, "Scale bar")); + assert!(h.query_by_label_contains("whole globe draws no scale bar").is_some(), "said"); + } + + /// On a narrow screen the step's controls stay on it. + #[test] + fn the_step_stays_on_a_narrow_screen() { + let mut app = app(); + open(&mut app); + app.dialogs.publication.as_mut().unwrap().step = Step::Elements; + app.dialogs.publication.as_mut().unwrap().style = "panel".into(); + let h = harness_sized(app, egui::vec2(320.0, 900.0)); + for label in ["Default: Globe", "Inset", "Comma (1,5)"] { + let rect = h.get_by_role_and_label(Role::RadioButton, label).rect(); + assert!(rect.left() >= 0.0 && rect.right() <= 320.0, "{label} at {rect:?}"); + } + let rect = ticked_box(&h, "Veil the map outside the extent if the legend needs room").rect(); + assert!(rect.right() <= 320.0, "{rect:?}"); + } + + /// The review lists what is on, on a sheet and on a figure. + #[test] + fn the_review_lists_the_elements() { + for (size, want) in [ + ("a4", "Locator: Default (globe)\nNorth arrow: Auto (none from 20°)\nLegend\nScale bar\nDecimal point"), + ("figure-1col", "North arrow: Auto (none from 20°)\nLegend\nScale bar\nDecimal point"), + ] { + let h = step_of(|app| { + let d = app.dialogs.publication.as_mut().unwrap(); + (d.step, d.size) = (Step::Review, size.into()); + }); + assert!(h.query_by_label(want).is_some(), "{size}"); + } + let h = step_of(|app| { + raster(app); + let d = app.dialogs.publication.as_mut().unwrap(); + d.step = Step::Review; + d.elements = Elements { + locator: LocatorChoice::Inset, + north: NorthChoice::None, + legend_box: true, + context: true, + scale_bar: false, + veil: false, + comma: true, + ..Elements::default() + }; + }); + let want = "Locator: Inset\nLegend\nAlways on a box\nContext layers listed\nColorbar\nNo veil\nDecimal comma"; + assert!(h.query_by_label(want).is_some()); + } + + /// Create makes the layout the step asked for; Undo takes it away. + #[test] + fn create_leaves_out_what_the_step_left_out() { + let mut app = app(); + open(&mut app); + let d = app.dialogs.publication.as_mut().unwrap(); + d.step = Step::Review; + d.elements = Elements { locator: LocatorChoice::None, legend: false, comma: true, ..Elements::default() }; + let before = app.session.project.layouts.len(); + let mut h = harness(app); + click(&mut h, "Create"); + assert_eq!(h.state().session.project.layouts.len(), before + 1); + let l = h.state().session.project.layouts.last().unwrap(); + assert!(l.decimal_comma); + assert!(!l.elements.iter().any(|e| matches!(e.kind, ElementKind::Legend { .. })), "no legend"); + let locators = l.elements.iter().filter(|e| matches!(e.kind, ElementKind::MapFrame { extent_of: Some(_), .. })); + assert_eq!(locators.count(), 0, "no locator"); + h.state_mut().run("edit.undo", Value::Null).unwrap(); + assert_eq!(h.state().session.project.layouts.len(), before); + } +} diff --git a/crates/ui-egui/src/publicationwizard/mod.rs b/crates/ui-egui/src/publicationwizard/mod.rs index 6e21cea062..34a93d6486 100644 --- a/crates/ui-egui/src/publicationwizard/mod.rs +++ b/crates/ui-egui/src/publicationwizard/mod.rs @@ -1,8 +1,9 @@ -//! Publication Layout Wizard: `layout.publication` asked step by step (size, map, style, placement, -//! texts, sources and reference, accent), then made at once, as the New Layout › Publication Layout -//! menu makes it (#2850). +//! Publication Layout Wizard: `layout.publication` asked step by step (size, map, style, elements, +//! placement, texts, sources and reference, accent), then made at once, as the New Layout › +//! Publication Layout menu makes it (#2850). mod accent; mod arrange; +mod elements; mod map; mod review; mod size; @@ -14,6 +15,7 @@ use crate::textform::StatLayer; use crate::{RustGisApp, i18n, theme::Tokens}; use accent::accent_step; use arrange::{Arrangement, arrange_step}; +use elements::{Elements, elements_step}; use map::{Area, area_extent, map_step}; use review::review_step; use rustgis_engine::Session; @@ -36,6 +38,8 @@ pub enum Step { Size, Map, Style, + /// What is drawn around the map. + Elements, Placement, Texts, Sources, @@ -128,6 +132,10 @@ pub struct Draft { pub accent: Option, /// The colour last picked, which the swatch comes back with when the box is ticked again. picked: Option, + /// What is drawn around the map, and how. + pub elements: Elements, + /// Whether the list of steps has yet to bring the current one into view. + list_follows: bool, /// The corners the surrounds take. pub arrangement: Arrangement, /// Whether Create also sets a chosen arrangement as the favourite. @@ -160,6 +168,8 @@ impl Draft { refused: [false; 2], accent: None, picked: None, + elements: Elements::default(), + list_follows: true, arrangement: Arrangement::Best, make_favourite: false, } @@ -182,9 +192,15 @@ impl Draft { /// The steps this draft goes through, in order. fn steps(&self) -> &'static [Step] { if self.figure() { - return &[Step::Size, Step::Map, Step::Placement, Step::Reference, Step::Review]; + return &[Step::Size, Step::Map, Step::Elements, Step::Placement, Step::Reference, Step::Review]; } - &[Step::Size, Step::Map, Step::Style, 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] + } + + /// Goes to `step`, which the list of steps then brings into view. + fn go(&mut self, step: Step) { + self.step = step; + self.list_follows = true; } /// The favourite Create sets once the layout is made, if any: what the review says and what @@ -372,6 +388,7 @@ fn step_name(step: Step) -> &'static str { Step::Size => tl_raw!("Size"), Step::Map => tl_raw!("Map"), Step::Style => tl_raw!("Style"), + Step::Elements => tl_raw!("Elements"), Step::Placement => tl_raw!("Placement"), Step::Texts => tl_raw!("Texts"), Step::Sources => tl_raw!("Sources and reference"), @@ -387,6 +404,7 @@ fn step_label(step: Step) -> &'static str { Step::Size => tl!("Size"), Step::Map => tl!("Map"), Step::Style => tl!("Style"), + Step::Elements => tl!("Elements"), Step::Placement => tl!("Placement"), Step::Texts => tl!("Texts"), Step::Sources => tl!("Sources"), @@ -436,16 +454,26 @@ const LIST_FROM: f32 = 480.0; /// The width of the list of steps. const LIST_WIDTH: f32 = 110.0; -/// The steps of this draft, each clickable to go to it. -fn step_list(ui: &mut egui::Ui, d: &mut Draft) { +/// The steps of this draft, each clickable to go to it, in `height`: a shorter window scrolls +/// them, bringing the current one into view once when it changes, not each frame, so the list can +/// be scrolled by hand. +fn step_list(ui: &mut egui::Ui, d: &mut Draft, height: f32) { ui.vertical(|ui| { ui.set_width(LIST_WIDTH); - for &step in d.steps() { - let item = egui::Button::selectable(d.step == step, step_label(step)).wrap().min_size(egui::vec2(LIST_WIDTH, 0.0)); - if ui.add(item).clicked() { - d.step = step; + egui::ScrollArea::vertical().id_salt("publication_wizard_steps").max_height(height).auto_shrink([false, false]).show(ui, |ui| { + let follow = std::mem::take(&mut d.list_follows); + for &step in d.steps() { + let width = ui.available_width(); + let item = egui::Button::selectable(d.step == step, step_label(step)).wrap().min_size(egui::vec2(width, 0.0)); + let item = ui.add(item); + if follow && d.step == step { + item.scroll_to_me(None); + } + if item.clicked() { + d.go(step); + } } - } + }); }); } @@ -501,7 +529,7 @@ pub fn show(app: &mut RustGisApp, ctx: &egui::Context) { ui.allocate_ui_with_layout(body, egui::Layout::left_to_right(egui::Align::Min), |ui| { ui.set_min_size(body); if list { - step_list(ui, &mut d); + step_list(ui, &mut d, body.y); ui.separator(); } ui.vertical(|ui| { @@ -513,6 +541,7 @@ pub fn show(app: &mut RustGisApp, ctx: &egui::Context) { Step::Size => size_step(ui, &mut d), Step::Map => map_step(ui, &app.session, &mut d), Step::Style => style_step(ui, &mut d, t.accent), + 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()), Step::Sources => sources_step(ui, &mut d, app.session.map()), @@ -528,7 +557,7 @@ pub fn show(app: &mut RustGisApp, ctx: &egui::Context) { match d.moved(1) { Some(next) => { if crate::widgets::dialog_button(ui, tl!("Next"), Some(t.accent), size).clicked() { - d.step = next; + d.go(next); } } None => create = crate::widgets::dialog_button(ui, tl!("Create"), Some(t.accent), size).clicked(), @@ -537,7 +566,7 @@ pub fn show(app: &mut RustGisApp, ctx: &egui::Context) { 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; + d.go(back); } close = crate::widgets::dialog_button(ui, tl!("Cancel"), None, size).clicked(); }); @@ -548,7 +577,7 @@ pub fn show(app: &mut RustGisApp, ctx: &egui::Context) { let held = d.arrangement.held(&app.session).map_err(String::from); match held.and_then(|_| area_extent(&app.session, &d.area)) { Ok(extent) => { - let mut params = d.params(); + let mut params = d.sent(&app.session); if let Some(extent) = extent { params["extent"] = json!(extent); } @@ -691,23 +720,23 @@ mod tests { open(&mut app); let mut h = harness(app); assert!(h.get_by_role_and_label(Role::Button, "Back").accesskit_node().is_disabled(), "Back is off"); - for want in [Step::Map, Step::Style, Step::Placement, Step::Texts, Step::Sources, Step::Accent, Step::Review] { + for want in [Step::Map, Step::Style, Step::Elements, Step::Placement, Step::Texts, Step::Sources, Step::Accent, Step::Review] { click(&mut h, "Next"); assert_eq!(step(&h), want); } assert!(h.query_by_role_and_label(Role::Button, "Next").is_none()); assert!(h.query_by_role_and_label(Role::Button, "Create").is_some()); - for want in [Step::Accent, Step::Sources, Step::Texts, Step::Placement, Step::Style, Step::Map, Step::Size] { + for want in [Step::Accent, Step::Sources, Step::Texts, Step::Placement, Step::Elements, Step::Style, Step::Map, 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); - for want in [Step::Map, Step::Placement, Step::Reference, Step::Review] { + for want in [Step::Map, Step::Elements, Step::Placement, Step::Reference, Step::Review] { click(&mut h, "Next"); assert_eq!(step(&h), want); } - for want in [Step::Reference, Step::Placement, Step::Map, Step::Size] { + for want in [Step::Reference, Step::Placement, Step::Elements, Step::Map, Step::Size] { click(&mut h, "Back"); assert_eq!(step(&h), want); } @@ -768,7 +797,7 @@ mod tests { /// The names the step list holds, in order, and the one it marks as the current step. fn listed(h: &egui_kittest::Harness<'static, RustGisApp>) -> (Vec<&'static str>, Vec<&'static str>) { let (mut names, mut current) = (Vec::new(), Vec::new()); - for name in ["Size", "Map", "Style", "Placement", "Texts", "Sources", "Reference", "Accent", "Review"] { + for name in ["Size", "Map", "Style", "Elements", "Placement", "Texts", "Sources", "Reference", "Accent", "Review"] { if let Some(n) = h.query_by_role_and_label(Role::Button, name) { names.push(name); if n.accesskit_node().toggled() == Some(egui::accesskit::Toggled::True) { @@ -803,13 +832,16 @@ mod tests { let mut app = app(); open(&mut app); let mut h = harness(app); - assert_eq!(listed(&h), (vec!["Size", "Map", "Style", "Placement", "Texts", "Sources", "Accent", "Review"], vec!["Size"])); + assert_eq!( + listed(&h), + (vec!["Size", "Map", "Style", "Elements", "Placement", "Texts", "Sources", "Accent", "Review"], vec!["Size"]) + ); click(&mut h, "Next"); assert_eq!(listed(&h).1, ["Map"]); click(&mut h, "Back"); h.state_mut().dialogs.publication.as_mut().unwrap().size = "figure-1col".into(); h.run_steps(2); - assert_eq!(listed(&h), (vec!["Size", "Map", "Placement", "Reference", "Review"], vec!["Size"])); + assert_eq!(listed(&h), (vec!["Size", "Map", "Elements", "Placement", "Reference", "Review"], vec!["Size"])); } /// A step clicked in the list is the one shown, first, middle or last, keeping what was @@ -830,6 +862,43 @@ mod tests { assert_eq!(h.state().dialogs.publication.as_ref().unwrap().subtitle, "Kept"); } + /// The smallest window scrolls its list: a list scrolled by hand stays where it was put, and + /// going to a step brings it into view. + #[test] + fn a_short_window_scrolls_its_list_to_the_current_step() { + let mut app = app(); + open(&mut app); + let mut h = harness(app); + resize(&mut h, vec2(-500.0, -400.0)); + // Taller entries, so the nine overflow by far more than a platform's font metrics differ. + h.ctx.all_styles_mut(|s| s.spacing.interact_size.y = 40.0); + h.run_steps(30); + // The top of the list, where its first step is before any scrolling. + let first = h.get_by_role_and_label(Role::Button, "Size").rect(); + let inside = |h: &egui_kittest::Harness<'static, RustGisApp>, name: &str| { + let item = h.get_by_role_and_label(Role::Button, name).rect(); + let next = h.get_by_role_and_label(Role::Button, "Next").rect(); + // Above the separator over the buttons (6 points) and the spacing beside it. + item.top() >= first.top() - 0.5 && item.bottom() <= next.top() - 10.0 + }; + assert!(inside(&h, "Size") && !inside(&h, "Review"), "9 steps don't fit"); + h.hover_at(first.center()); + h.event(egui::Event::MouseWheel { + unit: egui::MouseWheelUnit::Point, + source: egui::MouseWheelSource::Wheel, + delta: vec2(0.0, -500.0), + modifiers: egui::Modifiers::NONE, + phase: egui::TouchPhase::Move, + }); + h.run_steps(30); + assert!(inside(&h, "Review"), "scrolled by hand"); + h.run_steps(10); + assert!(inside(&h, "Review") && !inside(&h, "Size"), "not pinned to the current step"); + click(&mut h, "Next"); + h.run_steps(30); + assert!(inside(&h, "Map"), "Next brings its step into view"); + } + /// Each step in the list is reached with Tab. #[test] fn tab_reaches_every_step_in_the_list() { @@ -837,16 +906,16 @@ mod tests { open(&mut app); let mut h = harness(app); let mut reached = Vec::new(); - for _ in 0..30 { + for _ in 0..40 { h.key_press(egui::Key::Tab); h.run_steps(2); - for name in ["Size", "Map", "Style", "Placement", "Texts", "Sources", "Accent", "Review"] { + for name in ["Size", "Map", "Style", "Elements", "Placement", "Texts", "Sources", "Accent", "Review"] { if h.query_by_role_and_label(Role::Button, name).is_some_and(|n| n.accesskit_node().is_focused()) { reached.push(name); } } } - for name in ["Size", "Map", "Style", "Placement", "Texts", "Sources", "Accent", "Review"] { + for name in ["Size", "Map", "Style", "Elements", "Placement", "Texts", "Sources", "Accent", "Review"] { assert!(reached.contains(&name), "{name} not reached: {reached:?}"); } } @@ -867,9 +936,9 @@ mod tests { assert!((415.0..=460.0).contains(&small.width()) && (355.0..=420.0).contains(&small.height()), "smallest {small:?}"); let next = h.get_by_role_and_label(Role::Button, "Next").rect(); assert!(small.contains_rect(next), "Next at {next:?} outside {small:?}"); - assert_eq!(listed(&h).0.len(), 8, "the list stays"); + assert_eq!(listed(&h).0.len(), 9, "the list stays"); // Each step wraps or scrolls inside that size: none makes the window wider or taller. - for _ in 0..7 { + for _ in 0..8 { click(&mut h, "Next"); // Within the point a high-density screen's rounding of a wrapped line may add. let now = window(&h).size(); @@ -892,7 +961,7 @@ mod tests { let larger = at(&h); let moved = larger.right_bottom() - before.right_bottom(); assert!(moved.y > 50.0, "Next moved by {moved:?}"); - for _ in 0..6 { + for _ in 0..7 { click(&mut h, "Next"); assert_eq!(at(&h), larger, "{:?}", step(&h)); } @@ -906,7 +975,7 @@ mod tests { let mut h = harness(app); let at = |h: &egui_kittest::Harness<'static, RustGisApp>| h.get_by_role_and_label(Role::Button, "Next").rect(); let first = at(&h); - for _ in 0..6 { + for _ in 0..7 { click(&mut h, "Next"); assert_eq!(at(&h), first, "{:?}", step(&h)); } @@ -927,7 +996,7 @@ mod tests { assert_ne!(next, "Next", "{code}: the language changed"); let at = |h: &egui_kittest::Harness<'static, RustGisApp>| h.get_by_role_and_label(Role::Button, &next).rect(); let first = at(&h); - for _ in 0..6 { + for _ in 0..7 { h.get_by_role_and_label(Role::Button, &next).click(); h.run_steps(4); assert_eq!(at(&h), first, "{code}: {:?}", step(&h)); @@ -958,7 +1027,7 @@ mod tests { let text = h.get_by_label(about).rect(); assert!(text.right() <= 320.0, "{text:?} runs off a screen 320 wide"); assert_eq!(listed(&h).0, Vec::<&str>::new(), "the list is hidden"); - assert!(h.query_by_label("Step 3 of 8: Style").is_some(), "the heading still says the step"); + assert!(h.query_by_label("Step 3 of 9: Style").is_some(), "the heading still says the step"); } /// A screen that narrows while the wizard is open (a phone turned, a browser resized) keeps diff --git a/crates/ui-egui/src/publicationwizard/review.rs b/crates/ui-egui/src/publicationwizard/review.rs index c8f77db0b8..1981066500 100644 --- a/crates/ui-egui/src/publicationwizard/review.rs +++ b/crates/ui-egui/src/publicationwizard/review.rs @@ -1,4 +1,5 @@ //! The wizard's review step. +use super::elements::elements_value; use super::map::{area_label, name_label}; use super::*; @@ -17,6 +18,7 @@ pub(super) fn review_step(ui: &mut egui::Ui, s: &Session, d: &Draft) { row(tl!("Map extent"), area_label(s, &d.area)); row(tl!("Name"), name_label(s, &d.name)); if d.figure() { + row(tl!("Elements"), elements_value(s, d)); placement_rows(&mut row, s, d); row(tl!("Reference"), reference_value(d)); return; @@ -29,6 +31,7 @@ pub(super) fn review_step(ui: &mut egui::Ui, s: &Session, d: &Draft) { row(tl!("Orientation"), turned.to_string()); let style = crate::ribbon::publication_style(&d.style).map(|s| s.0.to_string()).unwrap_or_else(|| d.style.clone()); row(tl!("Style"), style); + row(tl!("Elements"), elements_value(s, d)); placement_rows(&mut row, s, d); row(tl!("Title"), or_none(&d.title)); row(tl!("Subtitle"), or_none(&d.subtitle)); diff --git a/crates/ui-egui/src/publicationwizard/texts.rs b/crates/ui-egui/src/publicationwizard/texts.rs index 85d1c83529..3ddd64489a 100644 --- a/crates/ui-egui/src/publicationwizard/texts.rs +++ b/crates/ui-egui/src/publicationwizard/texts.rs @@ -69,7 +69,7 @@ mod tests { h.state_mut().run("map.new", json!({"name": "Rivers"})).unwrap(); h.run_steps(2); assert_eq!(h.state().dialogs.publication.as_ref().unwrap().title, "Rivers"); - for _ in 0..4 { + for _ in 0..5 { click(&mut h, "Next"); } h.get_by_label("Title").focus(); diff --git a/docs/user-guide/layouts.md b/docs/user-guide/layouts.md index d5725dc428..3383c4d19a 100644 --- a/docs/user-guide/layouts.md +++ b/docs/user-guide/layouts.md @@ -43,30 +43,35 @@ Layouts open as tabs next to the maps; while one is open, its groups lead the Pu (a sheet turned Auto, Portrait or Landscape, or a figure), the map extent and the layout's name, the style (each beside an outline of where its title, map and footer go, and its column or panel if it has one, with the accent colour picked, or else its own, where the sheet takes it, which - Classic's doesn't; a click on the outline picks the style), the placement, the texts (title, the - active map's name until one is typed; subtitle, note and credit line, or none; an Editorial - sheet's column heading), the sources and reference (each one per line, with its heading; the - reference can be left out) and the accent colour, then shows what was picked; **Create** makes - the layout as the menu does. **Insert Statistic**, on the texts and sources steps, adds a layer - figure of the active map to the field the cursor was last in there (the note or the sources, - where it was in none). The map extent is the view, the features one layer shows (hidden or not, - in their longitude/latitude box) or the selected features (a point or a straight line is widened - to 0.01°, and what lies past ±180° or ±90° is left out of the frame; an area with nothing to - frame, one gone by Create, or one picked before the map or the project was switched or the map - renamed, is said and nothing is made); without a name the layout is `Publication`; the review - says when a layout has that name, so the new one is numbered. The **placement** is the - arrangement (below): `best`, the favourite, one by name or one saved, or **Custom**, a corner - for each surround (a corner another has swaps the two; on Panel, Editorial and Modular only the - north arrow and scale bar take one, the locator and legend sitting in the column, and a figure - gives the locator none, as it draws none); a chosen one can be made the favourite, once the - layout is made. A saved one removed after it was picked is said at Create and nothing is made. A - figure goes from its size to its map, its placement, its reference (each line typed; with no - heading, and it can be left out) and the review, as it takes no style, accent or other text. A - field left empty is left out (for the credit line, the reference and the headings, the command's - default applies); the title is the exception: empty, it means no title. A layout the command - refuses is said, and the wizard stays open. The window can be resized. Its steps are listed on - the left, and a click goes to one; a narrow screen leaves the list out, and the heading still - says which step this is. + Classic's doesn't; a click on the outline picks the style), the elements, the placement, the + texts (title, the active map's name until one is typed; subtitle, note and credit line, or none; + an Editorial sheet's column heading), the sources and reference (each one per line, with its + heading; the reference can be left out) and the accent colour, then shows what was picked; + **Create** makes the layout as the menu does. **Insert Statistic**, on the texts and sources + steps, adds a layer figure of the active map to the field the cursor was last in there (the note + or the sources, where it was in none). The map extent is the view, the features one layer shows + (hidden or not, in their longitude/latitude box) or the selected features (a point or a straight + line is widened to 0.01°, and what lies past ±180° or ±90° is left out of the frame; an area + with nothing to frame, one gone by Create, or one picked before the map or the project was + switched or the map renamed, is said and nothing is made); without a name the layout is + `Publication`; the review says when a layout has that name, so the new one is numbered. The + **elements** are what is drawn around the map: the locator (the default, named as what it will + 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 + 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. + A field left empty is left out (for the credit line, the reference and the headings, the + command's default applies); the title is the exception: empty, it means no title. A layout the + command refuses is said, and the wizard stays open. The window can be resized. Its steps are + listed on the left, and a click goes to one; a narrow screen leaves the list out, and the + heading still says which step this is. - **The map**: the `extent` given (or the view) fitted north-up, without tilt, at a round scale, two significant figures, rounded up so it still fits within the strips the graticule's labels take inside the frame. A graticule's step follows the extent (2° for a state, 15′ for a city),