Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

Smart Filters: select a filter, drag or ⌥-drag it onto another smart object (#4271) (#4371)

F4LCON05e98e7ade37
diff --git a/crates/engine/src/smart_cmds.rs b/crates/engine/src/smart_cmds.rs
index 635c5bb08..e108c4d7b 100644
--- a/crates/engine/src/smart_cmds.rs
+++ b/crates/engine/src/smart_cmds.rs
@@ -1069,6 +1069,73 @@ fn move_filter(s: &mut Session, p: &Value) -> Result<Value> {
})
}
+/// Dragging smart filters onto another smart object in the Layers panel (#4271): they move there,
+/// or are copied with `copy` (⌥-drag in Photoshop). One filter (`filter`) lands on top of the
+/// target's filters; all of them (the Smart Filters row) are added on top too, with the filter
+/// mask when the target has none. Both smart objects are re-rendered in one undo step.
+fn transfer_filters(s: &mut Session, p: &Value) -> Result<Value> {
+ const CMD: &str = "layer.smartFilter.transfer";
+ let id_of = |key: &str| p.get(key).and_then(Value::as_u64).map(LayerId).ok_or_else(|| bad(CMD, format!("`{key}` must be a layer id")));
+ let (from, to) = (id_of("from")?, id_of("to")?);
+ if from == to {
+ return Err(bad(CMD, "the smart filters are already on that layer"));
+ }
+ // The other `layer.smartFilter.*` commands name a filter `index`; here a guessed `index`
+ // would otherwise be dropped and every filter moved.
+ if p.get("index").is_some() {
+ return Err(bad(CMD, "name the filter with `filter` (no `filter`: all of them)"));
+ }
+ let copy = p.get("copy").and_then(Value::as_bool).unwrap_or(false);
+ let doc = &s.active().ok_or(EngineError::NoDocument)?.doc;
+ let src = smart(doc, from)?;
+ smart(doc, to).map_err(|_| bad(CMD, "smart filters can only be dropped on a smart object"))?;
+ let n = src.smart_filters.len();
+ if n == 0 {
+ return Err(other("the smart object has no smart filters"));
+ }
+ let index = match p.get("filter") {
+ None | Some(Value::Null) => None,
+ Some(v) => Some(v.as_u64().map(|i| i as usize).filter(|i| *i < n).ok_or_else(|| bad(CMD, format!("`filter` must be 0..{n} (0 = bottom filter)")))?),
+ };
+ let (filters, mask) = match index {
+ Some(i) => (vec![src.smart_filters[i].clone()], None),
+ None => (src.smart_filters.clone(), src.filter_mask.clone()),
+ };
+ let label = match (copy, index.is_some()) {
+ (true, true) => "Copy Smart Filter",
+ (true, false) => "Copy Smart Filters",
+ (false, true) => "Move Smart Filter",
+ (false, false) => "Move Smart Filters",
+ };
+ crate::jobs::edit_job(
+ s,
+ label,
+ move |doc, _, ctx| {
+ let dst = smart_mut(doc, to)?;
+ dst.smart_filters.extend(filters);
+ if dst.filter_mask.is_none() {
+ dst.filter_mask = mask;
+ }
+ refresh_or_fail_in(doc, to, ctx)?;
+ if !copy {
+ let src = smart_mut(doc, from)?;
+ match index {
+ Some(i) => {
+ src.smart_filters.remove(i);
+ }
+ None => {
+ src.smart_filters.clear();
+ src.filter_mask = None;
+ }
+ }
+ refresh_or_fail_in(doc, from, ctx)?;
+ }
+ Ok(())
+ },
+ move |()| json!({"from": from.0, "to": to.0}),
+ )
+}
+
// ---------- enablement ----------
fn active_smart(s: &Session) -> std::result::Result<&SmartObject, String> {
@@ -1088,6 +1155,9 @@ fn has_linked(s: &Session) -> std::result::Result<(), String> {
_ => Err("the smart object is embedded".into()),
}
}
+fn has_doc(s: &Session) -> std::result::Result<(), String> {
+ s.active().map(|_| ()).ok_or_else(|| "no document open".into())
+}
fn has_smart_filters(s: &Session) -> std::result::Result<(), String> {
if active_smart(s)?.smart_filters.is_empty() { Err("the smart object has no smart filters".into()) } else { Ok(()) }
}
@@ -1269,6 +1339,14 @@ pub fn specs() -> Vec<CommandSpec> {
),
spec!("layer.smartFilter.delete", "Delete Smart Filter", &[], r##"{"layer":id?,"index":u32?}"##, has_smart_filters, delete_filter),
spec!("layer.smartFilter.move", "Move Smart Filter", &[], r##"{"layer":id?,"index":u32?,"to":u32}"##, has_smart_filters, move_filter),
+ spec!(
+ "layer.smartFilter.transfer",
+ "Move or Copy Smart Filters",
+ &[],
+ r##"{"from":id,"to":id,"filter":u32? (default: all, with the filter mask),"copy":bool=false}"##,
+ has_doc,
+ transfer_filters
+ ),
]
}
diff --git a/crates/engine/src/smart_cmds/tests.rs b/crates/engine/src/smart_cmds/tests.rs
index aa88fe3fe..a6cdbf48d 100644
--- a/crates/engine/src/smart_cmds/tests.rs
+++ b/crates/engine/src/smart_cmds/tests.rs
@@ -247,6 +247,69 @@ fn smart_filter_commands_check_an_explicit_layer_target() {
assert_eq!(active(&s), curves);
}
+/// #4271: dragging smart filters onto another smart object moves them, ⌥-dragging copies them;
+/// one filter or all of them (with the filter mask), each in one undo step.
+#[test]
+fn smart_filters_move_or_copy_to_another_smart_object() {
+ let mut s = session(8);
+ paint(&mut s);
+ let a = convert(&mut s);
+ s.execute("select.rect", json!({"x": 0, "y": 0, "width": 16, "height": 48})).unwrap();
+ s.execute("filter.other.offset", json!({"horizontal": 5, "undefinedAreas": "transparent"})).unwrap();
+ s.execute("select.deselect", json!({})).unwrap();
+ s.execute("filter.blur.gaussianBlur", json!({"radius": 3})).unwrap();
+ s.execute("layer.new.layer", json!({})).unwrap();
+ paint(&mut s);
+ let b = convert(&mut s);
+ let pixel = s.execute("layer.new.layer", json!({})).unwrap()["layer"].as_u64().unwrap();
+ let so = |s: &Session, id: u64| match &s.active().unwrap().doc.layer(LayerId(id)).unwrap().content {
+ LayerContent::Smart(sm) => sm.clone(),
+ other => panic!("not smart: {}", other.kind_name()),
+ };
+ let commands = |sm: &SmartObject| sm.smart_filters.iter().map(|f| f.command.clone()).collect::<Vec<_>>();
+ let (offset, blur) = ("filter.other.offset", "filter.blur.gaussianBlur");
+ assert_eq!(commands(&so(&s, a)), [offset, blur]);
+ assert!(so(&s, a).filter_mask.is_some());
+ let before = flat(&s);
+
+ // ⌥-drag the blur: B gets a copy (re-rendered), A keeps it.
+ s.execute("layer.smartFilter.transfer", json!({"from": a, "to": b, "filter": 1, "copy": true})).unwrap();
+ assert_eq!(commands(&so(&s, b)), [blur]);
+ assert_eq!(commands(&so(&s, a)), [offset, blur]);
+ assert!(so(&s, b).filter_mask.is_none(), "one filter comes without the mask");
+ assert!(max_diff(&flat(&s), &before) > 1e-3, "B is blurred");
+ s.undo();
+ assert!(so(&s, b).smart_filters.is_empty());
+ assert_eq!(flat(&s), before);
+
+ // Drag the offset: it moves to the top of B's filters.
+ s.redo();
+ s.execute("layer.smartFilter.transfer", json!({"from": a, "to": b, "filter": 0})).unwrap();
+ assert_eq!(commands(&so(&s, a)), [blur]);
+ assert_eq!(commands(&so(&s, b)), [blur, offset]);
+
+ // Drag the Smart Filters row: all of A's filters and its filter mask move to B.
+ let mask = so(&s, a).filter_mask;
+ s.execute("layer.smartFilter.transfer", json!({"from": a, "to": b})).unwrap();
+ assert!(so(&s, a).smart_filters.is_empty() && so(&s, a).filter_mask.is_none());
+ assert_eq!(commands(&so(&s, b)), [blur, offset, blur]);
+ assert_eq!(so(&s, b).filter_mask, mask);
+ s.undo();
+ assert_eq!(so(&s, a).smart_filters.len(), 1);
+ assert_eq!(so(&s, b).smart_filters.len(), 2);
+
+ // Refused: onto itself, onto a layer that isn't a smart object, a bad index, no filters.
+ let transfer = |s: &mut Session, p: Value| s.execute("layer.smartFilter.transfer", p);
+ assert!(transfer(&mut s, json!({"from": a, "to": a})).is_err());
+ assert!(transfer(&mut s, json!({"from": a, "to": pixel})).is_err());
+ assert!(transfer(&mut s, json!({"from": a, "to": b, "filter": 5})).is_err());
+ assert!(transfer(&mut s, json!({"from": a, "to": b, "index": 0})).is_err(), "`index` isn't taken for `filter`");
+ assert!(transfer(&mut s, json!({"from": pixel, "to": b})).is_err());
+ s.execute("layer.smartFilter.clearSmartFilters", json!({"layer": a})).unwrap();
+ assert!(transfer(&mut s, json!({"from": a, "to": b})).is_err());
+ assert_eq!(so(&s, b).smart_filters.len(), 2, "nothing changed");
+}
+
#[test]
fn selection_becomes_the_filter_mask() {
let mut s = session(8);
diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs
index 96158c024..cc8d8bdf2 100644
--- a/crates/ui-egui/src/lib.rs
+++ b/crates/ui-egui/src/lib.rs
@@ -2390,6 +2390,9 @@ mod color_tab_theme_tests;
#[cfg(test)]
mod new_layer_button_tests;
+#[cfg(test)]
+mod smart_filter_rows_tests;
+
#[cfg(test)]
mod move_outline_tests;
diff --git a/crates/ui-egui/src/panels.rs b/crates/ui-egui/src/panels.rs
index 78f1715c9..3624dbbf5 100644
--- a/crates/ui-egui/src/panels.rs
+++ b/crates/ui-egui/src/panels.rs
@@ -2247,8 +2247,13 @@ fn layers(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
if !ctx.input(|i| i.pointer.primary_down() || i.pointer.any_released()) {
ctx.data_mut(|d| d.remove::<FxDrag>(fx_drag_key()));
ctx.data_mut(|d| d.remove::<MaskDrag>(mask_drag_key()));
+ ctx.data_mut(|d| d.remove::<crate::smart_ui::FilterDrag>(crate::smart_ui::drag_key()));
}
- let held = ctx.data(|d| d.get_temp::<u64>(egui::Id::new("layer-drag")).is_some() || d.get_temp::<FxDrag>(fx_drag_key()).is_some());
+ let held = ctx.data(|d| {
+ d.get_temp::<u64>(egui::Id::new("layer-drag")).is_some()
+ || d.get_temp::<FxDrag>(fx_drag_key()).is_some()
+ || d.get_temp::<crate::smart_ui::FilterDrag>(crate::smart_ui::drag_key()).is_some()
+ });
let dragging = held && ctx.input(|i| i.pointer.primary_down());
let pointer = ctx.input(|i| i.pointer.interact_pos());
let delta = layer_drag_edge_scroll(pointer, ui.clip_rect(), dragging, ctx.input(|i| i.stable_dt));
@@ -2332,6 +2337,9 @@ fn layers(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
// An effect row can be dropped on Delete too (#3102), and a mask's thumbnail (#3113, #3119).
let fx_footer_drag = ctx.data(|d| d.get_temp::<FxDrag>(fx_drag_key()));
fx_drag_feedback(&ctx, &doc);
+ // And a smart filter's row (#4271).
+ let filter_footer_drag = ctx.data(|d| d.get_temp::<crate::smart_ui::FilterDrag>(crate::smart_ui::drag_key()));
+ crate::smart_ui::drag_feedback(&ctx, &doc);
let mask_footer_drag = ctx.data(|d| d.get_temp::<MaskDrag>(mask_drag_key()));
if let Some((_, kind)) = mask_footer_drag
&& let Some(p) = ctx.input(|i| i.pointer.interact_pos())
@@ -2344,6 +2352,7 @@ fn layers(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
ctx.data_mut(|d| d.remove::<u64>(egui::Id::new("layer-drag")));
ctx.data_mut(|d| d.remove::<FxDrag>(fx_drag_key()));
ctx.data_mut(|d| d.remove::<MaskDrag>(mask_drag_key()));
+ ctx.data_mut(|d| d.remove::<crate::smart_ui::FilterDrag>(crate::smart_ui::drag_key()));
}
widgets::panel_footer(ui, |ui| {
let active_layer = active.and_then(|id| doc.layer(id));
@@ -2363,6 +2372,11 @@ fn layers(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
}
actions.extend(footer_drop(ui, &trash, footer_drag, "layer.delete"));
actions.extend(fx_trash_drop(ui, &trash, fx_footer_drag));
+ if let Some(drag) = filter_footer_drag
+ && dropped_on(ui, &trash)
+ {
+ actions.push(crate::smart_ui::trash_action(drag));
+ }
// Photoshop asks "Apply mask to layer before removing?" or "Delete the vector mask?"
// (`mask_trash_prompt`).
if let Some((layer, kind)) = mask_footer_drag
@@ -2642,6 +2656,7 @@ fn layer_row(
let mask_drag = mask_drag.is_some();
layer_drag_and_drop(app, ctx, ui, l, rect, &resp, actions);
fx_drop(ctx, ui, l, rect, actions);
+ crate::smart_ui::drop_on_row(ctx, ui, l, rect, actions);
if resp.drag_started() && !mask_drag {
crate::layer_transfer::begin_from_panel(app, ctx, l.id);
}
diff --git a/crates/ui-egui/src/smart_filter_rows_tests.rs b/crates/ui-egui/src/smart_filter_rows_tests.rs
new file mode 100644
index 000000000..519402672
--- /dev/null
+++ b/crates/ui-egui/src/smart_filter_rows_tests.rs
@@ -0,0 +1,164 @@
+//! Layers panel Smart Filters rows (#4271): a click selects a filter (and its smart object), a
+//! drag onto another smart object moves it there, ⌥-drag copies it, and a drag onto Delete
+//! removes it, as in Photoshop.
+
+use egui::accesskit::{Role, Toggled};
+use egui::{Modifiers, Pos2};
+use egui_kittest::kittest::{NodeT, Queryable};
+use photocraft_doc::{LayerContent, LayerId};
+use serde_json::json;
+
+use crate::PhotocraftApp;
+
+/// Smart objects "Smart A" (Gaussian Blur and Offset) and "Smart B" (no filters), and a pixel
+/// layer "Pixels" on top: (harness, A, B, pixels).
+fn panel() -> (egui_kittest::Harness<'static, PhotocraftApp>, u64, u64, u64) {
+ let mut s = photocraft_engine::Session::new();
+ s.execute("file.new", json!({"width": 16, "height": 16})).unwrap();
+ let smart = |s: &mut photocraft_engine::Session, name: &str| {
+ s.execute("layer.new.layer", json!({})).unwrap();
+ s.execute("edit.fill", json!({"contents": "black"})).unwrap();
+ let id = s.execute("layer.smartObjects.convertToSmartObject", json!({})).unwrap()["layer"].as_u64().unwrap();
+ s.execute("layer.setProps", json!({"layer": id, "name": name})).unwrap();
+ id
+ };
+ let a = smart(&mut s, "Smart A");
+ s.execute("filter.blur.gaussianBlur", json!({"radius": 1})).unwrap();
+ s.execute("filter.other.offset", json!({"horizontal": 2})).unwrap();
+ let b = smart(&mut s, "Smart B");
+ let c = s.execute("layer.new.layer", json!({})).unwrap()["layer"].as_u64().unwrap();
+ s.execute("layer.setProps", json!({"layer": c, "name": "Pixels"})).unwrap();
+ // 60 fps steps, so a double-click's two clicks fall inside egui's 0.3 s window.
+ let mut h = egui_kittest::Harness::builder().with_size(egui::vec2(1200.0, 900.0)).with_max_steps(64).with_step_dt(1.0 / 60.0).build_eframe(|cc| {
+ PhotocraftApp::setup_context(&cc.egui_ctx, Default::default());
+ PhotocraftApp::new(s, crate::Services::default())
+ });
+ h.run_steps(4);
+ (h, a, b, c)
+}
+
+fn filters(h: &egui_kittest::Harness<'static, PhotocraftApp>, id: u64) -> Vec<String> {
+ match &h.state().session.active().unwrap().doc.layer(LayerId(id)).unwrap().content {
+ LayerContent::Smart(sm) => sm.smart_filters.iter().map(|f| f.command.clone()).collect(),
+ _ => Vec::new(),
+ }
+}
+
+/// The centre of the Layers panel row (or footer button) labelled `label`: rows are selectable
+/// labels, which AccessKit calls buttons, unlike the same name drawn elsewhere.
+fn at(h: &egui_kittest::Harness<'static, PhotocraftApp>, label: &str) -> Pos2 {
+ h.query_all_by_label(label).find(|n| n.accesskit_node().role() == Role::Button).unwrap_or_else(|| panic!("`{label}` drawn")).rect().center()
+}
+
+fn selected(h: &egui_kittest::Harness<'static, PhotocraftApp>, label: &str) -> bool {
+ h.get_by_role_and_label(Role::Button, label).accesskit_node().toggled() == Some(Toggled::True)
+}
+
+/// Press at `from`, move to `to` in steps and release there, with `modifiers` held on release.
+fn drag(h: &mut egui_kittest::Harness<'static, PhotocraftApp>, from: Pos2, to: Pos2, modifiers: Modifiers) {
+ h.hover_at(from);
+ h.run_steps(1);
+ h.drag_at(from);
+ h.run_steps(1);
+ for i in 1..=6 {
+ h.hover_at(from + (to - from) * (i as f32 / 6.0));
+ h.run_steps(1);
+ }
+ h.event(egui::Event::ModifiersChanged(modifiers));
+ h.run_steps(1);
+ h.event(egui::Event::PointerButton { pos: to, button: egui::PointerButton::Primary, pressed: false, modifiers });
+ h.run_steps(4);
+ h.event(egui::Event::ModifiersChanged(Modifiers::NONE));
+ h.run_steps(2);
+}
+
+#[test]
+fn a_click_selects_the_filter_and_its_smart_object() {
+ let (mut h, a, _, c) = panel();
+ assert_eq!(h.state().session.active().unwrap().active_layer, Some(LayerId(c)));
+ h.get_by_role_and_label(Role::Button, "Gaussian Blur").click();
+ h.run_steps(4);
+ assert_eq!(h.state().session.active().unwrap().active_layer, Some(LayerId(a)), "the smart object becomes active");
+ assert!(selected(&h, "Gaussian Blur"));
+ assert!(!selected(&h, "Offset"));
+ // Another layer: the filter is no longer shown selected.
+ let pixels = at(&h, "Pixels");
+ h.hover_at(pixels);
+ h.run_steps(1);
+ h.drag_at(pixels);
+ h.run_steps(1);
+ h.drop_at(pixels);
+ h.run_steps(4);
+ assert_eq!(h.state().session.active().unwrap().active_layer, Some(LayerId(c)));
+ assert!(!selected(&h, "Gaussian Blur"));
+}
+
+#[test]
+fn dragging_a_filter_onto_another_smart_object_moves_it_and_alt_copies_it() {
+ let (mut h, a, b, _) = panel();
+ let (blur, offset) = ("filter.blur.gaussianBlur", "filter.other.offset");
+ let (from, to) = (at(&h, "Gaussian Blur"), at(&h, "Smart B"));
+ drag(&mut h, from, to, Modifiers::ALT);
+ assert_eq!(filters(&h, b), [blur], "⌥-drag copies");
+ assert_eq!(filters(&h, a), [blur, offset]);
+ let (from, to) = (at(&h, "Offset"), at(&h, "Smart B"));
+ drag(&mut h, from, to, Modifiers::NONE);
+ assert_eq!(filters(&h, b), [blur, offset], "a drag moves");
+ assert_eq!(filters(&h, a), [blur]);
+}
+
+#[test]
+fn a_pixel_layer_does_not_take_smart_filters() {
+ let (mut h, a, _, _) = panel();
+ let (from, to) = (at(&h, "Gaussian Blur"), at(&h, "Pixels"));
+ drag(&mut h, from, to, Modifiers::NONE);
+ assert_eq!(filters(&h, a).len(), 2);
+ assert!(!h.state().ui.status_error, "{}", h.state().ui.status);
+}
+
+#[test]
+fn dragging_filters_onto_delete_removes_them() {
+ let (mut h, a, _, _) = panel();
+ let (from, to) = (at(&h, "Offset"), at(&h, "Delete layer"));
+ drag(&mut h, from, to, Modifiers::NONE);
+ assert_eq!(filters(&h, a), ["filter.blur.gaussianBlur"]);
+ let (from, to) = (at(&h, "Smart Filters"), at(&h, "Delete layer"));
+ drag(&mut h, from, to, Modifiers::NONE);
+ assert!(filters(&h, a).is_empty());
+ assert_eq!(h.state().session.active().unwrap().doc.layers.len(), 4, "no layer was deleted");
+}
+
+/// The report's case: the Camera Raw Filter is ⌥-dragged to another smart object with its
+/// settings, and double-clicking the copy opens Camera Raw on that smart object's filter.
+#[test]
+fn a_camera_raw_filter_copies_and_its_copy_opens_on_the_target() {
+ let (mut h, a, b, _) = panel();
+ h.state_mut().run("layer.select", json!({"layer": a})).unwrap();
+ h.state_mut().run("filter.cameraRaw", json!({"exposure": 1.0, "contrast": 20})).unwrap();
+ h.run_steps(4);
+ let (from, to) = (at(&h, "Camera Raw Filter"), at(&h, "Smart B"));
+ drag(&mut h, from, to, Modifiers::ALT);
+ let raw = |h: &egui_kittest::Harness<'static, PhotocraftApp>, id: u64| match &h.state().session.active().unwrap().doc.layer(LayerId(id)).unwrap().content {
+ LayerContent::Smart(sm) => sm.smart_filters.iter().find(|f| f.command == "filter.cameraRaw").map(|f| f.params.clone()),
+ _ => None,
+ };
+ assert_eq!(raw(&h, b), raw(&h, a), "copied with its settings");
+ assert_eq!(raw(&h, b).unwrap()["exposure"], 1.0);
+ // B is above A in the panel, so its copy is the upper of the two Camera Raw rows.
+ let copy = h
+ .query_all_by_label("Camera Raw Filter")
+ .filter(|n| n.accesskit_node().role() == Role::Button)
+ .map(|n| n.rect().center())
+ .min_by(|p, q| p.y.total_cmp(&q.y))
+ .unwrap();
+ for _ in 0..2 {
+ h.hover_at(copy);
+ h.drag_at(copy);
+ h.run_steps(1);
+ h.drop_at(copy);
+ h.run_steps(1);
+ }
+ h.run_steps(3);
+ let dialog = h.state().camera_raw.as_ref().expect("Camera Raw opened");
+ assert_eq!(dialog.layer, LayerId(b));
+}
diff --git a/crates/ui-egui/src/smart_ui.rs b/crates/ui-egui/src/smart_ui.rs
index 99deaa60f..ed3109201 100644
--- a/crates/ui-egui/src/smart_ui.rs
+++ b/crates/ui-egui/src/smart_ui.rs
@@ -1,8 +1,9 @@
//! 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).
+//! (eye toggles; double-click a filter to re-open its dialog with the recorded parameters; click
+//! to select one; drag onto another smart object to move it there, ⌥-drag to copy it, #4271).
-use egui::{Align2, Color32, Rect, Sense, Stroke, pos2, vec2};
-use photocraft_doc::{Layer, LayerContent, SmartObject};
+use egui::{Align2, Color32, Rect, Sense, Stroke, StrokeKind, pos2, vec2};
+use photocraft_doc::{Document, Layer, LayerContent, LayerId, SmartObject};
use serde_json::{Value, json};
use crate::theme::Tokens;
@@ -41,10 +42,20 @@ pub fn filter_rows(app: &mut PhotocraftApp, ui: &mut egui::Ui, l: &Layer, depth:
}
let t = Tokens::get(ui.ctx());
let indent = 30.0 + depth as f32 * 14.0 + 34.0;
+ let Some(st) = app.session.active() else { return };
+ let (active, doc) = (st.active_layer == Some(l.id), st.doc.id);
+ let picked = ui.ctx().data(|d| d.get_temp::<FilterDrag>(selected_key(doc)));
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());
- if resp.hovered() {
+ let (rect, resp) = ui.allocate_exact_size(vec2(ui.available_width(), 22.0), Sense::click_and_drag());
+ if resp.drag_started() {
+ ui.ctx().data_mut(|d| d.insert_temp::<FilterDrag>(drag_key(), (l.id.0, index)));
+ }
+ // Selected as in Photoshop: the row stays highlighted while its smart object is active.
+ let selected = active && picked == Some((l.id.0, index));
+ if selected {
+ ui.painter().rect_filled(rect, 0.0, if t.pro { t.row_selected } else { t.hover });
+ } else if resp.hovered() {
ui.painter().rect_filled(rect, 0.0, t.hover.gamma_multiply(0.35));
}
if t.pro {
@@ -75,7 +86,14 @@ pub fn filter_rows(app: &mut PhotocraftApp, ui: &mut egui::Ui, l: &Layer, depth:
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 });
+ 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 });
+ resp.widget_info(|| egui::WidgetInfo::selected(egui::WidgetType::SelectableLabel, true, selected, &name));
+ if resp.clicked() {
+ ui.ctx().data_mut(|d| d.insert_temp::<FilterDrag>(selected_key(doc), (l.id.0, index)));
+ if !active {
+ actions.push(("layer.select".into(), json!({"layer": l.id.0})));
+ }
+ }
if let Some(i) = index
&& resp.double_clicked()
{
@@ -84,6 +102,67 @@ pub fn filter_rows(app: &mut PhotocraftApp, ui: &mut egui::Ui, l: &Layer, depth:
}
}
+/// Smart filter rows being dragged: the smart object and the filter index (`None` = the Smart
+/// Filters row, all of them). Also what a click selects.
+pub(crate) type FilterDrag = (u64, Option<usize>);
+
+pub(crate) fn drag_key() -> egui::Id {
+ egui::Id::new("smart-filter-drag")
+}
+
+/// The selected smart filter row of a document.
+fn selected_key(doc: photocraft_doc::DocId) -> egui::Id {
+ egui::Id::new(("smart-filter-selected", doc))
+}
+
+/// While smart filters are dragged: their name by the pointer, and the copy cursor while ⌥ is held.
+pub(crate) fn drag_feedback(ctx: &egui::Context, doc: &Document) {
+ let Some((from, filter)) = ctx.data(|d| d.get_temp::<FilterDrag>(drag_key())) else { return };
+ let Some(p) = ctx.input(|i| i.pointer.interact_pos()) else { return };
+ let label = match (filter, doc.layer(LayerId(from)).map(|l| &l.content)) {
+ (Some(i), Some(LayerContent::Smart(sm))) => sm.smart_filters.get(i).map_or_else(String::new, filter_label),
+ _ => "Smart Filters".to_string(),
+ };
+ crate::layer_transfer::ghost(ctx, p, &label);
+ if ctx.input(|i| i.modifiers.alt) {
+ ctx.set_cursor_icon(egui::CursorIcon::Copy);
+ }
+}
+
+/// The command for dropping the smart filters of `from` on the smart object `target`: they move
+/// there, or with ⌥ held on release are copied (Photoshop).
+pub(crate) fn drop_action(from: u64, filter: Option<usize>, target: LayerId, copy: bool) -> (String, Value) {
+ let mut payload = json!({"from": from, "to": target.0, "copy": copy});
+ if let (Some(i), Some(o)) = (filter, payload.as_object_mut()) {
+ o.insert("filter".into(), json!(i));
+ }
+ ("layer.smartFilter.transfer".into(), payload)
+}
+
+/// Another smart object's row accepts the smart filters being dragged: outlined while the pointer
+/// is over it, dropped on release. Other layers don't take them, as in Photoshop.
+pub(crate) fn drop_on_row(ctx: &egui::Context, ui: &egui::Ui, l: &Layer, rect: Rect, actions: &mut Vec<(String, Value)>) {
+ let Some((from, filter)) = ctx.data(|d| d.get_temp::<FilterDrag>(drag_key())) else { return };
+ let Some(p) = ctx.input(|i| i.pointer.interact_pos()) else { return };
+ if from == l.id.0 || !matches!(l.content, LayerContent::Smart(_)) || !rect.contains(p) {
+ return;
+ }
+ let t = Tokens::get(ctx);
+ ui.painter().rect_stroke(rect.shrink(1.0), t.radius_sm, Stroke::new(2.0, t.accent), StrokeKind::Inside);
+ if ctx.input(|i| i.pointer.any_released()) {
+ actions.push(drop_action(from, filter, l.id, ctx.input(|i| i.modifiers.alt)));
+ }
+}
+
+/// Smart filters dropped on the footer's Delete button: a filter's row deletes that filter, the
+/// Smart Filters row clears them all.
+pub(crate) fn trash_action((layer, filter): FilterDrag) -> (String, Value) {
+ match filter {
+ Some(i) => ("layer.smartFilter.delete".into(), json!({"layer": layer, "index": i})),
+ None => ("layer.smartFilter.clearSmartFilters".into(), json!({"layer": layer})),
+ }
+}
+
/// Re-opens a smart filter's dialog with its recorded parameters; OK runs
/// `layer.smartFilter.setParams` instead of adding another filter (see `dialogs::confirm`).
pub fn open_editor(app: &mut PhotocraftApp, ctx: &egui::Context, layer: u64, sm: &SmartObject, index: usize) {
diff --git a/docs/ui-parity.md b/docs/ui-parity.md
index 8c0e0d258..708e5276a 100644
--- a/docs/ui-parity.md
+++ b/docs/ui-parity.md
@@ -1,6 +1,6 @@
# UI parity: tools, handles, modifiers and feel
-> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-12 · **Change:** minor (toolbar tool shortcuts can be reassigned; ⇧-dragged guides land on ruler ticks; layer and selection keys; tool keys; spring-loaded tool letters; type formatting keys; Pen Auto Add/Delete, #4144) · **Target:** Adobe Photoshop 2026
+> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-12 · **Change:** minor (toolbar tool shortcuts can be reassigned; ⇧-dragged guides land on ruler ticks; layer and selection keys; tool keys; spring-loaded tool letters; type formatting keys; Pen Auto Add/Delete, #4144; smart filter rows) · **Target:** Adobe Photoshop 2026
How PhotoCraft's direct manipulation compares with Photoshop 2026 (27.11.0): the toolbox, the
handles and modifier keys of each gesture, nudging, snapping, numeric precision, navigation,
@@ -210,6 +210,7 @@ Paragraph; the rest open as in-app floating windows.
| Themes: Photoshop's four greys | partial | five themes; #2661 |
| Document tabs: overflow, context menu, reorder | done | UI-217-6; middle-click close #2570 |
| Layers panel: wheel steps blend modes, drop on New/Trash | partial | UI-217-14 |
+| Smart filter rows: click selects, drag onto another smart object moves, ⌥-drag copies, drag onto Delete removes | done | `smart_ui.rs`, `layer.smartFilter.transfer` (#4271) |
## Revision history
@@ -226,3 +227,4 @@ Paragraph; the rest open as in-app floating windows.
| 2026-10-11 | minor | Type formatting keys done: ⇧⌘K, U, B, I and /, ⌥↑/↓, ⇧⌥↑/↓, ⌥←/→ over a selection and ⌥⇧⌘H format the selected type while editing, and no longer reach Color Settings, Desaturate, Auto Color or Inverse |
| 2026-10-12 | minor | Pen Auto Add/Delete on the active path, with its options-bar checkbox, hover feedback and + / − cursor badge (#4144) |
| 2026-10-12 | minor | Toolbar tool shortcuts can be reassigned, removed and reset in Keyboard Shortcuts (#4086); capture, restart, group cycling, conflict and text-focus regressions |
+| 2026-10-12 | minor | Smart filter rows can be selected, and dragged (⌥: copied) onto another smart object or onto Delete (#4271) |