diff --git a/crates/ui-egui/src/layoutview/format.rs b/crates/ui-egui/src/layoutview/format.rs index afeb89b704..d90cc6e525 100644 --- a/crates/ui-egui/src/layoutview/format.rs +++ b/crates/ui-egui/src/layoutview/format.rs @@ -5,6 +5,7 @@ mod checklist; mod colorbar; mod frame; mod legend; +mod legend_breaks; mod north; mod picture; mod scalebar; diff --git a/crates/ui-egui/src/layoutview/format/checklist.rs b/crates/ui-egui/src/layoutview/format/checklist.rs index bc2b632273..0f3d365d69 100644 --- a/crates/ui-egui/src/layoutview/format/checklist.rs +++ b/crates/ui-egui/src/layoutview/format/checklist.rs @@ -22,6 +22,18 @@ pub(super) struct Row { pub(super) ticked: bool, /// Whether ▲ and ▼ move it, past other movable rows. pub(super) movable: bool, + /// A second check beside the arrows, where the section has one. + pub(super) mark: Option, +} + +/// A row's second check. Its texts come translated. +pub(super) struct Mark { + pub(super) on: bool, + /// What it's named for, apart from the row's own check. + pub(super) name: String, + pub(super) hover: &'static str, + /// Why it can't be changed, shown as its hover then. + pub(super) disabled: Option, } /// What the section says and allows. Its texts come translated. @@ -49,6 +61,8 @@ pub(super) enum Pick { Shown(Vec, bool), /// Two rows to change places, the upper first. Swap(usize, usize), + /// A row's second check ticked (true) or unticked. + Mark(usize, bool), Reset, } @@ -150,6 +164,15 @@ pub(super) fn checklist( if arrow(ui, "▲", above.is_some(), tl!("Move up"), crate::i18n::fmt("Move {name} up", &args)) { swap = above.map(|j| (j, i)); } + if let Some(m) = &row.mark { + let (free, mut on) = (m.disabled.is_none(), m.on); + let r = ui.add_enabled(free, egui::Checkbox::new(&mut on, "↵")); + r.widget_info(|| egui::WidgetInfo::selected(egui::Role::CheckBox, free, m.on, &m.name)); + if r.on_hover_text(m.hover).on_disabled_hover_text(m.disabled.as_deref().unwrap_or_default()).changed() + { + pick = Some(Pick::Mark(i, on)); + } + } ui.with_layout(egui::Layout::left_to_right(egui::Align::Center), |ui| { ui.style_mut().wrap_mode = Some(egui::TextWrapMode::Truncate); if let Some(d) = &details { @@ -226,7 +249,15 @@ mod tests { }; let rows = || { count.set(count.get() + 1); - vec![Row { name: "a".into(), key: "a".into(), text: "a".into(), also: String::new(), ticked: true, movable: true }] + vec![Row { + name: "a".into(), + key: "a".into(), + text: "a".into(), + also: String::new(), + ticked: true, + movable: true, + mark: None, + }] }; checklist(ui, &spec, rows, None); }); diff --git a/crates/ui-egui/src/layoutview/format/legend.rs b/crates/ui-egui/src/layoutview/format/legend.rs index db363fcde9..fa20ac7442 100644 --- a/crates/ui-egui/src/layoutview/format/legend.rs +++ b/crates/ui-egui/src/layoutview/format/legend.rs @@ -1,6 +1,7 @@ //! A legend's Format rows. -use super::checklist::{Details, Pick, Row, Spec, checklist}; +use super::checklist::{Details, Mark, Pick, Row, Spec, checklist}; +use super::legend_breaks::{break_change, break_mark}; use super::*; use crate::RustGisApp; use crate::widgets::Dragged; @@ -21,6 +22,7 @@ pub(super) fn legend_property_rows(app: &mut RustGisApp, ui: &mut Ui, li: usize, hide_other, show_no_data, columns, + column_breaks, text_size, fit, show_layer_names, @@ -65,21 +67,36 @@ pub(super) fn legend_property_rows(app: &mut RustGisApp, ui: &mut Ui, li: usize, let input_label = ui.label(tl!("Columns")); let mut n = *columns as u64; let drag = Dragged::lend(ui, drag_key("columns"), &mut n); + // Column breaks set the columns, so the command refuses these beside them (#3445). + let broken = !column_breaks.is_empty(); + let by_breaks = tl!("Set by the legend's column breaks"); let r = ui - .add(egui::DragValue::new(&mut n).update_while_editing(false).range(1..=MAX_LEGEND_COLUMNS as u64)) + .add_enabled(!broken, egui::DragValue::new(&mut n).update_while_editing(false).range(1..=MAX_LEGEND_COLUMNS as u64)) .labelled_by(input_label.id) - .on_hover_text(tl!("The columns its rows are laid in; a fit that adds columns starts from these")); + .on_hover_text(tl!("The columns its rows are laid in; a fit that adds columns starts from these")) + .on_disabled_hover_text(by_breaks); if drag.settled(ui, &r, &mut n) && n as usize != *columns { update(app, json!({"columns": n})); } ui.end_row(); + // Every break at once: one on a layer the legend no longer lists has no check of its own. + if broken { + ui.label(""); + let remove = ui.button(tl!("Remove Column Breaks")); + if remove.on_hover_text(tl!("Let the legend share its rows out among its columns again")).clicked() { + update(app, json!({"columnBreaks": []})); + } + ui.end_row(); + } let input_label = ui.label(tl!("Fit")); let current = fit.kept(); egui::ComboBox::from_id_salt(("legend_fit", id)) .selected_text(tl!(current.label())) .show_ui(ui, |ui| { for v in LegendFit::ALL { - if ui.selectable_label(current == v, tl!(v.label())).clicked() && current != v { + let adds = matches!(v, LegendFit::AdjustColumns | LegendFit::AdjustColumnsAndSize); + let row = egui::Button::selectable(current == v, tl!(v.label())); + if ui.add_enabled(!(broken && adds), row).on_disabled_hover_text(by_breaks).clicked() && current != v { update(app, json!({"fit": v.code()})); } } @@ -171,7 +188,7 @@ pub(super) fn legend_layers( // 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, column_breaks, columns, fit, .. } = &e.kind { let frame_map = layout.element(*frame).and_then(|f| match &f.kind { ElementKind::MapFrame { map, .. } => Some(map), _ => None, @@ -209,15 +226,34 @@ pub(super) fn legend_layers( // 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() { let left_out = |n: &str| exclude.iter().any(|x| x.eq_ignore_ascii_case(n)); + // The breaks the map still has, which a change writes back. + let breaks_kept: Vec = column_breaks.iter().filter(|x| on_map(x)).cloned().collect(); + let first = names.iter().position(|n| !left_out(n)); let rows = || { names .iter() - .map(|n| { + .enumerate() + .map(|(i, n)| { // By the legend's own text for it, still naming its layer: to a screen reader, // the keyboard and among equal texts. let own = legend_text(&e.kind, n, None); let text = if own.is_empty() || own == *n { n.clone() } else { format!("{own} ({n})") }; - Row { name: n.clone(), key: n.to_ascii_lowercase(), text, also: own, ticked: !left_out(n), movable: true } + let on = column_breaks.iter().any(|b| b.eq_ignore_ascii_case(n)); + let mark = Mark { + on, + name: crate::i18n::fmt("{name} starts a column", &[("name", n.as_str())]), + hover: tl!("Starts a column"), + disabled: break_mark(!left_out(n), first == Some(i), on, breaks_kept.len()), + }; + Row { + name: n.clone(), + key: n.to_ascii_lowercase(), + text, + also: own, + ticked: !left_out(n), + movable: true, + mark: Some(mark), + } }) .collect() }; @@ -307,6 +343,12 @@ pub(super) fn legend_layers( next.extend(&unlisted); json!({"layerOrder": next}) } + Pick::Mark(i, on) => { + let name = names.get(i).map_or("", String::as_str); + // Of the breaks, only those the map has are written back. + let has = |x: &str| breaks_kept.iter().any(|b| b == x); + break_change(&names, column_breaks, has, (*columns, *fit), name, on) + } Pick::Reset => json!({"exclude": [], "layerOrder": []}), }); } diff --git a/crates/ui-egui/src/layoutview/format/legend_breaks.rs b/crates/ui-egui/src/layoutview/format/legend_breaks.rs new file mode 100644 index 0000000000..70a62dfda7 --- /dev/null +++ b/crates/ui-egui/src/layoutview/format/legend_breaks.rs @@ -0,0 +1,111 @@ +//! What the Format pane sends for a legend's column breaks (#3445). + +use rustgis_engine::map::layout::{LegendFit, MAX_LEGEND_COLUMNS}; +use serde_json::{Value, json}; + +/// The `layout.update` that makes the layer `name` start a column (`on`) or stop. `drawn` are the +/// layers listed, in the order drawn; `breaks` the legend's own, kept for those the map still has. +/// Breaks set the columns, so with any left the same call takes `columns` to 1 and a fit that adds +/// columns to the one that doesn't: the command refuses them together, and one call is one undo. +pub(super) fn break_change( + drawn: &[String], + breaks: &[String], + on_map: impl Fn(&str) -> bool, + (columns, fit): (usize, LegendFit), + name: &str, + on: bool, +) -> Value { + let mut next: Vec<&String> = + drawn.iter().filter(|n| if n.eq_ignore_ascii_case(name) { on } else { breaks.iter().any(|b| b.eq_ignore_ascii_case(n)) }).collect(); + next.extend(breaks.iter().filter(|b| on_map(b) && !drawn.iter().any(|n| n.eq_ignore_ascii_case(b)))); + let mut change = json!({"columnBreaks": next}); + if !next.is_empty() { + if columns > 1 { + change["columns"] = json!(1); + } + let kept = match fit.kept() { + LegendFit::AdjustColumns => Some(LegendFit::Manual), + LegendFit::AdjustColumnsAndSize => Some(LegendFit::AdjustSize), + _ => None, + }; + if let Some(fit) = kept { + change["fit"] = json!(fit.code()); + } + } + change +} + +/// Why a layer's check can't be ticked, if it can't: a layer left out or the first listed starts +/// no column of its own, and `breaks` already set can fill the columns a legend has. A ticked one +/// is never disabled: its break can always come off, which frees Columns and the fits. +pub(super) fn break_mark(listed: bool, first: bool, on: bool, breaks: usize) -> Option { + if on { + None + } else if !listed { + Some(tl!("Not listed in the legend").into()) + } else if first { + Some(tl!("The first layer starts the first column").into()) + } else if breaks + 1 >= MAX_LEGEND_COLUMNS { + Some(crate::i18n::fmt("A legend has at most {max} columns", &[("max", &MAX_LEGEND_COLUMNS.to_string())])) + } else { + None + } +} + +#[cfg(test)] +mod tests { + use super::*; + + fn names(n: &[&str]) -> Vec { + n.iter().map(|n| n.to_string()).collect() + } + + fn change(breaks: &[&str], set: (usize, LegendFit), name: &str, on: bool) -> Value { + break_change(&names(&["A", "B", "C"]), &names(breaks), |n| n != "Gone", set, name, on) + } + + const PLAIN: (usize, LegendFit) = (1, LegendFit::Manual); + + #[test] + fn a_check_says_why_it_cant_be_ticked() { + let most = MAX_LEGEND_COLUMNS - 1; + assert_eq!(break_mark(true, false, false, most - 1), None); + let full = format!("A legend has at most {MAX_LEGEND_COLUMNS} columns"); + assert_eq!(break_mark(true, false, false, most), Some(full)); + assert_eq!(break_mark(false, false, false, 0).as_deref(), Some("Not listed in the legend")); + assert_eq!(break_mark(true, true, false, 0).as_deref(), Some("The first layer starts the first column")); + assert_eq!(break_mark(false, true, true, most), None, "a ticked one always comes off"); + } + + #[test] + fn breaks_go_in_the_order_drawn() { + assert_eq!(change(&[], PLAIN, "B", true), json!({"columnBreaks": ["B"]})); + assert_eq!(change(&["C"], PLAIN, "B", true), json!({"columnBreaks": ["B", "C"]})); + assert_eq!(change(&["B", "C"], PLAIN, "B", false), json!({"columnBreaks": ["C"]})); + } + + #[test] + fn the_layers_are_matched_by_name_in_any_case() { + assert_eq!(change(&["b"], PLAIN, "C", true), json!({"columnBreaks": ["B", "C"]})); + } + + #[test] + fn a_break_not_listed_is_kept_only_while_the_map_has_it() { + assert_eq!(change(&["Hidden", "Gone"], PLAIN, "B", true), json!({"columnBreaks": ["B", "Hidden"]})); + } + + #[test] + fn a_break_takes_columns_and_the_fit_with_it() { + use LegendFit::{AdjustColumns, AdjustColumnsAndSize, AdjustSize}; + assert_eq!(change(&[], (3, LegendFit::Manual), "B", true), json!({"columnBreaks": ["B"], "columns": 1})); + assert_eq!(change(&[], (1, AdjustColumns), "B", true), json!({"columnBreaks": ["B"], "fit": "manual"})); + assert_eq!(change(&[], (2, AdjustColumnsAndSize), "B", true), json!({"columnBreaks": ["B"], "columns": 1, "fit": "adjustSize"})); + assert_eq!(change(&[], (1, AdjustSize), "B", true), json!({"columnBreaks": ["B"]})); + } + + #[test] + fn taking_the_last_break_off_changes_nothing_else() { + // A file edited by hand can hold both. + assert_eq!(change(&["B"], (3, LegendFit::AdjustColumns), "B", false), json!({"columnBreaks": []})); + } +} diff --git a/crates/ui-egui/src/layoutview/format/table.rs b/crates/ui-egui/src/layoutview/format/table.rs index 4a06b834c7..3466c6d9c6 100644 --- a/crates/ui-egui/src/layoutview/format/table.rs +++ b/crates/ui-egui/src/layoutview/format/table.rs @@ -52,6 +52,7 @@ pub(super) fn table_columns(app: &mut RustGisApp, ui: &mut Ui, layout: &Layout, also: String::new(), ticked, movable: ticked, + mark: None, }; // Without a choice, every field in the layer's order. A chosen one keeps the name the // table stores, as it is drawn: one the layer has lost stays listed. @@ -97,6 +98,8 @@ pub(super) fn table_columns(app: &mut RustGisApp, ui: &mut Ui, layout: &Layout, Pick::Swap(a, b) if a < next.len() && b < next.len() => next.swap(a, b), Pick::Swap(..) => return, Pick::Reset => next.clear(), + // A table's rows have no second check. + Pick::Mark(..) => return, } // Every field in the layer's order is no choice: the table saves none. if next.iter().copied().eq(all()) { diff --git a/crates/ui-egui/src/layoutview/tests.rs b/crates/ui-egui/src/layoutview/tests.rs index 7a563e0d3e..8c108427fd 100644 --- a/crates/ui-egui/src/layoutview/tests.rs +++ b/crates/ui-egui/src/layoutview/tests.rs @@ -4202,3 +4202,255 @@ fn a_chart_keeps_automatic_maximum_when_its_series_cannot_be_read() { h.run_steps(3); assert!(maximum(&h).is_some_and(|n| n > 100.0), "complete data supplies its actual reach"); } + +/// With column breaks set, the Format pane's Columns box and the fits that add columns are +/// disabled, as the command refuses them (#3445); the other fits stay pickable. +#[test] +fn a_legends_column_breaks_disable_columns_and_the_fits_that_add_them() { + use egui::accesskit::Role; + use egui_kittest::kittest::{NodeT, Queryable}; + use rustgis_engine::map::layout::ElementKind; + 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.layout.selected = Some(legend); + 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 disabled = |h: &mut egui_kittest::Harness<'_, RustGisApp>| { + h.run_steps(3); + let columns = h.get_by_role_and_label(Role::SpinButton, "Columns").accesskit_node().is_disabled(); + h.get_by_role_and_label(Role::ComboBox, "Fit").click(); + h.run_steps(2); + let fits = ["Manual", "Shrink the text", "Add columns", "Add columns, then shrink the text"] + // The combo shows the current fit's text too: the last of the two is its row. + .map(|item| h.query_all_by_label(item).last().unwrap().accesskit_node().is_disabled()); + h.key_press(egui::Key::Escape); + h.run_steps(3); + (columns, fits) + }; + assert_eq!(disabled(&mut h), (false, [false; 4]), "without breaks, as ever"); + h.state_mut().run("layout.update", json!({"element": legend, "columnBreaks": ["Rivers"]})).unwrap(); + let depth = h.state().session.undo_depth(); + assert_eq!(disabled(&mut h), (true, [false, false, true, true])); + assert_eq!(h.state().session.undo_depth(), depth, "showing them sends nothing"); + h.state_mut().run("layout.update", json!({"element": legend, "columnBreaks": []})).unwrap(); + assert_eq!(disabled(&mut h), (false, [false; 4]), "the breaks taken off"); +} + +/// The sample's layers, as a legend draws them, with `more` copies of the first to reach past the +/// column limit, and its legend selected in the Format pane with the Layers section open. +fn a_legend_to_break(more: usize) -> (egui_kittest::Harness<'static, RustGisApp>, usize, u32, Vec) { + use egui_kittest::kittest::Queryable; + use rustgis_engine::map::Drawn; + use rustgis_engine::map::layout::ElementKind; + 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; + for i in 0..more { + let mut layer = app.session.map().layers[0].clone(); + layer.name = format!("Copy {i}"); + app.session.map_mut().layers.push(layer); + } + let map = app.session.map(); + let drawn: Vec = map + .stack() + .into_iter() + .map(|d| match d { + Drawn::Layer(i) => map.layers[i].name.clone(), + Drawn::Tile(i) => map.tiles[i].name.clone(), + }) + .collect(); + app.layout.selected = Some(legend); + let mut fonts = false; + let mut h = egui_kittest::Harness::builder().with_size(vec2(1200.0, 1400.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); + h.get_by_label("Layers").click(); + h.run_steps(10); + (h, li, legend, drawn) +} + +/// A legend's column breaks, columns and fit. +fn legend_breaks( + h: &egui_kittest::Harness<'_, RustGisApp>, + li: usize, + legend: u32, +) -> (Vec, usize, rustgis_engine::map::layout::LegendFit) { + match &h.state().session.project.layouts[li].element(legend).unwrap().kind { + rustgis_engine::map::layout::ElementKind::Legend { column_breaks, columns, fit, .. } => (column_breaks.clone(), *columns, *fit), + other => panic!("{other:?}"), + } +} + +/// The «starts a column» check of `name`: whether it's ticked, and whether it's disabled. +fn break_check(h: &egui_kittest::Harness<'_, RustGisApp>, name: &str) -> (bool, bool) { + use egui::accesskit::{Role, Toggled}; + use egui_kittest::kittest::{NodeT, Queryable}; + let label = format!("{name} starts a column"); + let node = h.get_by_role_and_label(Role::CheckBox, &label); + let node = node.accesskit_node(); + (node.toggled() == Some(Toggled::True), node.is_disabled()) +} + +fn press_break(h: &mut egui_kittest::Harness<'_, RustGisApp>, name: &str) { + use egui::accesskit::Role; + use egui_kittest::kittest::Queryable; + h.get_by_role_and_label(Role::CheckBox, &format!("{name} starts a column")).click(); + h.run_steps(3); +} + +/// Each layer's check in the Layers section starts a column at it, or stops, in one undo step, the +/// breaks written in the order drawn (#3445). Opening and filtering send nothing. +#[test] +fn a_legends_layers_start_columns_from_the_format_pane() { + let (mut h, li, legend, drawn) = a_legend_to_break(0); + let depth = h.state().session.undo_depth(); + for name in &drawn { + assert_eq!(break_check(&h, name), (false, name == &drawn[0]), "{name}"); + } + assert_eq!(h.state().session.undo_depth(), depth, "opening sends nothing"); + press_break(&mut h, &drawn[2]); + assert_eq!(legend_breaks(&h, li, legend).0, [drawn[2].clone()]); + assert_eq!(h.state().session.undo_depth(), depth + 1); + press_break(&mut h, &drawn[1]); + assert_eq!(legend_breaks(&h, li, legend).0, drawn[1..3]); + assert_eq!(break_check(&h, &drawn[1]), (true, false)); + press_break(&mut h, &drawn[1]); + assert_eq!(legend_breaks(&h, li, legend).0, [drawn[2].clone()]); + press_break(&mut h, &drawn[2]); + assert!(legend_breaks(&h, li, legend).0.is_empty()); + assert_eq!(h.state().session.undo_depth(), depth + 4); + h.state_mut().run("edit.undo", json!({})).unwrap(); + h.run_steps(3); + assert_eq!(break_check(&h, &drawn[2]), (true, false), "undone"); +} + +/// The first break takes the columns and a fit that adds them with it, in the one step. +#[test] +fn a_legends_first_break_takes_its_columns_and_fit_in_one_step() { + use rustgis_engine::map::layout::LegendFit; + for (fit, kept) in [("adjustColumns", LegendFit::Manual), ("adjustColumnsAndSize", LegendFit::AdjustSize)] { + let (mut h, li, legend, drawn) = a_legend_to_break(0); + h.state_mut().run("layout.update", json!({"element": legend, "columns": 3, "fit": fit})).unwrap(); + h.run_steps(3); + let before = legend_breaks(&h, li, legend); + let depth = h.state().session.undo_depth(); + press_break(&mut h, &drawn[1]); + assert_eq!(legend_breaks(&h, li, legend), (vec![drawn[1].clone()], 1, kept), "{fit}"); + assert_eq!(h.state().session.undo_depth(), depth + 1, "{fit}"); + h.state_mut().run("edit.undo", json!({})).unwrap(); + h.run_steps(3); + assert_eq!(legend_breaks(&h, li, legend), before, "{fit}"); + } +} + +/// The unticked checks that can't start a column are disabled: a layer left out, the first listed, +/// and the rest once five hold a break. A break goes with its layer as it moves, one already set can +/// always come off, and Reset leaves them. +#[test] +fn a_legends_break_checks_are_disabled_where_no_column_can_start() { + use egui::accesskit::Role; + use egui_kittest::kittest::Queryable; + let (mut h, li, legend, drawn) = a_legend_to_break(4); + assert!(drawn.len() >= 7, "{drawn:?}"); + // The top layer left out: the next is the first listed. + h.get_by_role_and_label(Role::CheckBox, &drawn[0]).click(); + h.run_steps(3); + assert_eq!(break_check(&h, &drawn[0]), (false, true), "left out"); + assert_eq!(break_check(&h, &drawn[1]), (false, true), "first listed"); + for name in &drawn[2..7] { + press_break(&mut h, name); + } + assert_eq!(legend_breaks(&h, li, legend).0, drawn[2..7]); + h.get_by_role_and_label(Role::CheckBox, &drawn[0]).click(); + h.run_steps(3); + assert_eq!(break_check(&h, &drawn[1]), (false, true), "at the limit"); + assert_eq!(break_check(&h, &drawn[2]), (true, false), "one set can be taken off"); + // Moved to the top, a layer keeps its break and its check is disabled. + for _ in 0..2 { + h.get_by_label(&format!("Move {} up", drawn[2])).click(); + h.run_steps(3); + } + assert_eq!(break_check(&h, &drawn[2]), (true, false), "first, its break kept"); + // Left out, it keeps its break too, still to be taken off. + h.get_by_role_and_label(Role::CheckBox, &drawn[3]).click(); + h.run_steps(3); + assert_eq!(break_check(&h, &drawn[3]), (true, false), "left out, its break kept"); + h.get_by_label("Reset").click(); + h.run_steps(3); + assert_eq!(legend_breaks(&h, li, legend).0.len(), 5, "Reset leaves the breaks"); + for _ in 0..2 { + h.get_by_label(&format!("Move {} up", drawn[2])).click(); + h.run_steps(3); + } + press_break(&mut h, &drawn[2]); + assert_eq!(legend_breaks(&h, li, legend).0, drawn[3..7]); + assert_eq!(break_check(&h, &drawn[2]), (false, true), "off, the first starts none again"); +} + +/// Under a filter, a check keeps the breaks of the rows hidden. +#[test] +fn a_legends_break_under_a_filter_keeps_the_hidden_ones() { + use egui::accesskit::Role; + use egui_kittest::kittest::Queryable; + let (mut h, li, legend, drawn) = a_legend_to_break(8); + press_break(&mut h, &drawn[1]); + let depth = h.state().session.undo_depth(); + let filter = h.get_by_role_and_label(Role::TextInput, "Filter layers"); + filter.focus(); + h.run_steps(2); + h.get_by_role_and_label(Role::TextInput, "Filter layers").type_text(&drawn[2]); + h.run_steps(3); + assert!(h.query_by_role_and_label(Role::CheckBox, &format!("{} starts a column", drawn[1])).is_none()); + assert_eq!(h.state().session.undo_depth(), depth, "filtering sends nothing"); + press_break(&mut h, &drawn[2]); + assert_eq!(legend_breaks(&h, li, legend).0, drawn[1..3]); +} + +/// Remove Column Breaks, beside the disabled Columns box, clears every break in one step, one on a +/// layer with no row of its own too; without breaks there is no button. +#[test] +fn a_legends_column_breaks_are_all_removed_from_the_pane() { + use egui::accesskit::Role; + use egui_kittest::kittest::{NodeT, Queryable}; + let (mut h, li, legend, drawn) = a_legend_to_break(0); + assert!(h.query_by_label("Remove Column Breaks").is_none(), "nothing to remove"); + h.state_mut().run("layout.update", json!({"element": legend, "columnBreaks": ["Rivers"]})).unwrap(); + // On the map still, but no longer listed, as a raster drawn on a ramp: no row for it. + h.state_mut().session.map_mut().layers.iter_mut().find(|l| l.name == "Rivers").unwrap().graphics = true; + h.run_steps(3); + assert!(drawn.iter().any(|n| n == "Rivers")); + assert!(h.query_by_role_and_label(Role::CheckBox, "Rivers starts a column").is_none()); + // In a row of its own: beside the box it widened the pane past its edge, 1200 here. + let button = h.get_by_label("Remove Column Breaks").rect(); + let columns = h.get_by_role_and_label(Role::SpinButton, "Columns").rect(); + assert!(button.max.x <= 1200.0 && button.min.y >= columns.max.y, "{button:?} {columns:?}"); + let depth = h.state().session.undo_depth(); + h.get_by_label("Remove Column Breaks").click(); + h.run_steps(3); + assert!(legend_breaks(&h, li, legend).0.is_empty()); + assert_eq!(h.state().session.undo_depth(), depth + 1); + assert!(!h.get_by_role_and_label(Role::SpinButton, "Columns").accesskit_node().is_disabled()); + assert!(h.query_by_label("Remove Column Breaks").is_none()); +} diff --git a/docs/user-guide/layouts.md b/docs/user-guide/layouts.md index ea6767f809..eed0f033c4 100644 --- a/docs/user-guide/layouts.md +++ b/docs/user-guide/layouts.md @@ -642,7 +642,11 @@ Layouts open as tabs next to the maps; while one is open, its groups lead the Pu breaks set the columns, so `"columns"` above 1 and the fits that add columns are refused beside them (send `"columns": 1` and `"fit": "manual"` in the same call to a legend that has them); `"fit": "adjustSize"` still shrinks the text. A column taller than the box loses its last rows, - which is said. `[]` takes the breaks off. A renamed layer keeps its column. + which is said. `[]` takes the breaks off. A renamed layer keeps its column. In the Format + pane, the ↵ check beside a layer in the Layers section starts a column at it; the first break + sets Columns to 1 and a fit that adds columns to the one that doesn't, in one undo step, and + both stay disabled while a break is set. **Remove Column Breaks**, under Columns, takes every + break off, one on a layer the legend no longer lists too. - **Labels**: a legend can show a layer under a label instead of its name, so a layer named for a plugin or a script (`BrasilData: Setores censitários 2022 (MG)`, `setores_mg_2022_clip`) reads well on the page while it keeps its name everywhere else. Scripts give