diff --git a/crates/render/src/layout/legend.rs b/crates/render/src/layout/legend.rs index f16b8f6026..d20d5e24d0 100644 --- a/crates/render/src/layout/legend.rs +++ b/crates/render/src/layout/legend.rs @@ -999,6 +999,23 @@ pub fn class_row_labels(l: &rustgis_map::Layer) -> Vec { entries.into_iter().map(|e| e.label).collect() } +/// Whether [`class_row_labels`] lists any row for a layer, without making a classed layer's rows: +/// asked for every row of a legend's Layers section on every frame (#3306), where making a Unique +/// Values layer's would sort and merge all its classes. A raster's are made, few and from kept +/// statistics. +pub fn has_class_rows(l: &rustgis_map::Layer) -> bool { + if !legend_lists(l) { + return false; + } + if l.is_raster() { + return !every_class(l).is_empty(); + } + // Every renderer but a single symbol lists a row, even with no class: Unique Values its + // fallback, Proportional its sizes, Graduated Colors its "No data". + let classed = !matches!(l.renderer, rustgis_map::Renderer::Single(_)); + classed || !l.with_size_legend(Vec::new()).is_empty() || l.diagram.as_ref().is_some_and(|d| !d.categories.is_empty()) +} + /// The rows of the legend of a frame's map. With `drawn` (from [`shown_legends`]) it shows what the /// frame draws: only the layers listed there, with their classes. Without, every class of every /// visible layer. `opts` leaves out `` and the layers it names, either way, and diff --git a/crates/render/src/layout/tests.rs b/crates/render/src/layout/tests.rs index ecac96ea32..c76bc1596e 100644 --- a/crates/render/src/layout/tests.rs +++ b/crates/render/src/layout/tests.rs @@ -8406,6 +8406,41 @@ fn a_legend_labels_a_layers_classes_itself() { }; assert_eq!(labels_of(&legend_rows(&map, None, &opts(&listed, false))), ["c0", "c1", "c99"]); assert_eq!(class_row_labels(&map.layers[0]), ["c0", "c1", "c99"]); + for l in &map.layers { + assert_eq!(has_class_rows(l), !class_row_labels(l).is_empty(), "{}", l.name); + } + // Graduated Colors with no class, as an imported style can bring: its "No data" row is one. + let mut empty = rows_map(1); + let l = &mut empty.layers[0]; + l.renderer = rustgis_map::Renderer::Graduated { + field: "g".into(), + breaks: Vec::new(), + symbols: Vec::new(), + ramp: rustgis_map::Ramp::Ember, + method: rustgis_map::ClassMethod::NaturalBreaks, + min: 0.0, + classes: 0, + class_labels: Default::default(), + class_strokes: Default::default(), + class_fills: Default::default(), + }; + assert_eq!(class_row_labels(l), ["No data"]); + assert!(has_class_rows(l)); + // One symbol: no row of its own until a diagram brings its categories. + l.renderer = rustgis_map::Renderer::Single(rustgis_map::Symbol::default_for(GeometryType::Point, 0)); + assert!(class_row_labels(l).is_empty() && !has_class_rows(l)); + l.diagram = Some(rustgis_map::DiagramSettings { + kind: rustgis_map::DiagramKind::Pie, + categories: vec![rustgis_map::DiagramCategory { field: "g".into(), colour: Rgba::rgb(255, 0, 0) }], + size: rustgis_map::DiagramSize::Fixed(12.0), + start_angle: 0.0, + background: None, + stroke: rustgis_map::DiagramSettings::default_stroke(), + stroke_width: 0.75, + labels: rustgis_map::DiagramLabel::None, + }); + assert_eq!(class_row_labels(l), ["g"]); + assert!(has_class_rows(l)); let mut own = ClassLabels::default(); own.by_layer.insert( "PTS".into(), diff --git a/crates/ui-egui/src/layoutview/format/legend.rs b/crates/ui-egui/src/layoutview/format/legend.rs index e70791a439..7ffe7c36e8 100644 --- a/crates/ui-egui/src/layoutview/format/legend.rs +++ b/crates/ui-egui/src/layoutview/format/legend.rs @@ -6,7 +6,7 @@ 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::render::layout::{legend_lists, legend_place}; +use rustgis_engine::render::layout::{class_row_labels, has_class_rows, legend_lists, legend_place}; use serde_json::{Value, json}; /// A legend's rows in the grid. @@ -99,13 +99,26 @@ pub(super) fn legend_property_rows(app: &mut RustGisApp, ui: &mut Ui, li: usize, } } +/// Over this many layers, a legend's Layers section has a box that filters them by name. +const FILTER_OVER: usize = 8; + +/// The height its rows scroll in, in points. +const LAYERS_HEIGHT: f32 = 320.0; + +/// `text` as the Layers filter compares it: lower case a character at a time, as +/// `str::to_lowercase` turns a capital sigma into one letter or another by its place, and the final +/// sigma as the other. +fn folded(text: &str) -> String { + text.chars().flat_map(char::to_lowercase).map(|c| if c == 'ς' { 'σ' } else { c }).collect() +} + /// The layers a legend lists, below the grid. pub(super) fn legend_layers(app: &mut RustGisApp, ui: &mut Ui, layout: &Layout, e: &Element, update: &dyn Fn(&mut RustGisApp, Value)) { let id = e.id; // The layers a legend lists: a checkbox for each vector layer of its frame's map, each raster // drawn by classes (#1679) and each WMS or WMTS layer with a legend, ticked when listed. Names // gone from the map drop out of the list as it's written back. - if let ElementKind::Legend { frame, exclude, layer_order, .. } = &e.kind { + if let ElementKind::Legend { frame, exclude, layer_order, class_labels, .. } = &e.kind { let map = layout.element(*frame).and_then(|f| match &f.kind { ElementKind::MapFrame { map, .. } => app.session.project.maps.iter().find(|m| m.name.eq_ignore_ascii_case(map)), _ => None, @@ -136,61 +149,136 @@ pub(super) fn legend_layers(app: &mut RustGisApp, ui: &mut Ui, layout: &Layout, let kept: Vec = exclude.iter().filter(|x| on_map(x)).cloned().collect(); // The same for the names ordered that aren't listed here. 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() { ui.add_space(4.0); let open = !exclude.is_empty() || !layer_order.is_empty(); - egui::CollapsingHeader::new(tl!("Layers")).id_salt(("legend_layers", id)).default_open(open).show(ui, |ui| { + // By layout too, as element ids repeat: the section's rows, scroll and open classes + // take their ids from it. + egui::CollapsingHeader::new(tl!("Layers")).id_salt(("legend_layers", &layout.name, id)).default_open(open).show(ui, |ui| { let left_out = |n: &str| exclude.iter().any(|x| x.eq_ignore_ascii_case(n)); - // The place a row moves with, up or down. + // The filter is the view's, not the project's: kept by egui, and read only while + // its box shows, so a list grown short again hides nothing. + let mut needle = String::new(); + if names.len() > FILTER_OVER { + // By layout too: element ids repeat from one to another. + let key = egui::Id::unique(("legend_layers_filter", &layout.name, id)); + let mut text = ui.data(|d| d.get_temp::(key)).unwrap_or_default(); + let r = ui.add(egui::TextEdit::singleline(&mut text).hint_text(tl!("Filter layers")).desired_width(f32::INFINITY)); + // Named once typed in too, when its hint is gone. + r.widget_info(|| egui::WidgetInfo::labeled(egui::Role::TextInput, true, tl!("Filter layers"))); + needle = folded(text.trim()); + ui.data_mut(|d| d.insert_temp(key, text)); + } + // The places in `names` of the rows shown. + let shown: Vec = names.iter().enumerate().filter(|(_, n)| folded(n).contains(&needle)).map(|(i, _)| i).collect(); + if !needle.is_empty() && shown.is_empty() { + ui.label(tl!("No layers match your search.")); + } + // The places a row swaps with the one shown above or below it. let mut swap = None; - for (i, n) in names.iter().enumerate() { - // Ids from the layer, not the row's place (`push_id` would mix it in), so the - // keyboard's focus moves with its layer. - let row_id = ui.make_persistent_id(n.to_ascii_lowercase()); - ui.scope_builder(egui::UiBuilder::new().scope_id(row_id), |ui| { - // The arrows on the right, the name in what they leave. - let row = vec2(ui.available_width(), ui.spacing().interact_size.y); - ui.allocate_ui_with_layout(row, egui::Layout::right_to_left(egui::Align::Center), |ui| { - // Named for its layer, so each row's arrows tell apart to a screen reader. - let arrow = |ui: &mut Ui, glyph: &str, on: bool, hover: &str, label: String| { - let r = ui.add_enabled(on, egui::Button::new(glyph).small()); - r.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Button, on, &label)); - r.on_hover_text(hover).clicked() - }; - let args = [("name", n.as_str())]; - if arrow(ui, "▼", i + 1 < names.len(), tl!("Move down"), crate::i18n::fmt("Move {name} down", &args)) { - swap = Some((i, i + 1)); - } - if arrow(ui, "▲", i > 0, tl!("Move up"), crate::i18n::fmt("Move {name} up", &args)) { - swap = Some((i - 1, i)); - } - ui.with_layout(egui::Layout::left_to_right(egui::Align::Center), |ui| { - ui.style_mut().wrap_mode = Some(egui::TextWrapMode::Truncate); - let mut listed = !left_out(n); - if ui.checkbox(&mut listed, n.as_str()).on_hover_text(tl!("List this layer in the legend")).changed() { - let mut next: Vec<&String> = kept.iter().filter(|x| !x.eq_ignore_ascii_case(n)).collect(); - if !listed { - next.push(n); + // A bar beside the rows, not floating over their arrows. + ui.scope(|ui| { + ui.spacing_mut().scroll = egui::style::ScrollStyle::solid(); + egui::ScrollArea::vertical() + .id_salt(("legend_layers_scroll", id)) + .max_height(LAYERS_HEIGHT) + .auto_shrink([false, true]) + .show(ui, |ui| { + for (k, (i, n)) in shown.iter().filter_map(|&i| names.get(i).map(|n| (i, n))).enumerate() { + let above = k.checked_sub(1).and_then(|k| shown.get(k)).copied(); + let below = shown.get(k + 1).copied(); + // The map's layers of this name: a web layer has no classes. + let layers = || map.into_iter().flat_map(|m| &m.layers).filter(|l| l.name.eq_ignore_ascii_case(n)); + let classed = layers().any(has_class_rows); + // Ids from the layer, not the row's place (`push_id` would mix it in), so + // the keyboard's focus and the row's expansion move with its layer. + let row_id = ui.make_persistent_id(n.to_ascii_lowercase()); + ui.scope_builder(egui::UiBuilder::new().scope_id(row_id), |ui| { + let mut classes = egui::collapsing_header::CollapsingState::load_with_default_open( + ui.ctx(), + row_id.with("classes"), + false, + ); + // The arrows on the right, the name in what they leave. + let row = vec2(ui.available_width(), ui.spacing().interact_size.y); + ui.allocate_ui_with_layout(row, egui::Layout::right_to_left(egui::Align::Center), |ui| { + // Named for its layer, so each row's arrows tell apart to a screen reader. + let arrow = |ui: &mut Ui, glyph: &str, on: bool, hover: &str, label: String| { + let r = ui.add_enabled(on, egui::Button::new(glyph).small()); + r.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Button, on, &label)); + r.on_hover_text(hover).clicked() + }; + let args = [("name", n.as_str())]; + if arrow(ui, "▼", below.is_some(), tl!("Move down"), crate::i18n::fmt("Move {name} down", &args)) + { + swap = below.map(|j| (i, j)); + } + if arrow(ui, "▲", above.is_some(), tl!("Move up"), crate::i18n::fmt("Move {name} up", &args)) { + swap = above.map(|j| (j, i)); + } + ui.with_layout(egui::Layout::left_to_right(egui::Align::Center), |ui| { + ui.style_mut().wrap_mode = Some(egui::TextWrapMode::Truncate); + let open = classes.is_open(); + let (glyph, hover, label) = if open { + ("▾", tl!("Hide classes"), crate::i18n::fmt("Hide the classes of {name}", &args)) + } else { + ("▸", tl!("Show classes"), crate::i18n::fmt("Show the classes of {name}", &args)) + }; + // Drawn unseen without classes, so the checkboxes line up. + let toggle = ui.add_visible(classed, egui::Button::new(glyph).small().frame(false)); + if classed { + toggle.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Button, true, &label)); + if toggle.on_hover_text(hover).clicked() { + classes.toggle(ui); + } + } + let mut listed = !left_out(n); + if ui + .checkbox(&mut listed, n.as_str()) + .on_hover_text(tl!("List this layer in the legend")) + .changed() + { + let mut next: Vec<&String> = kept.iter().filter(|x| !x.eq_ignore_ascii_case(n)).collect(); + if !listed { + next.push(n); + } + change = Some(json!({"exclude": next})); + } + }); + }); + if classed && classes.is_open() { + // As the legend labels them: its own text for a class, else the layer's. + let own = class_labels.of(n); + ui.indent("classes", |ui| { + ui.style_mut().wrap_mode = Some(egui::TextWrapMode::Truncate); + for label in layers().flat_map(class_row_labels) { + ui.label(own.and_then(|o| o.get(&label)).unwrap_or(&label)); + } + }); } - update(app, json!({"exclude": next})); - } - }); + classes.store(ui.ctx()); + }); + } }); - }); - } + }); if let Some((a, b)) = swap { let mut next: Vec<&String> = names.iter().collect(); next.swap(a, b); // Those ordered but not listed stay ordered, after these. next.extend(&unlisted); - update(app, json!({"layerOrder": next})); + change = Some(json!({"layerOrder": next})); } if !layer_order.is_empty() && ui.button(tl!("Map order")).on_hover_text(tl!("List the layers in the map's order")).clicked() { - update(app, json!({"layerOrder": []})); + change = Some(json!({"layerOrder": []})); } }); } + if let Some(change) = change { + update(app, change); + } } } diff --git a/crates/ui-egui/src/layoutview/tests.rs b/crates/ui-egui/src/layoutview/tests.rs index a45e1b2d46..83bc3d8a94 100644 --- a/crates/ui-egui/src/layoutview/tests.rs +++ b/crates/ui-egui/src/layoutview/tests.rs @@ -2352,6 +2352,216 @@ fn a_legend_listing_no_layer_still_goes_back_to_the_maps_order() { assert!(h.query_by_label("Layers").is_none(), "nothing left to list"); } +/// A legend of the sample's layers and `extra` copies, "Extra 000" on, with its Layers section +/// open in the Format pane. +fn legend_tree(extra: u32, params: serde_json::Value) -> (egui_kittest::Harness<'static, RustGisApp>, usize, u32) { + use egui_kittest::kittest::Queryable; + let mut app = RustGisApp::with_sample(); + app.run("layer.symbology", json!({"layer": "Countries", "type": "unique", "field": "continent"})).unwrap(); + for i in 0..extra { + let mut copy = app.session.map().layers.iter().find(|l| l.name == "Cities").unwrap().clone(); + copy.id = 1000 + i; + copy.name = format!("Extra {i:03}"); + app.session.map_mut().layers.push(copy); + } + 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; + let mut p = params; + p["element"] = json!(legend); + app.run("layout.update", p).unwrap(); + app.layout.selected = Some(legend); + let mut fonts = false; + let mut h = egui_kittest::Harness::builder().with_size(vec2(1200.0, 1600.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, + ); + h.run_steps(3); + // An order or a layer left out opens it already. + if h.query_by_role_and_label(egui::accesskit::Role::CheckBox, "Rivers").is_none() { + h.get_by_label("Layers").click(); + h.run_steps(10); + } + (h, li, legend) +} + +/// The filter box of a legend's Layers section, if it shows one. +fn layer_filter<'a>(h: &'a egui_kittest::Harness<'_, RustGisApp>) -> Option> { + use egui_kittest::kittest::Queryable; + h.query_by_role_and_label(egui::accesskit::Role::TextInput, "Filter layers") +} + +/// Over eight layers, a legend's Layers section filters them by name, in any case; ▲ and ▼ then +/// swap a layer with the nearest one shown, and ticking keeps the hidden layers left out (#3306). +#[test] +fn a_legends_layers_are_filtered_by_name() { + use egui::accesskit::Role; + use egui_kittest::kittest::{NodeT, Queryable}; + let (h, ..) = legend_tree(4, json!({})); + assert!(h.query_by_role_and_label(Role::CheckBox, "Extra 003").is_some()); + assert!(layer_filter(&h).is_none(), "eight layers: none"); + + let (mut h, li, legend) = legend_tree(8, json!({"layerOrder": ["Rivers", "Cities", "Countries"], "exclude": ["Cities"]})); + let shown = |h: &egui_kittest::Harness<'_, RustGisApp>, n: &str| h.query_by_role_and_label(Role::CheckBox, n).is_some(); + let kept = |h: &egui_kittest::Harness<'_, RustGisApp>| match &h.state().session.project.layouts[li].element(legend).unwrap().kind { + ElementKind::Legend { exclude, layer_order, .. } => (exclude.clone(), layer_order.clone()), + _ => panic!("a legend"), + }; + let typed = |h: &mut egui_kittest::Harness<'_, RustGisApp>, text: &str| { + layer_filter(h).unwrap().focus(); + h.run_steps(2); + h.key_press_modifiers(Modifiers::COMMAND, Key::A); + h.key_press(Key::Backspace); + h.run_steps(2); + layer_filter(h).unwrap().type_text(text); + h.run_steps(3); + }; + // Spaces alone filter nothing out. + typed(&mut h, " "); + assert!(shown(&h, "Cities") && shown(&h, "Extra 007")); + typed(&mut h, "no such layer"); + assert!(!shown(&h, "Rivers")); + assert!(h.query_by_label("No layers match your search.").is_some()); + assert!(h.query_by_label("Map order").is_some()); + typed(&mut h, " RI "); + assert!(shown(&h, "Rivers") && shown(&h, "Countries")); + assert!(!shown(&h, "Cities") && !shown(&h, "Extra 000")); + assert!(h.query_by_label("No layers match your search.").is_none()); + let disabled = |h: &egui_kittest::Harness<'_, RustGisApp>, l: &str| h.get_by_label(l).accesskit_node().is_disabled(); + assert!(disabled(&h, "Move Rivers up"), "the first shown"); + assert!(disabled(&h, "Move Countries down"), "the last shown"); + // Up over the hidden Cities, which keeps its place. + let depth = h.state().session.undo_depth(); + h.get_by_label("Move Countries up").click(); + h.run_steps(3); + assert_eq!(kept(&h).1[..3], ["Countries", "Cities", "Rivers"]); + assert_eq!(h.state().session.undo_depth(), depth + 1); + h.get_by_label("Move Countries down").click(); + h.run_steps(3); + assert_eq!(kept(&h).1[..3], ["Rivers", "Cities", "Countries"]); + h.get_by_role_and_label(Role::CheckBox, "Rivers").click(); + h.run_steps(3); + assert_eq!(kept(&h).0, ["Cities", "Rivers"]); +} + +/// A layer drawn by classes expands to the classes as the legend labels them, and stays expanded +/// when moved; a layer drawn in one symbol has no arrow, nor a web layer (#3306). +#[test] +fn a_legends_layers_expand_to_their_classes() { + use egui_kittest::kittest::Queryable; + let (mut h, ..) = legend_tree(0, json!({})); + let mut web = rustgis_engine::map::TileLayer::new("Walls", rustgis_engine::map::TileKind::Raster, "https://h/{z}/{x}/{y}.png"); + web.legends = vec![Default::default()]; + h.state_mut().session.map_mut().tiles.push(web); + h.run_steps(3); + let countries = h.state().session.map().layers.iter().find(|l| l.name == "Countries").unwrap(); + let classes = rustgis_engine::render::layout::class_row_labels(countries); + assert!(classes.len() > 2, "{classes:?}"); + assert!(h.query_by_label("Show the classes of Countries").is_some()); + assert!(h.query_by_label("Show the classes of Cities").is_some(), "sized in proportion: it has rows"); + for none in ["Rivers", "Lakes", "Walls"] { + assert!(h.query_by_label(&format!("Show the classes of {none}")).is_none(), "{none}"); + } + assert!(h.query_by_label(&classes[0]).is_none(), "closed at first"); + let legend = h.state().layout.selected.unwrap(); + h.state_mut() + .run("layout.update", json!({"element": legend, "classLabels": {"Countries": {classes[0].clone(): "Renamed here"}}})) + .unwrap(); + h.run_steps(2); + h.get_by_label("Show the classes of Countries").click(); + h.run_steps(3); + assert!(h.query_by_label("Renamed here").is_some()); + assert!(h.query_by_label(&classes[0]).is_none(), "the legend's text in its place"); + let rows: Vec = classes[1..].iter().map(|c| h.get_by_label(c).rect().min.y).collect(); + assert!(rows.windows(2).all(|w| w[0] < w[1]), "in the legend's order: {classes:?}"); + let way = if h.query_by_label("Move Countries up").is_some_and(|n| !egui_kittest::kittest::NodeT::accesskit_node(&n).is_disabled()) { + "up" + } else { + "down" + }; + h.get_by_label(&format!("Move Countries {way}")).click(); + h.run_steps(3); + assert!(h.query_by_label("Hide the classes of Countries").is_some(), "still expanded in its new place"); + assert!(h.query_by_label("Renamed here").is_some()); + h.get_by_label("Hide the classes of Countries").click(); + h.run_steps(3); + assert!(h.query_by_label("Renamed here").is_none()); +} + +/// A hundred layers scroll in a box of their own, so what follows the list stays near (#3306). +#[test] +fn a_hundred_layers_scroll_in_the_legends_section() { + use egui::accesskit::Role; + use egui_kittest::kittest::Queryable; + let (mut h, ..) = legend_tree(100, json!({"layerOrder": ["Extra 000"]})); + let top = layer_filter(&h).unwrap().rect().max.y; + let below = h.get_by_label("Map order").rect().min.y; + assert!(below - top < 360.0, "{top} {below}"); + layer_filter(&h).unwrap().focus(); + h.run_steps(2); + layer_filter(&h).unwrap().type_text("extra 099"); + h.run_steps(3); + assert!(h.query_by_role_and_label(Role::CheckBox, "Extra 099").is_some()); + assert!(h.query_by_role_and_label(Role::CheckBox, "Extra 000").is_none()); + // Short again, the list has no box, and the text typed before hides nothing. + h.state_mut().session.map_mut().layers.retain(|l| !l.name.starts_with("Extra")); + h.run_steps(3); + assert!(layer_filter(&h).is_none()); + assert!(h.query_by_role_and_label(Role::CheckBox, "Rivers").is_some()); +} + +/// A filter typed and classes opened in one layout's legend leave another layout's alone (#3306). +#[test] +fn a_legends_layer_filter_is_its_layouts_own() { + use egui::accesskit::Role; + use egui_kittest::kittest::Queryable; + let (mut h, _, legend) = legend_tree(8, json!({"layerOrder": ["Rivers", "Countries"]})); + h.get_by_label("Show the classes of Countries").click(); + h.run_steps(3); + layer_filter(&h).unwrap().focus(); + h.run_steps(2); + layer_filter(&h).unwrap().type_text("riv"); + h.run_steps(3); + assert!(h.query_by_role_and_label(Role::CheckBox, "Lakes").is_none()); + h.state_mut().run("layout.new", json!({"name": "Other"})).unwrap(); + let li = h.state().session.active_layout.unwrap(); + let other = h.state().session.project.layouts[li].elements.iter().find(|e| matches!(e.kind, ElementKind::Legend { .. })).unwrap().id; + assert_eq!(other, legend, "the same element id in both"); + h.state_mut().run("layout.update", json!({"element": other, "layerOrder": ["Rivers", "Countries"]})).unwrap(); + h.state_mut().layout.selected = Some(other); + h.run_steps(10); + assert!(h.query_by_role_and_label(Role::CheckBox, "Lakes").is_some()); + assert!(h.query_by_label("Show the classes of Countries").is_some(), "and its classes closed"); +} + +/// The filter finds a name in any case, a Greek sigma too, whose lower case depends on its place +/// (#3306). +#[test] +fn a_legends_layer_filter_folds_a_final_sigma() { + use egui::accesskit::Role; + use egui_kittest::kittest::Queryable; + let (mut h, ..) = legend_tree(8, json!({"layerOrder": ["Rivers"]})); + h.state_mut().run("layer.rename", json!({"layer": "Lakes", "name": "ΟΔΟΣ"})).unwrap(); + for typed in ["Σ", "οδος", "οδοσ"] { + layer_filter(&h).unwrap().focus(); + h.run_steps(2); + h.key_press_modifiers(Modifiers::COMMAND, Key::A); + h.key_press(Key::Backspace); + h.run_steps(2); + layer_filter(&h).unwrap().type_text(typed); + h.run_steps(3); + assert!(h.query_by_role_and_label(Role::CheckBox, "ΟΔΟΣ").is_some(), "{typed}"); + assert!(h.query_by_role_and_label(Role::CheckBox, "Rivers").is_none(), "{typed}"); + } +} + /// A legend's Fit and Layer names in the Format pane: shown at their defaults on opening and /// sending nothing then, each change one undo step, picking the current fit none, and a column /// count past six set at six. diff --git a/docs/user-guide/layouts.md b/docs/user-guide/layouts.md index de182fb8f0..f186e040eb 100644 --- a/docs/user-guide/layouts.md +++ b/docs/user-guide/layouts.md @@ -546,7 +546,10 @@ Layouts open as tabs next to the maps; while one is open, its groups lead the Pu `"exclude": ["Graticule"]` on `layout.addElement` or `layout.update` (`[]` lists every layer again); a renamed layer stays left out. The section lists the layers in the order the legend draws them; ▲ and ▼ move one a place, each move one undo step, and **Map order** returns to - the map's order. + the map's order. The rows scroll in a box of their own, and over eight layers **Filter + layers** keeps those whose name contains the text, in any case; ▲ and ▼ then swap a layer + with the nearest one shown. The arrow beside a layer drawn by classes shows its classes as + the legend labels them, every one it can list, to read only. - **Layer order** (`"layerOrder"`, or ▲ and ▼ in the Layers section): a legend lists its layers as the map draws them, top first, unless it is given its own order: `layout.update {"element": 3, "layerOrder": ["Rivers", "Roads"]}` lists those layers first, in