From 24b5930cc80330d6dfcd472b70694754e52ed22c Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 28 Nov 2026 13:10:23 -0800 Subject: [PATCH] Swatches: the footer reads the panel's selection and kind filter The panel model is out of the app while the swatch browser draws, so the footer read an empty selection and the default kind filter: Swatch Options and Delete Swatch stayed disabled with a swatch selected, and Show Swatch Kinds never showed as pressed. The footer now takes its state from the model the browser holds. --- crates/ui-egui/src/panels/swatches.rs | 17 +++++++++++------ crates/ui-egui/src/panels/swatches/tests.rs | 16 ++++++++++++++++ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/crates/ui-egui/src/panels/swatches.rs b/crates/ui-egui/src/panels/swatches.rs index 0e1991154b..a179e07a53 100644 --- a/crates/ui-egui/src/panels/swatches.rs +++ b/crates/ui-egui/src/panels/swatches.rs @@ -219,8 +219,13 @@ fn name_of(key: &SwatchKey) -> &str { /// The swatches and colour groups selected in the panel, in click order, without names that no longer exist /// (deleted, renamed or undone). pub(crate) fn selected(app: &VectorcraftApp) -> Vec { + selected_in(app, &app.ui.swatches_panel) +} + +/// The swatches and colour groups selected in `model`, as [`selected`] reads them from the app's panel. +fn selected_in(app: &VectorcraftApp, model: &Model) -> Vec { let Some(st) = app.session.active() else { return vec![] }; - let mut names = app.ui.swatches_panel.names(); + let mut names = model.names(); names.retain(|n| n == REGISTRATION || st.doc.swatch_name_taken(n)); names } @@ -407,7 +412,7 @@ fn body(app: &mut VectorcraftApp, ui: &mut Ui) { let doc = Arc::clone(&st.doc); let document = st.uid; let reverts = st.reverts; - let foot = Footer::of(app); + let foot = Footer::of(app, &model); let shown_app: &VectorcraftApp = app; let search = model.show_find; let state = &mut model.state; @@ -789,14 +794,14 @@ struct Footer { } impl Footer { - /// The footer's state, read before the swatch browser borrows the app. - fn of(app: &VectorcraftApp) -> Self { - let sel = selected(app); + /// The footer's state for the panel `model`, which is out of the app while the swatch browser borrows it. + fn of(app: &VectorcraftApp, model: &Model) -> Self { + let sel = selected_in(app, model); let del = actions::deletable(app, &sel); let opts = actions::editable(app, &sel); let group = actions::selected_group(app, &sel).filter(|_| opts.is_none()); Footer { - kind: app.ui.swatches_panel.kind, + kind: model.kind, libraries_open: library_panel::any_open::(&app.ui), document: app.session.active().map(|state| state.uid), sel, diff --git a/crates/ui-egui/src/panels/swatches/tests.rs b/crates/ui-egui/src/panels/swatches/tests.rs index e45e0f3132..617fb83a35 100644 --- a/crates/ui-egui/src/panels/swatches/tests.rs +++ b/crates/ui-egui/src/panels/swatches/tests.rs @@ -184,6 +184,22 @@ fn the_footer_menu_buttons_report_that_they_open_a_menu() { } } +/// The footer reads the panel's selection while the browser holds the panel's model: with one swatch selected, Swatch +/// Options and Delete Swatch are enabled. +#[test] +fn the_footer_acts_on_the_panels_selection() { + use crate::tests::panel_harness::Panel; + + let mut app = app(); + select_rows(&mut app, &["Red"]); + let mut panel = Panel::new(app, show); + panel.frame(); + assert_eq!(selected(&panel.app()), vec!["Red".to_string()]); + for name in ["Swatch Options", "Delete Swatch"] { + assert!(panel.enabled(name), "{name}"); + } +} + /// Art `ids` dragged off the canvas. fn art_drag(app: &VectorcraftApp, ids: Vec) -> PanelDrag { let (document, reverts) = app.session.active().map_or((0, 0), |st| (st.uid, st.reverts));