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
This commit is contained in:
Psychotoxical committed 2026-11-01 21:56:58 +01:00
1 parent cf8e3d352b
commit c5defb8873
3 files changed
+57 -3

No files matched your search

@@ -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 }
}
@@ -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());
}
+2 -1
View File
@@ -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);
}