Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/engine/src/cmd/layout/publication/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
16 changes: 7 additions & 9 deletions crates/engine/src/cmd/layout/publication/mosaic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -29,7 +27,7 @@ pub(super) struct Panel {
/// `"scale"` if it has them.
pub(super) fn publication_panels(s: &Session, p: &Value) -> Result<Option<Vec<Panel>>, 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::<Result<_, _>>().map(Some)
}

Expand All @@ -51,7 +49,7 @@ fn panel_of(s: &Session, i: usize, v: &Value) -> Result<Panel, String> {
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::<Vec<_>>().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)
}
};
Expand Down
13 changes: 12 additions & 1 deletion crates/engine/src/cmd/layout/publication/sheet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}";
Expand Down Expand Up @@ -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,
}
Expand Down
13 changes: 13 additions & 0 deletions crates/engine/src/tests/layout_publication_parts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
17 changes: 16 additions & 1 deletion crates/ui-egui/src/publicationwizard/elements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down
22 changes: 16 additions & 6 deletions crates/ui-egui/src/publicationwizard/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ fn held<'a>(s: &'a Session, area: &Area, coords: Option<&Coords>) -> Result<Held
}

/// Whether sides name an area: West less than East, and South less than North.
fn ordered([w, s, e, n]: [f64; 4]) -> bool {
pub(super) fn ordered([w, s, e, n]: [f64; 4]) -> bool {
w < e && s < n
}

Expand All @@ -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)]
}
Expand Down Expand Up @@ -243,11 +243,16 @@ fn number(text: &str) -> Option<f64> {

/// 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.
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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)]),
Expand Down Expand Up @@ -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;
}
Expand Down
44 changes: 41 additions & 3 deletions crates/ui-egui/src/publicationwizard/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ mod accent;
mod arrange;
mod elements;
mod map;
mod panels;
mod review;
mod size;
mod sources;
Expand All @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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<PanelDraft>,
/// 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,
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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]
}

Expand Down Expand Up @@ -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::<Vec<_>>());
}
p["title"] = json!(self.title.trim());
for (key, text) in [("subtitle", &self.subtitle), ("note", &self.note), ("author", &self.author)] {
if !text.trim().is_empty() {
Expand Down Expand Up @@ -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"
}
Expand Down Expand Up @@ -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"),
Expand All @@ -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"),
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -545,6 +579,9 @@ fn step_list(ui: &mut egui::Ui, d: &mut Draft, height: f32) -> Option<Step> {
/// resolves the area, which may walk a whole layer, so it runs only on those two.
fn create_params(s: &Session, d: &Draft) -> Result<Value, String> {
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 {
Expand Down Expand Up @@ -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()),
Expand Down
Loading
Loading