Repository navigation
feat(layout): choose a table's columns in the Format pane #3450
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 3 commits into
opengeos:main
from
jgregoriorincon:feat/3409-table-columns-chooser
Nov 30, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
e109e8c
feat(layout): choose a table's columns in the Format pane
jgregoriorincon a030f6e
fix(layout): keep the legend's layer filter and spare a wide layer pe…
jgregoriorincon 5866039
fix(layout): keep a lost table column as stored and build rows only w…
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
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,240 @@ | ||
| //! A section of named rows to tick and to move up or down, below an element's grid: a legend's | ||
| //! layers and a table's fields (#3409). | ||
|
|
||
| use egui::{Ui, vec2}; | ||
|
|
||
| /// Over this many rows, the section has a box that filters them by name. | ||
| const FILTER_OVER: usize = 8; | ||
|
|
||
| /// The height its rows scroll in, in points. | ||
| const LIST_HEIGHT: f32 = 320.0; | ||
|
|
||
| /// A row of the section. | ||
| pub(super) struct Row { | ||
| /// What its arrows are named for. | ||
| pub(super) name: String, | ||
| /// What its focus and its expansion follow as it moves: one per row. | ||
| pub(super) key: String, | ||
| /// What its checkbox shows. | ||
| pub(super) text: String, | ||
| /// Another text the filter finds it by, besides its name; empty for none. | ||
| pub(super) also: String, | ||
| pub(super) ticked: bool, | ||
| /// Whether ▲ and ▼ move it, past other movable rows. | ||
| pub(super) movable: bool, | ||
| } | ||
|
|
||
| /// What the section says and allows. Its texts come translated. | ||
| pub(super) struct Spec<'a> { | ||
| pub(super) title: &'a str, | ||
| /// What its ids come from: one per layout and element. | ||
| pub(super) id: egui::Id, | ||
| pub(super) open: bool, | ||
| pub(super) filter: &'a str, | ||
| pub(super) no_match: &'a str, | ||
| pub(super) tick: &'a str, | ||
| pub(super) select_all: &'a str, | ||
| pub(super) select_none: &'a str, | ||
| /// Reset's hover, while there is something to put back. | ||
| pub(super) reset: Option<&'a str>, | ||
| /// One row at least stays ticked. | ||
| pub(super) keep_one: bool, | ||
| } | ||
|
|
||
| /// What the section was asked for, by the rows' places. | ||
| pub(super) enum Pick { | ||
| /// A row ticked (true) or unticked. | ||
| Tick(usize, bool), | ||
| /// Every row shown, ticked or unticked. | ||
| Shown(Vec<usize>, bool), | ||
| /// Two rows to change places, the upper first. | ||
| Swap(usize, usize), | ||
| Reset, | ||
| } | ||
|
|
||
| /// What a row opens below itself. | ||
| pub(super) struct Details<'a> { | ||
| /// The hovers of its arrow, closed and open. | ||
| pub(super) show: &'a str, | ||
| pub(super) hide: &'a str, | ||
| /// The name of its arrow, open or closed, for the row named. | ||
| pub(super) named: &'a dyn Fn(bool, &str) -> String, | ||
| /// Draws what the row at this place opens. | ||
| pub(super) body: &'a mut dyn FnMut(&mut Ui, usize), | ||
| } | ||
|
|
||
| /// `text` as the 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 section: collapsible, its filter, Select All and Select None, the rows and Reset. `rows` | ||
| /// is called only while it's open; what was asked for comes with the rows it was asked of. | ||
| pub(super) fn checklist( | ||
| ui: &mut Ui, | ||
| spec: &Spec<'_>, | ||
| rows: impl FnOnce() -> Vec<Row>, | ||
| mut details: Option<Details<'_>>, | ||
| ) -> Option<(Pick, Vec<Row>)> { | ||
| let mut pick = None; | ||
| ui.add_space(4.0); | ||
| let shown_rows = egui::CollapsingHeader::new(spec.title).id_salt(spec.id).default_open(spec.open).show(ui, |ui| { | ||
| let rows = rows(); | ||
| // 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 rows.len() > FILTER_OVER { | ||
| let key = spec.id.with("filter"); | ||
| let mut text = ui.data(|d| d.get_temp::<String>(key)).unwrap_or_default(); | ||
| let r = ui.add(egui::TextEdit::singleline(&mut text).hint_text(spec.filter).desired_width(f32::INFINITY)); | ||
| // Named once typed in too, when its hint is gone. | ||
| r.widget_info(|| egui::WidgetInfo::labeled(egui::Role::TextInput, true, spec.filter)); | ||
| needle = folded(text.trim()); | ||
| ui.data_mut(|d| d.insert_temp(key, text)); | ||
| } | ||
| // The places of the rows shown. | ||
| let found = |r: &Row| needle.is_empty() || folded(&r.name).contains(&needle) || folded(&r.also).contains(&needle); | ||
| let shown: Vec<usize> = rows.iter().enumerate().filter(|(_, r)| found(r)).map(|(i, _)| i).collect(); | ||
| if !needle.is_empty() && shown.is_empty() { | ||
| ui.label(spec.no_match); | ||
| } | ||
| let ticked = rows.iter().filter(|r| r.ticked).count(); | ||
| // Every row shown at once, the matches alone under a filter. | ||
| if !shown.is_empty() { | ||
| ui.horizontal(|ui| { | ||
| let visible = || shown.iter().filter_map(|&i| rows.get(i)); | ||
| let some_out = visible().any(|r| !r.ticked); | ||
| let ticked_shown = visible().filter(|r| r.ticked).count(); | ||
| let may_untick = ticked_shown > 0 && (!spec.keep_one || ticked_shown < ticked); | ||
| if ui.add_enabled(some_out, egui::Button::new(tl!("Select All"))).on_hover_text(spec.select_all).clicked() { | ||
| pick = Some(Pick::Shown(shown.clone(), true)); | ||
| } | ||
| if ui.add_enabled(may_untick, egui::Button::new(tl!("Select None"))).on_hover_text(spec.select_none).clicked() { | ||
| pick = Some(Pick::Shown(shown.clone(), false)); | ||
| } | ||
| }); | ||
| } | ||
| // The places a row swaps with the one shown above or below it. | ||
| let mut swap = None; | ||
| let movable = |&&j: &&usize| rows.get(j).is_some_and(|r| r.movable); | ||
| // 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(spec.id.with("scroll")).max_height(LIST_HEIGHT).auto_shrink([false, true]).show( | ||
| ui, | ||
| |ui| { | ||
| for (k, (i, row)) in shown.iter().filter_map(|&i| rows.get(i).map(|r| (i, r))).enumerate() { | ||
| // A row that doesn't move looks for neither: a table's fields can be many. | ||
| let above = row.movable.then(|| shown.iter().take(k).rev().find(movable).copied()).flatten(); | ||
| let below = row.movable.then(|| shown.iter().skip(k + 1).find(movable).copied()).flatten(); | ||
| // Ids from the row's key, not its place (`push_id` would mix it in), so the | ||
| // keyboard's focus and the row's expansion move with it. | ||
| let row_id = ui.make_persistent_id(&row.key); | ||
| ui.scope_builder(egui::UiBuilder::new().scope_id(row_id), |ui| { | ||
| let mut opened = | ||
| egui::collapsing_header::CollapsingState::load_with_default_open(ui.ctx(), row_id.with("details"), false); | ||
| // The arrows on the right, the name in what they leave. | ||
| let size = vec2(ui.available_width(), ui.spacing().interact_size.y); | ||
| ui.allocate_ui_with_layout(size, egui::Layout::right_to_left(egui::Align::Center), |ui| { | ||
| // Named for its row, 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", row.name.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); | ||
| if let Some(d) = &details { | ||
| let open = opened.is_open(); | ||
| let (glyph, hover) = if open { ("▾", d.hide) } else { ("▸", d.show) }; | ||
| let label = (d.named)(open, &row.name); | ||
| let toggle = ui.add(egui::Button::new(glyph).small().frame(false)); | ||
| toggle.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Button, true, &label)); | ||
| if toggle.on_hover_text(hover).clicked() { | ||
| opened.toggle(ui); | ||
| } | ||
| } | ||
| let mut on = row.ticked; | ||
| let free = !(spec.keep_one && row.ticked && ticked == 1); | ||
| if ui.add_enabled(free, egui::Checkbox::new(&mut on, &row.text)).on_hover_text(spec.tick).changed() { | ||
| pick = Some(Pick::Tick(i, on)); | ||
| } | ||
| }); | ||
| }); | ||
| if let Some(d) = &mut details { | ||
| if opened.is_open() { | ||
| (d.body)(ui, i); | ||
| } | ||
| opened.store(ui.ctx()); | ||
| } | ||
| }); | ||
| } | ||
| }, | ||
| ); | ||
| }); | ||
| if let Some((a, b)) = swap { | ||
| pick = Some(Pick::Swap(a, b)); | ||
| } | ||
| if let Some(hover) = spec.reset | ||
| && ui.button(tl!("Reset")).on_hover_text(hover).clicked() | ||
| { | ||
| pick = Some(Pick::Reset); | ||
| } | ||
| rows | ||
| }); | ||
| pick.zip(shown_rows.body_returned) | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
| use egui_kittest::kittest::Queryable; | ||
| use std::cell::Cell; | ||
| use std::rc::Rc; | ||
|
|
||
| /// A collapsed section builds no rows; opened, it does. | ||
| #[test] | ||
| fn a_collapsed_section_builds_no_rows() { | ||
| let built = Rc::new(Cell::new(0)); | ||
| let count = built.clone(); | ||
| let mut fonts = false; | ||
| let mut h = egui_kittest::Harness::new_ui(move |ui| { | ||
| if !fonts { | ||
| crate::theme::install_fonts(ui.ctx(), &[], None); | ||
| fonts = true; | ||
| return; | ||
| } | ||
| let spec = Spec { | ||
| title: "Rows", | ||
| id: egui::Id::unique("rows"), | ||
| open: false, | ||
| filter: "Filter", | ||
| no_match: "None", | ||
| tick: "Tick", | ||
| select_all: "All", | ||
| select_none: "None of them", | ||
| reset: None, | ||
| keep_one: false, | ||
| }; | ||
| 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 }] | ||
| }; | ||
| checklist(ui, &spec, rows, None); | ||
| }); | ||
| h.run_steps(3); | ||
| assert_eq!(built.get(), 0); | ||
| h.get_by_label("Rows").click(); | ||
| h.run_steps(10); | ||
| assert!(built.get() > 0); | ||
| assert!(h.query_by_label("a").is_some()); | ||
| } | ||
| } |
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.