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
8 changes: 8 additions & 0 deletions crates/map/src/layout/legend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
18 changes: 17 additions & 1 deletion crates/ui-egui/src/layoutview/format/legend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand All @@ -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 {
Expand Down Expand Up @@ -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}));
Expand Down
70 changes: 70 additions & 0 deletions crates/ui-egui/src/layoutview/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion docs/user-guide/layouts.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading