diff --git a/crates/automation/src/server.rs b/crates/automation/src/server.rs index f5ccef00c7..1eef187f30 100644 --- a/crates/automation/src/server.rs +++ b/crates/automation/src/server.rs @@ -346,9 +346,10 @@ pub struct UiSetParams { /// dashes, dashOffset and opacity; null disables the stroke). Shape stroke fields use /// `shape.edit` names and units; colour comes from `tools.setColors`. camTransformOnDrop (bool, /// the Content-Aware Move tool's Transform On Drop). tileGrid (bool, a developer overlay of the - /// active layer's storage tiles). layerFilter (an object patching by ("kind", "name" or - /// "mode"), kinds (a list of layer kinds), name (matches part of the layer name) and mode (a - /// blend mode name) for the Layers panel filter). strokeTrace (true, false, "stderr" or "off": + /// active layer's storage tiles). layerFilter (an object patching by ("kind", "name", "mode" + /// or "artboard", which lists the artboards that hold the selected layers), kinds (a list of + /// layer kinds), name (matches part of the layer name) and mode (a blend mode name) for the + /// Layers panel filter). strokeTrace (true, false, "stderr" or "off": /// the stroke latency trace at runtime; a CSV file is set at launch with --stroke-trace, not /// over this channel). updatesOpen (bool, the Help › Check for Updates window). Other fields /// are an error. diff --git a/crates/ui-egui/src/control.rs b/crates/ui-egui/src/control.rs index b85427c6fa..3fcd24498d 100644 --- a/crates/ui-egui/src/control.rs +++ b/crates/ui-egui/src/control.rs @@ -2041,6 +2041,21 @@ mod tests { assert!(app.ui.tool_options.gradient_classic, "invalid mode must not change options"); } + /// The Layers panel's Artboard filter type is drivable; it has no criteria of its own. + #[test] + fn ui_set_drives_the_layers_panel_artboard_filter() { + use crate::layer_filter_ui::FilterBy; + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + let ctx = egui::Context::default(); + let ok = call(&mut app, &ctx, "ui.set", json!({"layerFilter": {"by": "artboard"}})); + assert_eq!(ok["ok"], true, "{ok}"); + assert_eq!(app.ui.layer_filter_by, FilterBy::Artboard); + let bad = call(&mut app, &ctx, "ui.set", json!({"layerFilter": {"by": "artboards"}})); + assert_eq!(bad["ok"], false, "{bad}"); + assert!(bad.to_string().contains("kind, name, mode or artboard"), "{bad}"); + assert_eq!(app.ui.layer_filter_by, FilterBy::Artboard, "a bad value changed nothing"); + } + /// #5048: the Layers panel filter is drivable; a bad field changes nothing. #[test] fn ui_set_drives_the_layers_panel_filter() { diff --git a/crates/ui-egui/src/layer_filter_ui.rs b/crates/ui-egui/src/layer_filter_ui.rs index e933d0c165..275ecf8753 100644 --- a/crates/ui-egui/src/layer_filter_ui.rs +++ b/crates/ui-egui/src/layer_filter_ui.rs @@ -1,10 +1,12 @@ //! The Layers panel's filter row (#5048): a filter-type dropdown, as in Photoshop, then the //! controls for that type. Kind toggles layer kinds, Name matches part of the layer name, Mode -//! picks one blend mode. The criteria live in `UiState` (`layer_filter*`), so the control channel -//! can read and set them. +//! picks one blend mode, Artboard lists only the artboards that hold the selected layers. The +//! criteria live in `UiState` (`layer_filter*`), so the control channel can read and set them. + +use std::collections::HashSet; use photocraft_color::BlendMode; -use photocraft_doc::{Layer, LayerContent}; +use photocraft_doc::{Document, Layer, LayerContent, LayerId}; use serde::{Deserialize, Serialize}; use crate::state::UiState; @@ -18,6 +20,7 @@ pub enum FilterBy { Kind, Name, Mode, + Artboard, } /// The filter criteria, copied out of `UiState` for one frame of the Layers panel. @@ -28,20 +31,43 @@ pub struct Filter { /// As typed; matched trimmed and ignoring case. pub name: String, pub mode: BlendMode, + /// The rows the Artboard filter lists ([`board_rows`]); empty lists every row. + pub board_rows: HashSet, } impl Filter { pub fn of(ui: &UiState) -> Self { - Self { by: ui.layer_filter_by, kinds: ui.layer_filter.clone(), name: ui.layer_filter_name.clone(), 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, + board_rows: HashSet::new(), + } + } + + /// Returns [`Filter::of`] for `app`'s settings, with `board_rows` set to the rows of the + /// artboards that hold the active document's selected layers while the panel filters by + /// Artboard. + pub fn of_app(app: &PhotocraftApp) -> Self { + let mut f = Self::of(&app.ui); + if f.by == FilterBy::Artboard + && let Some(d) = app.session.active() + { + f.board_rows = board_rows(&d.doc, &d.selected_layers()); + } + f } /// Whether the panel is filtered. Like Photoshop, Mode always filters (by Normal at first); - /// Kind and Name only once a kind is toggled or some text is typed. + /// Kind and Name only once a kind is toggled or some text is typed; Artboard only while some + /// layers are selected and each of them is in an artboard. pub fn active(&self) -> bool { match self.by { FilterBy::Kind => !self.kinds.is_empty(), FilterBy::Name => !self.name.trim().is_empty(), FilterBy::Mode => true, + FilterBy::Artboard => !self.board_rows.is_empty(), } } @@ -54,25 +80,54 @@ impl Filter { FilterBy::Kind => self.kinds.iter().any(|k| k == kind(l)), FilterBy::Name => l.name.to_lowercase().contains(&self.name.trim().to_lowercase()), FilterBy::Mode => l.blend == self.mode, + FilterBy::Artboard => self.board_rows.contains(&l.id), } } } +/// The Artboard filter's rows for `selection`: the artboards that hold the selected layers and +/// every layer inside them. The set is empty when nothing is selected or a selected layer is in +/// no artboard, and the panel is then not filtered. The panel lists these rows as its tree does: the contents of a closed +/// group stay hidden until the group is opened (`layer_tree_ui::panel_rows` opens every group only +/// for the types whose matches can sit in a closed group). +pub fn board_rows(doc: &Document, selection: &[LayerId]) -> HashSet { + fn add(l: &Layer, rows: &mut HashSet) { + rows.insert(l.id); + for c in l.children().unwrap_or_default() { + add(c, rows); + } + } + let mut boards = Vec::new(); + for &id in selection { + let Some(board) = doc.artboard_of(id) else { return HashSet::new() }; + if !boards.contains(&board) { + boards.push(board); + } + } + let mut rows = HashSet::new(); + for board in boards { + if let Some(l) = doc.layer(board) { + add(l, &mut rows); + } + } + rows +} + /// The kinds the Kind filter toggles. pub const KINDS: [&str; 5] = ["pixel", "adjustment", "type", "shape", "smart"]; /// `ui.set {layerFilter: {by?, kinds?, name?, mode?}}`: `current` with the given fields replaced, -/// or an error naming the bad field (nothing changes then). `by` is `kind`, `name` or `mode`; -/// `kinds` a list of [`KINDS`]; `mode` a blend mode name such as `Multiply` or `Pass Through`. +/// or an error naming the bad field (nothing changes then). `by` is `kind`, `name`, `mode` or +/// `artboard`; `kinds` a list of [`KINDS`]; `mode` a blend mode name such as `Multiply` or +/// `Pass Through`. Artboard has no criteria of its own: the selected layers pick the artboards. pub fn patched(current: &UiState, v: &serde_json::Value) -> Result { let Some(o) = v.as_object() else { return Err("layerFilter must be an object".into()) }; if let Some(k) = o.keys().find(|k| !["by", "kinds", "name", "mode"].contains(&k.as_str())) { return Err(format!("unknown layerFilter field `{k}` (fields: by, kinds, name, mode)")); } - let mut f = - Filter { by: current.layer_filter_by, kinds: current.layer_filter.clone(), name: current.layer_filter_name.clone(), mode: current.layer_filter_mode }; + let mut f = Filter::of(current); if let Some(by) = o.get("by") { - f.by = serde_json::from_value(by.clone()).map_err(|_| "layerFilter.by must be kind, name or mode".to_string())?; + f.by = serde_json::from_value(by.clone()).map_err(|_| "layerFilter.by must be kind, name, mode or artboard".to_string())?; } if let Some(kinds) = o.get("kinds") { let list = kinds.as_array().ok_or("layerFilter.kinds must be a list")?; @@ -122,7 +177,7 @@ fn kind(l: &Layer) -> &'static str { pub fn bar(app: &mut PhotocraftApp, ui: &mut egui::Ui) { ui.horizontal(|ui| { ui.spacing_mut().item_spacing.x = 2.0; - let by = [(FilterBy::Kind, tl!("Kind")), (FilterBy::Name, tl!("Name")), (FilterBy::Mode, tl!("Mode"))]; + let by = [(FilterBy::Kind, tl!("Kind")), (FilterBy::Name, tl!("Name")), (FilterBy::Mode, tl!("Mode")), (FilterBy::Artboard, tl!("Artboard"))]; widgets::dropdown(ui, "layer-filter-by", &mut app.ui.layer_filter_by, &by, 64.0); ui.add_space(4.0); match app.ui.layer_filter_by { @@ -153,6 +208,8 @@ pub fn bar(app: &mut PhotocraftApp, ui: &mut egui::Ui) { let width = ui.available_width().max(96.0); widgets::dropdown(ui, "layer-filter-mode", &mut app.ui.layer_filter_mode, &modes, width); } + // Artboard has no controls: the selected layers pick the artboards ([`board_rows`]). + FilterBy::Artboard => {} } }); } diff --git a/crates/ui-egui/src/layer_filter_ui_tests.rs b/crates/ui-egui/src/layer_filter_ui_tests.rs index aeeb63e7cc..aa7cb6418b 100644 --- a/crates/ui-egui/src/layer_filter_ui_tests.rs +++ b/crates/ui-egui/src/layer_filter_ui_tests.rs @@ -1,4 +1,4 @@ -//! #5048: the Layers panel's filter-type dropdown (Kind, Name, Mode). +//! #5048: the Layers panel's filter-type dropdown (Kind, Name, Mode, Artboard). use egui::vec2; use egui_kittest::Harness; @@ -135,3 +135,78 @@ fn the_dropdown_switches_the_panel_between_filter_types() { h.run_steps(4); assert_eq!(drawn(&h), ["ink notes"]); } + +/// On a Background: the artboard "Back" holding "Grass", the artboard "Front" holding the group +/// "Trees" with "Oak", and "Loose" in no artboard, on top. +fn boards_session() -> photocraft_engine::Session { + let mut s = photocraft_engine::Session::new(); + s.execute("file.new", json!({"width": 64, "height": 48})).unwrap(); + s.execute("layer.new.layer", json!({"name": "Grass"})).unwrap(); + s.execute("layer.new.artboardFromLayers", json!({"name": "Back"})).unwrap(); + s.execute("layer.new.layer", json!({"name": "Oak"})).unwrap(); + s.execute("layer.groupLayers", json!({"name": "Trees"})).unwrap(); + s.execute("layer.new.artboardFromLayers", json!({"name": "Front"})).unwrap(); + s.execute("layer.new.layer", json!({"name": "Loose"})).unwrap(); + s.execute("layer.setExpanded", json!({"all": true, "expanded": true})).unwrap(); + s +} + +/// The names the Artboard filter lists with the layers `names` selected, every group open. +fn listed_by_artboard(s: &mut photocraft_engine::Session, names: &[&str]) -> Vec { + s.execute("select.deselectLayers", json!({})).unwrap(); + for (i, name) in names.iter().enumerate() { + let id = layer(&s.active().unwrap().doc, name); + s.execute("layer.select", json!({"layer": id, "mode": if i == 0 { "replace" } else { "add" }})).unwrap(); + } + let d = s.active().unwrap(); + let mut f = filter(FilterBy::Artboard, &[], "", BlendMode::Normal); + f.board_rows = super::board_rows(&d.doc, &d.selected_layers()); + listed(&d.doc, &f) +} + +#[test] +fn the_artboard_filter_lists_the_artboards_that_hold_the_selected_layers() { + let mut s = boards_session(); + let all = ["Loose", "Front", "Trees", "Oak", "Back", "Grass", "Background"]; + assert_eq!(listed_by_artboard(&mut s, &[]), all, "nothing selected: every layer"); + // A layer at any depth in an artboard, or the artboard itself: that artboard only. + assert_eq!(listed_by_artboard(&mut s, &["Oak"]), ["Front", "Trees", "Oak"]); + assert_eq!(listed_by_artboard(&mut s, &["Front"]), ["Front", "Trees", "Oak"]); + assert_eq!(listed_by_artboard(&mut s, &["Grass"]), ["Back", "Grass"]); + // Layers in two artboards: both artboards. + assert_eq!(listed_by_artboard(&mut s, &["Oak", "Grass"]), ["Front", "Trees", "Oak", "Back", "Grass"]); + // A selected layer in no artboard: every layer again. + assert_eq!(listed_by_artboard(&mut s, &["Loose"]), all); + assert_eq!(listed_by_artboard(&mut s, &["Oak", "Loose"]), all); + let round = serde_json::to_value(UiState { layer_filter_by: FilterBy::Artboard, ..UiState::default() }).unwrap(); + assert_eq!(round["layer_filter_by"], "artboard"); +} + +#[test] +fn the_artboard_filter_follows_the_selection_in_the_panel() { + let session = boards_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()) + }); + h.run_steps(8); + let all = ["Loose", "Front", "Trees", "Oak", "Back", "Grass", "Background"]; + h.get_by_value("Kind").click(); + h.run_steps(4); + h.query_all_by_label("Artboard").last().expect("Artboard in the open list").click(); + h.run_steps(4); + assert_eq!(h.state().ui.layer_filter_by, FilterBy::Artboard); + assert_eq!(drawn(&h), all, "Loose, in no artboard, is selected: every layer"); + let oak = layer(&h.state().session.active().unwrap().doc, "Oak"); + h.state_mut().session.execute("layer.select", json!({"layer": oak})).unwrap(); + h.run_steps(4); + assert_eq!(drawn(&h), ["Front", "Trees", "Oak"]); + // The artboard's tree as the panel shows it: a closed group keeps its contents hidden. + let trees = layer(&h.state().session.active().unwrap().doc, "Trees"); + h.state_mut().session.execute("layer.setExpanded", json!({"layer": trees, "expanded": false})).unwrap(); + h.run_steps(4); + assert_eq!(drawn(&h), ["Front", "Trees"]); + h.state_mut().session.execute("select.deselectLayers", json!({})).unwrap(); + h.run_steps(4); + assert_eq!(drawn(&h), ["Loose", "Front", "Trees", "Back", "Grass", "Background"], "nothing selected: every row"); +} diff --git a/crates/ui-egui/src/panels.rs b/crates/ui-egui/src/panels.rs index b6bd34d9d2..f8dc2b563b 100644 --- a/crates/ui-egui/src/panels.rs +++ b/crates/ui-egui/src/panels.rs @@ -2714,7 +2714,7 @@ fn layers(app: &mut PhotocraftApp, ui: &mut egui::Ui) { ui.scroll_with_delta(vec2(0.0, delta)); ctx.request_repaint(); } - let filter = crate::layer_filter_ui::Filter::of(&app.ui); + let filter = crate::layer_filter_ui::Filter::of_app(app); let fx_collapsed = app.session.active().map(|d| d.fx_collapsed.clone()).unwrap_or_default(); crate::layer_row_ui::begin(ui.ctx()); // The drawn rows, top to bottom (#1721): the space between them and below the last diff --git a/docs/control-protocol.md b/docs/control-protocol.md index 3d4d601b30..6a2e32aa02 100644 --- a/docs/control-protocol.md +++ b/docs/control-protocol.md @@ -54,7 +54,7 @@ The transport is `apps/photocraft/src/control_server.rs`, and the handlers are i - `ui.set` also accepts `camTransformOnDrop` (boolean), the Content-Aware Move tool's Transform On Drop checkbox: a drop then puts a scale/rotate box on the patch (`ui.inspect` › `camTransform`: its document/revision, drag `offset` and `frame`), driven with `ui.pointer` (handles as Free Transform's; outside the box rotates), committed with `ui.key Enter` (one `paint.contentAwareMove` with `scaleX`, `scaleY`, `rotate`) or dropped with `Escape`. - `ui.set` also accepts `tileGrid` (boolean), a developer overlay of the active layer's storage tiles: the tile grid over the document, every stored tile filled and labelled `tx,ty`, tiles with identical pixels in a shared colour and unique ones in blue. It has no menu item and View › Extras doesn't hide it. `ui.inspect` reports it as `view.tile_grid`. - `ui.set` also accepts `strokeTrace` (`true`, `false`, `"stderr"` or `"off"`): turn the stroke latency trace on or off at runtime; each stroke's summary is in `ui.inspect` `perf.strokeTrace`. A CSV file of every frame is set only at launch (`PHOTOCRAFT_STROKE_TRACE=` / `--stroke-trace `): the control channel doesn't write files outside the automation write root -- `ui.set` also accepts `layerFilter` (#5048), the Layers panel filter row: `{by?, kinds?, name?, mode?}`, any subset. `by` is `kind`, `name` or `mode` (the filter-type dropdown); `kinds` lists the Kind toggles that are on (`pixel`, `adjustment`, `type`, `shape`, `smart`); `name` matches part of a layer name, ignoring case; `mode` is a blend mode name (`Multiply`, `Pass Through`). Kind and Name filter only once a kind is on or text is typed; Mode always filters, by Normal at first, as in Photoshop. Fields left out keep their value; a bad one is an error and changes nothing. +- `ui.set` also accepts `layerFilter` (#5048), the Layers panel filter row: `{by?, kinds?, name?, mode?}`, any subset. `by` is `kind`, `name`, `mode` or `artboard` (the filter-type dropdown); `kinds` lists the Kind toggles that are on (`pixel`, `adjustment`, `type`, `shape`, `smart`); `name` matches part of a layer name, ignoring case; `mode` is a blend mode name (`Multiply`, `Pass Through`). Kind and Name filter only once a kind is on or text is typed; Mode always filters, by Normal at first, as in Photoshop. Artboard has no field of its own: it lists the artboards that hold the selected layers, with everything inside them (closed groups stay closed), and does not filter when nothing is selected or a selected layer is in no artboard. Fields left out keep their value; a bad one is an error and changes nothing. - Each painting tool keeps its own brush, as in Photoshop: `tools.setBrush` and `ui.set {brushSize}` change the active tool's brush, and switching tools swaps in that tool's own (size, hardness, mode, opacity, flow, dynamics, smoothing). A tool used for the first time starts from the brush in hand. The colours, the erase flag and the stroke seed stay shared. So `ui.set {tool: "eraser", brushSize: 12}` sets the Eraser's size, and `ui.set {tool: "brush"}` afterwards brings the Brush's own size back. - Brush Pose's `pose.overrideTiltX` and `pose.overrideTiltY` are independent booleans. For example, `engine.execute {"command":"tools.setBrush","params":{"pose":{"enabled":true,"tiltX":45,"overrideTiltX":true,"overrideTiltY":false}}}` fixes X at 45° while Y follows the stylus. Pose tilts are degrees (±90); the Brush Settings panel displays percentages (±100). Old stored `overrideTilt` values migrate to both axes. In command patches, `overrideTilt` sets both axes unless an explicit axis field in the same patch overrides it. `brush.get` includes both axis flags and the legacy combined readback (`overrideTilt` is true only when both flags are true). Axis-only journals omit that derived combined key so replay retains the other axis. Present flag values must be booleans; null and other types return an error. - `ui.set` also accepts the Eyedropper options bar (#1649): `eyedropperSampleSize` (`"point"` or 1, 3, 5, 11, 31, 51, 101: the side of the averaged square, shared by the Eyedropper, a painting tool's Alt-click eyedropper, the Curves/Color Picker eyedroppers and the Info panel), `eyedropperSample` (`current`, `currentAndBelow`, `all`, `allNoAdjustments`, `currentAndBelowNoAdjustments`) and `eyedropperRing` (boolean, Show Sampling Ring). `ui.inspect` reports them under `toolOptions` (`eyedropper_size`, `eyedropper_sample`, `eyedropper_ring`). The engine command `document.sampleColor {x, y, size, sampleLayer}` returns the colour such a sample picks, as four floats 0..1 (not 0..255). diff --git a/docs/ui-parity.md b/docs/ui-parity.md index 8a189ad491..2049d14612 100644 --- a/docs/ui-parity.md +++ b/docs/ui-parity.md @@ -234,7 +234,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 | -| Layers panel filter-type dropdown (Kind, Name, Effect, Mode, Attribute, Color, Smart Object, Selected, Artboard) | partial | Kind, Name and Mode; the other six missing. `layer_filter_ui.rs`, `ui.set {layerFilter}` (#5048) | +| Layers panel filter-type dropdown (Kind, Name, Effect, Mode, Attribute, Color, Smart Object, Selected, Artboard) | partial | Kind, Name, Mode and Artboard; the other five missing. `layer_filter_ui.rs`, `ui.set {layerFilter}` (#5048) | | Adjustment scope: clipping control visible above tall Properties editors in a compact dock | done (2026-10-21) | `panels.rs`, `clipping_indicator_tests.rs`; #5231; stack-wide default retained | | Smart filter rows: click selects, drag onto another smart object moves, ⌥-drag copies, drag onto Delete removes; with a row selected, the Delete button and the ⌫/Delete key remove that filter, not the smart object | done | `smart_ui.rs`, `layer.smartFilter.transfer` (#4271), `smart_ui::keys` (#4751) | | Layers panel: Clip Thumbnails to Layer Bounds (panel menu, `interface.clipThumbnailsToLayerBounds`) | done (2026-10-12) | `layer_thumb_bounds_tests.rs`; #4281. Thumbnail size and the Panel Options dialog to come | @@ -292,6 +292,7 @@ Paragraph; the rest open as in-app floating windows. | 2026-10-14 | minor | Move › Show Transform Controls frames every selected layer and outlines the selected shapes | | 2026-10-21 | minor | Crop rows corrected against the code and the scorecard: saved custom crop presets (TOOL-214-9, #2723) and Delete Cropped Pixels off are done (#6562); no percentage changed | | 2026-10-20 | minor | Free Transform of an artboard child omits ancestor paper from the covering and isolated composites while retaining board clipping. The base canvas and whole-artboard backgrounds are preserved; synthetic regressions in `transform_tool.rs`. No parity percentage changed. | +| 2026-10-24 | minor | Layers panel filter row: Artboard lists only the artboards that hold the selected layers, and the unfiltered tree when nothing is selected or a selected layer is in no artboard; drivable by `ui.set {layerFilter: {by: "artboard"}}`; no percentage changed | | 2026-10-18 | minor | Move tool: dragging selected pixels shrinks the marching ants to the moved pixels as the drag starts, and the dropped selection is theirs, as in Photoshop (#7538) | | 2026-10-18 | minor | Marching ants drawn in device pixels like Photoshop's: equally thick on every edge at 125 %/150 % display scale, thicker on HiDPI, slanted dash ends (#7489) | | 2026-10-16 | minor | View › Extras (⌘H) hides the Move tool's transform controls and their handles stop responding; ⌘H again restores them, and Show Transform Controls keeps its setting (#6699) |