From c5defb8873ea96cd0ab27efbf2f92eff90a62c4e Mon Sep 17 00:00:00 2001 From: Psychotoxical <171614930+Psychotoxical@users.noreply.github.com> Date: Sun, 1 Nov 2026 21:56:58 +0100 Subject: [PATCH] Layers panel: show the filter row in every theme The filter row (Kind, Name, Mode) was drawn only in the Pro themes, while Filter Options > Show is in every theme's panel menu, so in Studio, Classic, Solarized and the others the toggle did nothing. A hidden filter row no longer filters either: criteria set in Pro used to keep hiding layers after switching to another theme, with no row to show or clear them. They are kept and apply again once the row is shown. Related: #5546, #2729 --- crates/ui-egui/src/panels/layer_filter_ui.rs | 5 ++ .../src/panels/layer_filter_ui/tests.rs | 52 ++++++++++++++++++- crates/ui-egui/src/panels/layers.rs | 3 +- 3 files changed, 57 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/panels/layer_filter_ui.rs b/crates/ui-egui/src/panels/layer_filter_ui.rs index fd035f3284..ba207ef3af 100644 --- a/crates/ui-egui/src/panels/layer_filter_ui.rs +++ b/crates/ui-egui/src/panels/layer_filter_ui.rs @@ -31,7 +31,12 @@ pub struct Filter { } impl Filter { + /// A hidden filter row filters nothing: the criteria stay for when it's shown again, but no + /// layer may go missing from the panel without the row that says why. pub fn of(ui: &UiState) -> Self { + if !ui.layers_panel_options.show_filters { + return Self { by: FilterBy::Kind, kinds: Vec::new(), name: String::new(), mode: ui.layer_filter_mode }; + } Self { by: ui.layer_filter_by, kinds: ui.layer_filter.clone(), name: ui.layer_filter_name.clone(), mode: ui.layer_filter_mode } } diff --git a/crates/ui-egui/src/panels/layer_filter_ui/tests.rs b/crates/ui-egui/src/panels/layer_filter_ui/tests.rs index 89e1a6a0b9..ecbdc0d240 100644 --- a/crates/ui-egui/src/panels/layer_filter_ui/tests.rs +++ b/crates/ui-egui/src/panels/layer_filter_ui/tests.rs @@ -10,6 +10,7 @@ use serde_json::json; use super::{Filter, FilterBy}; use crate::PhotocraftApp; use crate::state::UiState; +use crate::theme::ThemeKind; /// Background, "Ink" (Multiply) and "Paper" in a group "Sheets", and "ink notes" (type) on top. fn session() -> photocraft_engine::Session { @@ -91,10 +92,17 @@ fn saved_settings_without_the_new_fields_still_load() { } fn harness() -> Harness<'static, PhotocraftApp> { + harness_in(ThemeKind::default()) +} + +fn harness_in(theme: ThemeKind) -> Harness<'static, PhotocraftApp> { let session = session(); let mut h = Harness::builder().with_size(vec2(1440.0, 900.0)).with_max_steps(64).build_eframe(move |cc| { - PhotocraftApp::setup_context(&cc.egui_ctx, Default::default()); - PhotocraftApp::new(session, crate::Services::default()) + PhotocraftApp::setup_context(&cc.egui_ctx, theme); + let mut app = PhotocraftApp::new(session, crate::Services::default()); + app.run("prefs.set", json!({"path": "interface.theme", "value": theme.id()})).unwrap(); + app.ui.theme = theme; + app }); h.run_steps(8); h @@ -136,3 +144,43 @@ fn the_dropdown_switches_the_panel_between_filter_types() { h.run_steps(4); assert_eq!(drawn(&h), ["ink notes"]); } + +/// The filter row was drawn in the Pro themes only, while Filter Options › Show is in every +/// theme's panel menu: in Studio and the others it did nothing. +#[test] +fn every_theme_shows_the_filter_row() { + for theme in ThemeKind::ALL { + let mut h = harness_in(theme); + assert!(h.query_by_value("Kind").is_some(), "{theme:?} draws the filter row"); + h.state_mut().ui.layer_filter = vec!["type".into()]; + h.run_steps(4); + assert_eq!(drawn(&h), ["ink notes"], "{theme:?} filters by kind"); + } +} + +/// A filter set while the row was shown stops filtering once the row is hidden, so no layer goes +/// missing without the row that says why; showing the row again brings the filter back. +#[test] +fn a_hidden_filter_row_filters_nothing() { + let mut h = harness_in(ThemeKind::Studio); + h.state_mut().ui.layer_filter = vec!["type".into()]; + h.run_steps(4); + assert_eq!(drawn(&h), ["ink notes"]); + h.state_mut().ui.layers_panel_options.show_filters = false; + h.run_steps(4); + assert!(h.query_by_value("Kind").is_none(), "the row is hidden"); + assert_eq!(drawn(&h), ["ink notes", "Sheets", "Ink", "Paper", "Background"]); + assert_eq!(h.state().ui.layer_filter, ["type"], "the criteria are kept"); + h.state_mut().ui.layers_panel_options.show_filters = true; + h.run_steps(4); + assert_eq!(drawn(&h), ["ink notes"]); +} + +#[test] +fn a_hidden_filter_row_makes_the_filter_inactive() { + let mut ui = UiState { layer_filter_by: FilterBy::Mode, layer_filter_name: "ink".into(), ..UiState::default() }; + ui.layer_filter = vec!["pixel".into()]; + assert!(Filter::of(&ui).active()); + ui.layers_panel_options.show_filters = false; + assert!(!Filter::of(&ui).active()); +} diff --git a/crates/ui-egui/src/panels/layers.rs b/crates/ui-egui/src/panels/layers.rs index 176ed271e1..e95ac7db97 100644 --- a/crates/ui-egui/src/panels/layers.rs +++ b/crates/ui-egui/src/panels/layers.rs @@ -123,7 +123,8 @@ pub(super) fn layers(app: &mut PhotocraftApp, ui: &mut egui::Ui) { if !ui.input(|i| i.pointer.primary_down()) || !app.ui.layers_panel_options.preview_on_canvas_when_reordering_layers { app.reorder_preview = None; } - if t.pro && app.ui.layers_panel_options.show_filters { + // Every theme draws the filter row: Filter Options › Show is in every theme's panel menu. + if app.ui.layers_panel_options.show_filters { crate::layer_filter_ui::bar(app, ui); ui.add_space(4.0); }