Repository navigation
feat(layout): start a legend column from the Format pane #3472
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jgregoriorincon
merged 7 commits into
opengeos:main
from
jgregoriorincon:feat/3445-legend-break-checkbox
Nov 30, 2026
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
fa49432
feat(layout): disable columns and column fits while a legend has colu…
jgregoriorincon 248040b
feat(layout): start a legend column from a layer's check in the Forma…
jgregoriorincon 12c97b9
docs(layout): the Format pane's column break check
jgregoriorincon 7676634
fix(layout): keep a ticked column break check enabled
jgregoriorincon 12be6ae
fix(layout): take the column limit in a break check's reason from its…
jgregoriorincon fb46157
fix(layout): remove every column break from the Format pane
jgregoriorincon 2edc266
fix(layout): give the remove-column-breaks button its own row
jgregoriorincon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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<String> { | ||
| 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<String> { | ||
| 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": []})); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.