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
4 changes: 2 additions & 2 deletions crates/ui-egui/src/layoutview/format/legend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ pub(super) fn legend_layers(app: &mut RustGisApp, ui: &mut Ui, layout: &Layout,
let unlisted: Vec<&String> = layer_order.iter().filter(|x| on_map(x) && !names.iter().any(|n| n.eq_ignore_ascii_case(x))).collect();
// What a row or button asks for, sent once the map is no longer read.
let mut change = None;
// With none to list, still there to drop the legend's own order.
if !names.is_empty() || !layer_order.is_empty() {
// With none to list, still there to reset the legend's own order or the names left out.
if !names.is_empty() || !layer_order.is_empty() || !kept.is_empty() {
ui.add_space(4.0);
let open = !exclude.is_empty() || !layer_order.is_empty();
// By layout too, as element ids repeat: the section's rows, scroll and open classes
Expand Down
37 changes: 27 additions & 10 deletions crates/ui-egui/src/layoutview/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2316,16 +2316,39 @@ fn a_legends_layers_section_opens_in_the_legends_order() {
assert!(ordered.iter().position(|n| n == "Rivers") == Some(1), "{ordered:?}");
}

/// An order of its own can be dropped in the pane though no layer it names is listed there.
/// An order of its own, or a layer left out, can be reset in the pane though the legend lists no
/// layer there (#3321). A left-out name the map no longer has brings no section up.
#[test]
fn a_legend_listing_no_layer_still_goes_back_to_the_maps_order() {
fn a_legend_listing_no_layer_can_still_be_reset() {
use egui_kittest::kittest::Queryable;
for params in [json!({"layerOrder": ["Rivers"]}), json!({"exclude": ["Rivers"]})] {
let (mut h, li, legend) = a_legend_listing_no_layer(&params, None);
assert!(h.query_by_label("Select All").is_none(), "{params}");
h.get_by_label("Reset").click();
h.run_steps(3);
assert_eq!(legend_listing(&h, li, legend), (Vec::new(), Vec::new()), "{params}");
assert!(h.query_by_label("Layers").is_none(), "nothing left to list: {params}");
}
let (h, li, legend) = a_legend_listing_no_layer(&json!({}), Some("Gone"));
assert_eq!(legend_listing(&h, li, legend).0, ["Gone"]);
assert!(h.query_by_label("Layers").is_none() && h.query_by_label("Reset").is_none(), "nothing to reset");
}

/// A legend set to `params` whose map's layers it can't list, selected in the Format pane, leaving
/// out `gone` too: a name the map doesn't have, which only a file can hold, as `layout.update`
/// refuses it.
fn a_legend_listing_no_layer(params: &serde_json::Value, gone: Option<&str>) -> (egui_kittest::Harness<'static, RustGisApp>, usize, u32) {
use rustgis_engine::map::layout::ElementKind;
let mut app = RustGisApp::with_sample();
app.run("layout.new", json!({"name": "Legend"})).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, "layerOrder": ["Rivers"]})).unwrap();
let mut p = params.clone();
p["element"] = json!(legend);
app.run("layout.update", p).unwrap();
let element = app.session.project.layouts[li].element_mut(legend).unwrap();
let ElementKind::Legend { exclude, .. } = &mut element.kind else { panic!("a legend") };
exclude.extend(gone.map(String::from));
for l in &mut app.session.map_mut().layers {
l.graphics = true;
}
Expand All @@ -2343,13 +2366,7 @@ fn a_legend_listing_no_layer_still_goes_back_to_the_maps_order() {
app,
);
h.run_steps(3);
h.get_by_label("Reset").click();
h.run_steps(3);
match &h.state().session.project.layouts[li].element(legend).unwrap().kind {
ElementKind::Legend { layer_order, .. } => assert!(layer_order.is_empty(), "{layer_order:?}"),
_ => panic!("a legend"),
}
assert!(h.query_by_label("Layers").is_none(), "nothing left to list");
(h, li, legend)
}

/// A legend of the sample's layers and `extra` copies, "Extra 000" on, with its Layers section
Expand Down
Loading