diff --git a/crates/map/src/layout/legend.rs b/crates/map/src/layout/legend.rs index a7e65f6454..23e6a09d96 100644 --- a/crates/map/src/layout/legend.rs +++ b/crates/map/src/layout/legend.rs @@ -210,6 +210,14 @@ pub enum LegendSizes { impl LegendSizes { pub const ALL: [LegendSizes; 2] = [LegendSizes::Rows, LegendSizes::Nested]; + /// What the Format pane calls it. + pub fn label(self) -> &'static str { + match self { + LegendSizes::Rows | LegendSizes::Invalid => "One row each", + LegendSizes::Nested => "Nested on one base", + } + } + pub fn code(self) -> &'static str { match self { LegendSizes::Rows | LegendSizes::Invalid => "rows", diff --git a/crates/ui-egui/src/layoutview/format/legend.rs b/crates/ui-egui/src/layoutview/format/legend.rs index 1cacd4ecea..e58d790d4d 100644 --- a/crates/ui-egui/src/layoutview/format/legend.rs +++ b/crates/ui-egui/src/layoutview/format/legend.rs @@ -5,7 +5,7 @@ use crate::RustGisApp; use crate::widgets::Dragged; use egui::{Ui, vec2}; use rustgis_engine::map::Drawn; -use rustgis_engine::map::layout::{Element, ElementKind, Layout, LegendFit, MAX_LEGEND_COLUMNS}; +use rustgis_engine::map::layout::{Element, ElementKind, Layout, LegendFit, LegendSizes, MAX_LEGEND_COLUMNS}; use rustgis_engine::render::layout::{class_row_labels, has_class_rows, legend_lists, legend_place}; use serde_json::{Value, json}; @@ -22,6 +22,7 @@ pub(super) fn legend_property_rows(app: &mut RustGisApp, ui: &mut Ui, li: usize, fit, show_layer_names, show_counts, + sizes, .. } = &e.kind else { @@ -108,6 +109,21 @@ pub(super) fn legend_property_rows(app: &mut RustGisApp, ui: &mut Ui, li: usize, update(app, json!({"showCounts": counts})); } ui.end_row(); + let input_label = ui.label(tl!("Sizes")); + let current = sizes.kept(); + egui::ComboBox::from_id_salt(("legend_sizes", id)) + .selected_text(tl!(current.label())) + .show_ui(ui, |ui| { + for v in LegendSizes::ALL { + if ui.selectable_label(current == v, tl!(v.label())).clicked() && current != v { + update(app, json!({"sizes": v.code()})); + } + } + }) + .response + .labelled_by(input_label.id) + .on_hover_text(tl!("How a point layer's marker sizes are drawn: a row each, or one inside another on a common base")); + ui.end_row(); // Its names' and labels' points; the title, rows and swatches follow (#2581). if let Some(pt) = text_size_row(ui, tl!("Text size"), drag_key("textSize"), *text_size) { update(app, json!({"textSize": pt})); diff --git a/crates/ui-egui/src/layoutview/tests.rs b/crates/ui-egui/src/layoutview/tests.rs index d73db7175f..270d0f6b4f 100644 --- a/crates/ui-egui/src/layoutview/tests.rs +++ b/crates/ui-egui/src/layoutview/tests.rs @@ -2792,6 +2792,76 @@ fn a_legends_fit_and_layer_names_are_one_undo_step_each() { assert_eq!(set(h.state()), (LegendFit::AdjustColumnsAndSize, LayerNames::Hidden, 1), "one step undoes the columns alone"); } +/// A legend's Sizes in the Format pane: the value the legend has, set by a command or read from a +/// file, shown without sending anything, each change one undo step and picking the current one none. +#[test] +fn a_legends_sizes_are_picked_in_the_format_pane() { + use egui::accesskit::Role; + use egui_kittest::kittest::Queryable; + use rustgis_engine::map::layout::{ElementKind, LegendSizes}; + let mut app = RustGisApp::with_sample(); + app.run("layout.new", json!({"name": "Key", "template": "map"})).unwrap(); + let li = app.session.active_layout.unwrap(); + let legend = app.session.project.layouts[li].elements.iter().find(|e| matches!(e.kind, ElementKind::Legend { .. })).unwrap().id; + app.run("layout.update", json!({"element": legend, "sizes": "nested"})).unwrap(); + app.layout.selected = Some(legend); + let set = |app: &RustGisApp| match &app.session.project.layouts[li].element(legend).unwrap().kind { + ElementKind::Legend { sizes, .. } => *sizes, + other => panic!("{other:?}"), + }; + let mut fonts = false; + let mut h = egui_kittest::Harness::builder().with_size(vec2(1200.0, 900.0)).build_ui_state( + move |ui, app: &mut RustGisApp| { + if !fonts { + crate::theme::install_fonts(ui.ctx(), &[], None); + fonts = true; + return; + } + with_format(app, ui); + }, + app, + ); + let depth = h.state().session.undo_depth(); + h.run_steps(3); + let shown = |h: &egui_kittest::Harness<'_, RustGisApp>| h.get_by_role_and_label(Role::ComboBox, "Sizes").value(); + assert_eq!(h.state().session.undo_depth(), depth, "opening the pane changed nothing"); + assert_eq!(shown(&h).as_deref(), Some("Nested on one base")); + let pick = |h: &mut egui_kittest::Harness<'_, RustGisApp>, item: &str| { + h.get_by_role_and_label(Role::ComboBox, "Sizes").click(); + h.run_steps(2); + // The item, not the combo box showing the same words. + h.get_by_role_and_label(Role::Button, item).click(); + h.run_steps(3); + }; + pick(&mut h, "Nested on one base"); + assert_eq!(h.state().session.undo_depth(), depth, "the sizes already set are no step"); + pick(&mut h, "One row each"); + assert_eq!(set(h.state()), LegendSizes::Rows); + assert_eq!(h.state().session.undo_depth(), depth + 1, "one step"); + assert_eq!(shown(&h).as_deref(), Some("One row each")); + pick(&mut h, "One row each"); + assert_eq!(h.state().session.undo_depth(), depth + 1); + pick(&mut h, "Nested on one base"); + assert_eq!(set(h.state()), LegendSizes::Nested); + assert_eq!(h.state().session.undo_depth(), depth + 2); + h.state_mut().run("edit.undo", json!({})).unwrap(); + h.run_steps(3); + assert_eq!(set(h.state()), LegendSizes::Rows); + assert_eq!(shown(&h).as_deref(), Some("One row each")); + // A file's value that is not a name shows as the default, and picking the default sends nothing. + for e in &mut h.state_mut().session.project.layouts[li].elements { + if let ElementKind::Legend { sizes, .. } = &mut e.kind { + *sizes = LegendSizes::Invalid; + } + } + let depth = h.state().session.undo_depth(); + h.run_steps(3); + assert_eq!(shown(&h).as_deref(), Some("One row each")); + pick(&mut h, "One row each"); + assert_eq!(h.state().session.undo_depth(), depth); + assert_eq!(set(h.state()), LegendSizes::Invalid); +} + /// The layout view with the Format pane beside it, as the app draws them: after following /// what agents ran (`RustGisApp::logic`), and saving drafts at the end. fn with_format(app: &mut RustGisApp, ui: &mut egui::Ui) { diff --git a/docs/user-guide/layouts.md b/docs/user-guide/layouts.md index 170bad2a27..50b7681a8e 100644 --- a/docs/user-guide/layouts.md +++ b/docs/user-guide/layouts.md @@ -513,7 +513,7 @@ Layouts open as tabs next to the maps; while one is open, its groups lead the Pu line. The rows start under it, so a box holds one row less, which the fit and its warnings count; a fit shrinks the rows, not the subtitle. Like the title, a line wider than the box runs past it. `""` takes it away. - - **Sizes** (`"sizes"`, set with a command): how the legend draws the rows that show a point + - **Sizes** (`"sizes"`, picked in the Format pane or set with a command): how the legend draws the rows that show a point layer's marker sizes, those of Proportional Symbols and those a layer sized by a field lists after its classes. `"rows"`, the default, gives each its own row. `"nested"` draws a layer's as one block: the markers one inside another, the largest first, on a common base, each with a