From 475a0745d8f1aeb0f097fe4d9e31224f2b5c75d2 Mon Sep 17 00:00:00 2001 From: abc2cb <271337822+abc2cb@users.noreply.github.com> Date: Mon, 12 Oct 2026 08:19:25 +0300 Subject: [PATCH 1/2] Scale Smart Filter and effect rows with Layers thumbnails --- crates/ui-egui/src/panels.rs | 7 ++-- crates/ui-egui/src/smart_ui.rs | 69 +++++++++++++++++++++++++++++++--- 2 files changed, 67 insertions(+), 9 deletions(-) diff --git a/crates/ui-egui/src/panels.rs b/crates/ui-egui/src/panels.rs index 87336ce045d..483539ae446 100644 --- a/crates/ui-egui/src/panels.rs +++ b/crates/ui-egui/src/panels.rs @@ -3859,6 +3859,7 @@ fn fx_drop(ctx: &egui::Context, ui: &egui::Ui, l: &Layer, rect: Rect, actions: & /// on "Effects" shows or hides them all, the eye on an effect's row just that one (#1622). fn effect_rows(app: &mut PhotocraftApp, ui: &mut egui::Ui, l: &Layer, depth: usize, actions: &mut Vec<(String, Value)>) { let t = Tokens::get(ui.ctx()); + let (row_height, _, eye_size, font_size) = crate::smart_ui::smart_filter_row_geometry(app.ui.layers_panel_options.thumbnail_size, t.pro); let indent = 30.0 + depth as f32 * 14.0 + 34.0; let mut rows: Vec<(String, bool, Option<&'static str>)> = vec![("Effects".into(), l.effects.enabled, None)]; for e in &l.effects.items { @@ -3866,7 +3867,7 @@ fn effect_rows(app: &mut PhotocraftApp, ui: &mut egui::Ui, l: &Layer, depth: usi rows.push((e.label().to_string(), e.enabled(), kind)); } for (i, (name, on, kind)) in rows.into_iter().enumerate() { - let (rect, resp) = ui.allocate_exact_size(vec2(ui.available_width(), 22.0), Sense::click_and_drag()); + let (rect, resp) = ui.allocate_exact_size(vec2(ui.available_width(), row_height), Sense::click_and_drag()); // Drag the row onto another layer to move its effects there, ⌥-drag to copy them. if resp.drag_started() { start_fx_drag(ui.ctx(), l.id, i.checked_sub(1)); @@ -3883,7 +3884,7 @@ fn effect_rows(app: &mut PhotocraftApp, ui: &mut egui::Ui, l: &Layer, depth: usi let eye = Rect::from_min_size(pos2(rect.left() + 6.0, rect.center().y - 9.0), vec2(18.0, 18.0)); // A hidden effect's eye box is left empty (still clickable), like a hidden layer's. if on { - icons::paint(ui, eye, "eye", 12.0, t.icon); + icons::paint(ui, eye, "eye", eye_size, t.icon); } // The whole eye column of the row takes the click, so it never opens the Layer Style dialog. let eye_cell = Rect::from_min_max(rect.left_top(), pos2((rect.left() + 30.0).min(rect.right()), rect.bottom())); @@ -3905,7 +3906,7 @@ fn effect_rows(app: &mut PhotocraftApp, ui: &mut egui::Ui, l: &Layer, depth: usi rect.center().y, right, &name, - egui::FontId::proportional(11.5), + egui::FontId::proportional(font_size), if on { t.text_dim } else { t.text_faint }, ); resp.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, true, name.clone())); diff --git a/crates/ui-egui/src/smart_ui.rs b/crates/ui-egui/src/smart_ui.rs index 99deaa60fe6..a563853df95 100644 --- a/crates/ui-egui/src/smart_ui.rs +++ b/crates/ui-egui/src/smart_ui.rs @@ -1,10 +1,11 @@ //! Layers-panel pieces for smart objects: the thumbnail badge and the Smart Filters sub-rows //! (eye toggles; double-click a filter to re-open its dialog with the recorded parameters). -use egui::{Align2, Color32, Rect, Sense, Stroke, pos2, vec2}; +use egui::{Color32, Rect, Sense, Stroke, pos2, vec2}; use photocraft_doc::{Layer, LayerContent, SmartObject}; use serde_json::{Value, json}; +use crate::state::LayerThumbnailSize; use crate::theme::Tokens; use crate::{PhotocraftApp, icons}; @@ -32,6 +33,18 @@ fn filter_label(f: &photocraft_doc::SmartFilter) -> String { .map_or_else(|| command.rsplit('.').next().unwrap_or(command).to_string(), |c| tl!(c.label).trim_end_matches('…').to_string()) } +/// Smart-filter sub-rows scale with the main Layers panel setting. The eye column +/// remains independently clickable, while the filter mask and text keep their +/// own alignment and avoid overlap when the thumbnail is set to None. +pub(crate) fn smart_filter_row_geometry(size: LayerThumbnailSize, pro: bool) -> (f32, f32, f32, f32) { + let (thumb, row) = crate::layers_panel_ui::thumbnail_geometry(size, pro); + let height = row.max(22.0); + let mask = if thumb == 0.0 { 0.0 } else { thumb.min(height - 8.0) }; + let eye = if thumb >= 40.0 { 17.0 } else { 12.0 }; + let font = if thumb >= 40.0 { 13.0 } else { 11.5 }; + (height, mask, eye, font) +} + /// Smart Filters header + one row per filter (top filter first, as in Photoshop) under a smart /// layer. Edits are queued in `actions` as engine commands. pub fn filter_rows(app: &mut PhotocraftApp, ui: &mut egui::Ui, l: &Layer, depth: usize, actions: &mut Vec<(String, Value)>) { @@ -40,10 +53,11 @@ pub fn filter_rows(app: &mut PhotocraftApp, ui: &mut egui::Ui, l: &Layer, depth: return; } let t = Tokens::get(ui.ctx()); + let (row_height, mask_size, eye_size, font_size) = smart_filter_row_geometry(app.ui.layers_panel_options.thumbnail_size, t.pro); let indent = 30.0 + depth as f32 * 14.0 + 34.0; let rows = std::iter::once(None).chain((0..sm.smart_filters.len()).rev().map(Some)); for index in rows { - let (rect, resp) = ui.allocate_exact_size(vec2(ui.available_width(), 22.0), Sense::click()); + let (rect, resp) = ui.allocate_exact_size(vec2(ui.available_width(), row_height), Sense::click()); if resp.hovered() { ui.painter().rect_filled(rect, 0.0, t.hover.gamma_multiply(0.35)); } @@ -61,7 +75,7 @@ pub fn filter_rows(app: &mut PhotocraftApp, ui: &mut egui::Ui, l: &Layer, depth: Some(i) => sm.smart_filters[i].visible, }; if shown { - icons::paint(ui, eye, "eye", 12.0, t.icon); + icons::paint(ui, eye, "eye", eye_size, t.icon); } if eye_resp.clicked() { actions.push(match index { @@ -70,12 +84,24 @@ pub fn filter_rows(app: &mut PhotocraftApp, ui: &mut egui::Ui, l: &Layer, depth: }); } let x = rect.left() + indent + if index.is_none() { 0.0 } else { 16.0 }; - if index.is_none() { - let sw = Rect::from_center_size(pos2(x - 12.0, rect.center().y), vec2(14.0, 10.0)); + if index.is_none() && mask_size > 0.0 { + // The Smart Filters mask scales along with the thumbnail size, not + // independently of the selected Layers panel display preference. + let sw = Rect::from_center_size(pos2(x + mask_size / 2.0, rect.center().y), vec2(mask_size, mask_size)); ui.painter().rect_filled(sw, 1.0, if sm.filter_mask.as_ref().is_some_and(|m| m.enabled) { Color32::from_gray(200) } else { Color32::WHITE }); ui.painter().rect_stroke(sw, 1.0, Stroke::new(1.0, t.field_border), egui::StrokeKind::Inside); } - ui.painter().text(pos2(x, rect.center().y), Align2::LEFT_CENTER, name, egui::FontId::proportional(11.5), if on { t.text_dim } else { t.text_faint }); + let text_x = if index.is_none() && mask_size > 0.0 { x + mask_size + 7.0 } else { x }; + crate::layer_row_ui::label( + ui.painter(), + text_x, + rect.center().y, + rect.right() - crate::layer_row_ui::RIGHT_PAD, + &name, + egui::FontId::proportional(font_size), + if on { t.text_dim } else { t.text_faint }, + ); + resp.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, true, name.clone())); if let Some(i) = index && resp.double_clicked() { @@ -121,3 +147,34 @@ pub fn confirm_command(fields: &serde_json::Map, command: String, None => (command, params), } } + +#[cfg(test)] +mod layer_thumbnail_scaling_tests { + use super::*; + use egui_kittest::{Harness, kittest::Queryable}; + + #[test] + fn smart_filters_and_layer_effect_rows_follow_thumbnail_setting() { + for setting in [LayerThumbnailSize::None, LayerThumbnailSize::Small, LayerThumbnailSize::Medium, LayerThumbnailSize::Large] { + let mut session = photocraft_engine::Session::new(); + session.execute("file.new", json!({"width": 50, "height": 38})).unwrap(); + session.execute("edit.fill", json!({"color": "#8A42B3"})).unwrap(); + session.execute("layer.smartObjects.convertToSmartObject", json!({})).unwrap(); + session.execute("filter.blur.gaussianBlur", json!({"radius": 3})).unwrap(); + session.execute("filter.sharpen.unsharpMask", json!({"amount": 80, "radius": 1, "threshold": 0})).unwrap(); + session.execute("layer.layerStyle.dropShadow", json!({"size": 2})).unwrap(); + assert!(matches!(session.active().unwrap().doc.layers.last().unwrap().content, LayerContent::Smart(_))); + let mut h = Harness::builder().with_size(vec2(1440.0, 1400.0)).with_max_steps(64).build_eframe(move |cc| { + PhotocraftApp::setup_context(&cc.egui_ctx, Default::default()); + PhotocraftApp::new(session, crate::Services::default()) + }); + h.state_mut().ui.layers_panel_options.thumbnail_size = setting; + h.run_steps(8); + let expected = smart_filter_row_geometry(setting, true).0; + for label in ["Smart Filters", "Gaussian Blur", "Unsharp Mask", "Effects", "Drop Shadow"] { + let rect = h.get_by_label(label).rect(); + assert!((rect.height() - expected).abs() < 1.0, "{setting:?}: {label} was {rect:?}, expected {expected}"); + } + } + } +} From 932303788371aaedc150fb198a722cb713de6002 Mon Sep 17 00:00:00 2001 From: abc2cb <271337822+abc2cb@users.noreply.github.com> Date: Tue, 13 Oct 2026 00:09:28 +0300 Subject: [PATCH 2/2] Keep Smart Filter and effect rows compact at every thumbnail size Photoshop keeps the Effects, effect and Smart Filter rows at their compact height and font at every Layers panel thumbnail size; only the layer row grows, and the Smart Filters header grows just enough for its shared-mask thumbnail, which follows the thumbnail size (hidden at None). Previously every sub-row took the layer row height and a 13 pt font at Large, so sub-rows outsized the layer name. Keep sub-rows at 22 px, 11.5 pt and a 12 px eye; scale only the Smart Filters header and its mask. Effect rows are back to main's layout. The test checks both and can save renders with PHOTOCRAFT_LAYERS_SNAPSHOTS=. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/panels.rs | 7 +++--- crates/ui-egui/src/smart_ui.rs | 46 +++++++++++++++++++++------------- 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/crates/ui-egui/src/panels.rs b/crates/ui-egui/src/panels.rs index 483539ae446..87336ce045d 100644 --- a/crates/ui-egui/src/panels.rs +++ b/crates/ui-egui/src/panels.rs @@ -3859,7 +3859,6 @@ fn fx_drop(ctx: &egui::Context, ui: &egui::Ui, l: &Layer, rect: Rect, actions: & /// on "Effects" shows or hides them all, the eye on an effect's row just that one (#1622). fn effect_rows(app: &mut PhotocraftApp, ui: &mut egui::Ui, l: &Layer, depth: usize, actions: &mut Vec<(String, Value)>) { let t = Tokens::get(ui.ctx()); - let (row_height, _, eye_size, font_size) = crate::smart_ui::smart_filter_row_geometry(app.ui.layers_panel_options.thumbnail_size, t.pro); let indent = 30.0 + depth as f32 * 14.0 + 34.0; let mut rows: Vec<(String, bool, Option<&'static str>)> = vec![("Effects".into(), l.effects.enabled, None)]; for e in &l.effects.items { @@ -3867,7 +3866,7 @@ fn effect_rows(app: &mut PhotocraftApp, ui: &mut egui::Ui, l: &Layer, depth: usi rows.push((e.label().to_string(), e.enabled(), kind)); } for (i, (name, on, kind)) in rows.into_iter().enumerate() { - let (rect, resp) = ui.allocate_exact_size(vec2(ui.available_width(), row_height), Sense::click_and_drag()); + let (rect, resp) = ui.allocate_exact_size(vec2(ui.available_width(), 22.0), Sense::click_and_drag()); // Drag the row onto another layer to move its effects there, ⌥-drag to copy them. if resp.drag_started() { start_fx_drag(ui.ctx(), l.id, i.checked_sub(1)); @@ -3884,7 +3883,7 @@ fn effect_rows(app: &mut PhotocraftApp, ui: &mut egui::Ui, l: &Layer, depth: usi let eye = Rect::from_min_size(pos2(rect.left() + 6.0, rect.center().y - 9.0), vec2(18.0, 18.0)); // A hidden effect's eye box is left empty (still clickable), like a hidden layer's. if on { - icons::paint(ui, eye, "eye", eye_size, t.icon); + icons::paint(ui, eye, "eye", 12.0, t.icon); } // The whole eye column of the row takes the click, so it never opens the Layer Style dialog. let eye_cell = Rect::from_min_max(rect.left_top(), pos2((rect.left() + 30.0).min(rect.right()), rect.bottom())); @@ -3906,7 +3905,7 @@ fn effect_rows(app: &mut PhotocraftApp, ui: &mut egui::Ui, l: &Layer, depth: usi rect.center().y, right, &name, - egui::FontId::proportional(font_size), + egui::FontId::proportional(11.5), if on { t.text_dim } else { t.text_faint }, ); resp.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, true, name.clone())); diff --git a/crates/ui-egui/src/smart_ui.rs b/crates/ui-egui/src/smart_ui.rs index a563853df95..79cdd47c6ae 100644 --- a/crates/ui-egui/src/smart_ui.rs +++ b/crates/ui-egui/src/smart_ui.rs @@ -33,16 +33,15 @@ fn filter_label(f: &photocraft_doc::SmartFilter) -> String { .map_or_else(|| command.rsplit('.').next().unwrap_or(command).to_string(), |c| tl!(c.label).trim_end_matches('…').to_string()) } -/// Smart-filter sub-rows scale with the main Layers panel setting. The eye column -/// remains independently clickable, while the filter mask and text keep their -/// own alignment and avoid overlap when the thumbnail is set to None. -pub(crate) fn smart_filter_row_geometry(size: LayerThumbnailSize, pro: bool) -> (f32, f32, f32, f32) { - let (thumb, row) = crate::layers_panel_ui::thumbnail_geometry(size, pro); - let height = row.max(22.0); - let mask = if thumb == 0.0 { 0.0 } else { thumb.min(height - 8.0) }; - let eye = if thumb >= 40.0 { 17.0 } else { 12.0 }; - let font = if thumb >= 40.0 { 13.0 } else { 11.5 }; - (height, mask, eye, font) +/// Height of a Smart Filter or effect sub-row. As in Photoshop, these stay compact at every +/// Layers panel thumbnail size; only the layer row itself grows with its thumbnails. +pub(crate) const SUB_ROW_H: f32 = 22.0; + +/// The Smart Filters header row: (row height, shared-mask thumbnail side). The mask follows the +/// Layers panel thumbnail size (hidden at None) and the row grows just enough to hold it. +pub(crate) fn smart_filters_header_geometry(size: LayerThumbnailSize, pro: bool) -> (f32, f32) { + let (thumb, _) = crate::layers_panel_ui::thumbnail_geometry(size, pro); + if thumb == 0.0 { (SUB_ROW_H, 0.0) } else { ((thumb + 6.0).max(SUB_ROW_H), thumb) } } /// Smart Filters header + one row per filter (top filter first, as in Photoshop) under a smart @@ -53,11 +52,11 @@ pub fn filter_rows(app: &mut PhotocraftApp, ui: &mut egui::Ui, l: &Layer, depth: return; } let t = Tokens::get(ui.ctx()); - let (row_height, mask_size, eye_size, font_size) = smart_filter_row_geometry(app.ui.layers_panel_options.thumbnail_size, t.pro); + let (header_height, mask_size) = smart_filters_header_geometry(app.ui.layers_panel_options.thumbnail_size, t.pro); let indent = 30.0 + depth as f32 * 14.0 + 34.0; let rows = std::iter::once(None).chain((0..sm.smart_filters.len()).rev().map(Some)); for index in rows { - let (rect, resp) = ui.allocate_exact_size(vec2(ui.available_width(), row_height), Sense::click()); + let (rect, resp) = ui.allocate_exact_size(vec2(ui.available_width(), if index.is_none() { header_height } else { SUB_ROW_H }), Sense::click()); if resp.hovered() { ui.painter().rect_filled(rect, 0.0, t.hover.gamma_multiply(0.35)); } @@ -75,7 +74,7 @@ pub fn filter_rows(app: &mut PhotocraftApp, ui: &mut egui::Ui, l: &Layer, depth: Some(i) => sm.smart_filters[i].visible, }; if shown { - icons::paint(ui, eye, "eye", eye_size, t.icon); + icons::paint(ui, eye, "eye", 12.0, t.icon); } if eye_resp.clicked() { actions.push(match index { @@ -98,7 +97,7 @@ pub fn filter_rows(app: &mut PhotocraftApp, ui: &mut egui::Ui, l: &Layer, depth: rect.center().y, rect.right() - crate::layer_row_ui::RIGHT_PAD, &name, - egui::FontId::proportional(font_size), + egui::FontId::proportional(11.5), if on { t.text_dim } else { t.text_faint }, ); resp.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, true, name.clone())); @@ -154,7 +153,7 @@ mod layer_thumbnail_scaling_tests { use egui_kittest::{Harness, kittest::Queryable}; #[test] - fn smart_filters_and_layer_effect_rows_follow_thumbnail_setting() { + fn sub_rows_stay_compact_while_the_smart_filter_mask_follows_thumbnail_setting() { for setting in [LayerThumbnailSize::None, LayerThumbnailSize::Small, LayerThumbnailSize::Medium, LayerThumbnailSize::Large] { let mut session = photocraft_engine::Session::new(); session.execute("file.new", json!({"width": 50, "height": 38})).unwrap(); @@ -170,10 +169,21 @@ mod layer_thumbnail_scaling_tests { }); h.state_mut().ui.layers_panel_options.thumbnail_size = setting; h.run_steps(8); - let expected = smart_filter_row_geometry(setting, true).0; - for label in ["Smart Filters", "Gaussian Blur", "Unsharp Mask", "Effects", "Drop Shadow"] { + // Filter and effect rows keep Photoshop's compact height at every thumbnail size. + for label in ["Gaussian Blur", "Unsharp Mask", "Effects", "Drop Shadow"] { let rect = h.get_by_label(label).rect(); - assert!((rect.height() - expected).abs() < 1.0, "{setting:?}: {label} was {rect:?}, expected {expected}"); + assert!((rect.height() - SUB_ROW_H).abs() < 1.0, "{setting:?}: {label} was {rect:?}, expected {SUB_ROW_H}"); + } + // Only the Smart Filters header grows, just enough for its shared-mask thumbnail. + let (header, mask) = smart_filters_header_geometry(setting, true); + let rect = h.get_by_label("Smart Filters").rect(); + assert!((rect.height() - header).abs() < 1.0, "{setting:?}: Smart Filters was {rect:?}, expected {header}"); + assert!(mask <= header - 6.0 || mask == 0.0, "{setting:?}: a {mask} mask must fit a {header} row"); + assert_eq!(mask == 0.0, setting == LayerThumbnailSize::None, "{setting:?}: the mask hides only at None"); + if let Some(dir) = std::env::var_os("PHOTOCRAFT_LAYERS_SNAPSHOTS") { + let dir = std::path::PathBuf::from(dir); + std::fs::create_dir_all(&dir).unwrap(); + h.render().unwrap().save(dir.join(format!("layers-sub-rows-{setting:?}.png"))).unwrap(); } } }