diff --git a/crates/ui-egui/src/control/tests.rs b/crates/ui-egui/src/control/tests.rs index bfb2bf4f1a..48e958e646 100644 --- a/crates/ui-egui/src/control/tests.rs +++ b/crates/ui-egui/src/control/tests.rs @@ -928,9 +928,9 @@ fn ui_set_drives_the_layers_panel_filter() { let ok = call(&mut app, &ctx, "ui.set", json!({"layerFilter": {"by": "name", "name": "ink"}})); assert_eq!(ok["ok"], true, "{ok}"); assert_eq!((app.ui.layer_filter_by, app.ui.layer_filter_name.as_str()), (FilterBy::Name, "ink")); - let ok = call(&mut app, &ctx, "ui.set", json!({"layerFilter": {"by": "mode", "mode": "Pass Through", "kinds": ["type", "pixel", "type"]}})); + let ok = call(&mut app, &ctx, "ui.set", json!({"layerFilter": {"by": "mode", "mode": "Multiply", "kinds": ["type", "pixel", "type"]}})); assert_eq!(ok["ok"], true, "{ok}"); - assert_eq!((app.ui.layer_filter_by, app.ui.layer_filter_mode), (FilterBy::Mode, photocraft_color::BlendMode::PassThrough)); + assert_eq!((app.ui.layer_filter_by, app.ui.layer_filter_mode), (FilterBy::Mode, photocraft_color::BlendMode::Multiply)); assert_eq!(app.ui.layer_filter, ["type", "pixel"], "kinds are kept once each"); assert_eq!(app.ui.layer_filter_name, "ink", "fields left out keep their value"); for bad in [ @@ -940,6 +940,8 @@ fn ui_set_drives_the_layers_panel_filter() { json!({"layerFilter": {"kinds": "pixel"}}), json!({"layerFilter": {"name": 3}}), json!({"layerFilter": {"mode": "Nonsense"}}), + // The Mode list has no Pass Through (#10878). + json!({"layerFilter": {"mode": "Pass Through"}}), json!({"layerFilter": {"color": "crimson"}}), json!({"layerFilter": {"by": "kind", "extra": true}}), json!({"layerFilter": {"by": "kind"}, "tileGrid": "yes"}), @@ -947,6 +949,7 @@ fn ui_set_drives_the_layers_panel_filter() { let r = call(&mut app, &ctx, "ui.set", bad.clone()); assert_eq!(r["ok"], false, "{bad} → {r}"); assert_eq!(app.ui.layer_filter_by, FilterBy::Mode, "{bad} changed nothing"); + assert_eq!(app.ui.layer_filter_mode, photocraft_color::BlendMode::Multiply, "{bad} left the mode alone"); } // #5898: the Color filter through the same path. let ok = call(&mut app, &ctx, "ui.set", json!({"layerFilter": {"by": "color", "color": "red"}})); diff --git a/crates/ui-egui/src/panels/layer_filter_ui.rs b/crates/ui-egui/src/panels/layer_filter_ui.rs index 047b6d47e9..30d85e3f84 100644 --- a/crates/ui-egui/src/panels/layer_filter_ui.rs +++ b/crates/ui-egui/src/panels/layer_filter_ui.rs @@ -8,7 +8,7 @@ use std::collections::HashSet; use photocraft_color::BlendMode; -use photocraft_doc::{Document, LabelColor, Layer, LayerContent, LayerId, SmartSource}; +use photocraft_doc::{Document, Fill, LabelColor, Layer, LayerContent, LayerId, SmartSource}; use serde::{Deserialize, Serialize}; use crate::state::UiState; @@ -160,10 +160,10 @@ pub const SMART: [&str; 3] = ["linked", "missing", "embedded"]; /// `ui.set {layerFilter: {by?, kinds?, name?, effect?, mode?, color?, smart?}}`: `current` with /// the given fields replaced, or an error naming the bad field (nothing changes then). `by` is /// `kind`, `name`, `effect`, `mode`, `color`, `smartObject` or `artboard`; `kinds` a list of -/// [`KINDS`]; `effect` an [`effect::EffectKind`] id; `mode` a blend mode name such as `Multiply` -/// or `Pass Through`; `color` a label colour id (`none`, `red`, … `gray`, [`LabelColor::id`]); -/// `smart` a list of [`SMART`]. Artboard has no criteria of its own: the selected layers pick the -/// artboards. +/// [`KINDS`]; `effect` an [`effect::EffectKind`] id; `mode` one of the layer blend modes such as +/// `Multiply` (not Pass Through, which the Mode list doesn't offer, #10878); `color` a label colour +/// id (`none`, `red`, … `gray`, [`LabelColor::id`]); `smart` a list of [`SMART`]. 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", "effect", "mode", "color", "smart"].contains(&k.as_str())) { @@ -190,9 +190,10 @@ pub fn patched(current: &UiState, v: &serde_json::Value) -> Result = BlendMode::LAYER_MODES.iter().map(|m| m.label()).collect(); + format!("layerFilter.mode: `{name}` is not a layer blend mode the filter lists (modes: {})", modes.join(", ")) + })?; } if let Some(e) = o.get("effect") { f.effect = effect::parse(e)?; @@ -234,7 +235,11 @@ pub fn apply(ui: &mut UiState, f: Filter) { fn kind(l: &Layer) -> &'static str { match &l.content { LayerContent::Raster(_) => "pixel", - LayerContent::Adjustment(_) | LayerContent::Fill(_) => "adjustment", + LayerContent::Adjustment(_) => "adjustment", + // A fill layer (Layer › New Fill Layer) matches no Kind button, as in the reference + // application, except a solid colour with a vector mask, which lists as a shape (#10878). + LayerContent::Fill(Fill::Solid(_)) if l.vector_mask.is_some() => "shape", + LayerContent::Fill(_) => "", LayerContent::Text(_) => "type", LayerContent::Shape(_) => "shape", LayerContent::Smart(_) => "smart", @@ -282,7 +287,9 @@ pub fn bar(app: &mut PhotocraftApp, ui: &mut egui::Ui) { } FilterBy::Effect => effect::controls(app, ui), FilterBy::Mode => { - let modes: Vec<(BlendMode, &str)> = std::iter::once(BlendMode::PassThrough).chain(BlendMode::LAYER_MODES).map(|m| (m, m.label())).collect(); + // The 27 layer modes, without Pass Through: a group set to Pass Through is never + // listed by Mode (#10878). + let modes: Vec<(BlendMode, &str)> = BlendMode::LAYER_MODES.into_iter().map(|m| (m, m.label())).collect(); let width = ui.available_width().max(96.0); widgets::dropdown(ui, "layer-filter-mode", tl!("Mode"), &mut app.ui.layer_filter_mode, &modes, width); } @@ -325,3 +332,6 @@ mod effect_tests; mod selection_tests; #[cfg(test)] mod tests; + +#[cfg(test)] +mod kind_mode_tests; diff --git a/crates/ui-egui/src/panels/layer_filter_ui/kind_mode_tests.rs b/crates/ui-egui/src/panels/layer_filter_ui/kind_mode_tests.rs new file mode 100644 index 0000000000..260bda8812 --- /dev/null +++ b/crates/ui-egui/src/panels/layer_filter_ui/kind_mode_tests.rs @@ -0,0 +1,117 @@ +//! #10878: the Kind and Mode filters list the same layers as the reference application. Fill +//! layers (solid colour without a vector shape, gradient, pattern) match no Kind button, a solid +//! colour fill with a vector mask lists as a shape, and the Mode list has no Pass Through. + +use photocraft_color::BlendMode; +use photocraft_doc::Document; +use serde_json::json; + +use super::{Filter, FilterBy, KINDS}; +use crate::state::UiState; + +fn new_session() -> photocraft_engine::Session { + let mut s = photocraft_engine::Session::new(); + s.execute("file.new", json!({"width": 64, "height": 48})).unwrap(); + s +} + +/// Make a layer with `cmd`, name it `name` and return its id. +fn make(s: &mut photocraft_engine::Session, cmd: &str, params: serde_json::Value, name: &str) -> u64 { + let id = s.execute(cmd, params).unwrap()["layer"].as_u64().unwrap(); + s.execute("layer.setProps", json!({"layer": id, "name": name})).unwrap(); + id +} + +/// The names `filter` lists, top to bottom. +fn listed(doc: &Document, filter: &Filter) -> Vec { + crate::layer_tree_ui::display_rows(doc, filter.active()).into_iter().filter(|(_, l)| filter.shows(l)).map(|(_, l)| l.name.clone()).collect() +} + +fn kinds(kinds: &[&str]) -> Filter { + Filter::of(&UiState { layer_filter_by: FilterBy::Kind, layer_filter: kinds.iter().map(|k| k.to_string()).collect(), ..UiState::default() }) +} + +fn mode(mode: BlendMode) -> Filter { + Filter::of(&UiState { layer_filter_by: FilterBy::Mode, layer_filter_mode: mode, ..UiState::default() }) +} + +/// Every kind of fill layer, a solid fill with a vector mask, and a Gradient Map adjustment. +fn fills() -> photocraft_engine::Session { + let mut s = new_session(); + make(&mut s, "layer.newFillLayer.solidColor", json!({"color": "#112233"}), "Solid"); + let shaped = make(&mut s, "layer.newFillLayer.solidColor", json!({"color": "#445566"}), "Solid shape"); + s.execute("layer.vectorMask.revealAll", json!({"layer": shaped})).unwrap(); + make(&mut s, "layer.newFillLayer.gradient", json!({}), "Gradient"); + make(&mut s, "layer.newFillLayer.pattern", json!({"pattern": "Checkerboard"}), "Pattern"); + make(&mut s, "layer.newAdjustmentLayer.gradientMap", json!({}), "Gradient Map"); + s +} + +#[test] +fn fill_layers_match_no_kind_button_and_a_shaped_solid_fill_is_a_shape() { + let s = fills(); + let doc = &s.active().unwrap().doc; + // Each button on its own: the measured table, row by row. + assert_eq!(listed(doc, &kinds(&["adjustment"])), ["Gradient Map"], "only the adjustment layer is an adjustment"); + assert_eq!(listed(doc, &kinds(&["shape"])), ["Solid shape"], "a solid fill with a vector mask lists as a shape"); + assert!(listed(doc, &kinds(&["pixel"])).iter().all(|n| n == "Background"), "no fill layer is a pixel layer"); + // With all five buttons on, the plain solid, gradient and pattern fills are still not listed. + let all = listed(doc, &kinds(&KINDS)); + for fill in ["Solid", "Gradient", "Pattern"] { + assert!(!all.iter().any(|n| n == fill), "{fill} matches no Kind button: {all:?}"); + } + assert!(all.iter().any(|n| n == "Solid shape") && all.iter().any(|n| n == "Gradient Map")); +} + +#[test] +fn a_normal_group_is_listed_by_mode_and_a_pass_through_group_never_is() { + let mut s = new_session(); + make(&mut s, "layer.new.layer", json!({}), "Child"); + let normal = s.execute("layer.groupLayers", json!({"name": "Normal group"})).unwrap()["layer"].as_u64().unwrap(); + s.execute("layer.setProps", json!({"layer": normal, "blend": "Normal"})).unwrap(); + let child = { + let doc = &s.active().unwrap().doc; + doc.walk().into_iter().find(|(_, _, l)| l.name == "Child").map(|(_, _, l)| l.id.0).unwrap() + }; + s.execute("layer.setProps", json!({"layer": child, "blend": "Multiply"})).unwrap(); + make(&mut s, "layer.new.layer", json!({}), "Other"); + s.execute("layer.groupLayers", json!({"name": "Pass group"})).unwrap(); + let doc = &s.active().unwrap().doc; + let pass = doc.walk().into_iter().find(|(_, _, l)| l.name == "Pass group").map(|(_, _, l)| l.blend).unwrap(); + assert_eq!(pass, BlendMode::PassThrough, "a new group passes through"); + + let normal_rows = listed(doc, &mode(BlendMode::Normal)); + assert!(normal_rows.iter().any(|n| n == "Normal group"), "a Normal group is listed under Normal: {normal_rows:?}"); + assert!(!normal_rows.iter().any(|n| n == "Child"), "its Multiply child is not"); + assert!(listed(doc, &mode(BlendMode::Multiply)).iter().any(|n| n == "Child"), "a Multiply layer inside a group is listed under Multiply"); + assert!(!normal_rows.iter().any(|n| n == "Pass group"), "a Pass Through group is not"); + for m in BlendMode::LAYER_MODES { + assert!(!listed(doc, &mode(m)).iter().any(|n| n == "Pass group"), "no mode lists the Pass Through group ({m:?})"); + } +} + +#[test] +fn the_mode_filter_takes_no_pass_through() { + let ui = UiState::default(); + let err = super::patched(&ui, &json!({"mode": "Pass Through"})).unwrap_err(); + assert!(err.contains("Pass Through"), "the error names what was asked for: {err}"); + for m in BlendMode::LAYER_MODES { + assert!(err.contains(m.label()), "the error names the valid mode {}: {err}", m.label()); + } + // The 27 layer modes still work. + assert_eq!(BlendMode::LAYER_MODES.len(), 27); + assert_eq!(super::patched(&ui, &json!({"mode": "Multiply"})).unwrap().mode, BlendMode::Multiply); + assert_eq!(super::patched(&ui, &json!({"mode": "Normal"})).unwrap().mode, BlendMode::Normal); +} + +#[test] +fn a_stored_pass_through_filter_mode_loads_as_normal() { + let mut stored = serde_json::to_value(UiState::default()).unwrap(); + stored["layer_filter_mode"] = serde_json::to_value(BlendMode::PassThrough).unwrap(); + let ui: UiState = serde_json::from_value(stored.clone()).unwrap(); + assert_eq!(ui.layer_filter_mode, BlendMode::Normal); + // Any other stored mode is kept as it was. + stored["layer_filter_mode"] = serde_json::to_value(BlendMode::Screen).unwrap(); + let ui: UiState = serde_json::from_value(stored).unwrap(); + assert_eq!(ui.layer_filter_mode, BlendMode::Screen); +} diff --git a/crates/ui-egui/src/state.rs b/crates/ui-egui/src/state.rs index 71cce38f37..2b197a24c0 100644 --- a/crates/ui-egui/src/state.rs +++ b/crates/ui-egui/src/state.rs @@ -16,7 +16,7 @@ pub use panel_state::{ }; pub use tool::Tool; pub use tool_options::{SampleAllLayers, ToolOptions}; -use tool_options::{default_brush_tool, default_layer_filter_mode, yes}; +use tool_options::{default_brush_tool, default_layer_filter_mode, layer_filter_mode_or_normal, yes}; pub use transform::{ BoxResize, CamTransform, ContentAwareOptions, Extras, MadeLayer, TextEdit, TransformMode, TransformSession, TypeInsertionStyle, TypeTransform, }; @@ -365,7 +365,7 @@ pub struct UiState { #[serde(default)] pub layer_filter_name: String, /// Layers panel blend-mode filter. - #[serde(default = "default_layer_filter_mode")] + #[serde(default = "default_layer_filter_mode", deserialize_with = "layer_filter_mode_or_normal")] pub layer_filter_mode: photocraft_color::BlendMode, /// Layers panel effect filter (#10880). #[serde(default)] diff --git a/crates/ui-egui/src/state/tool_options.rs b/crates/ui-egui/src/state/tool_options.rs index bf5303e0d5..36ee1a5036 100644 --- a/crates/ui-egui/src/state/tool_options.rs +++ b/crates/ui-egui/src/state/tool_options.rs @@ -313,6 +313,14 @@ pub(super) fn default_layer_filter_mode() -> photocraft_color::BlendMode { photocraft_color::BlendMode::Normal } +/// A stored Mode filter set to Pass Through, which the Mode list offered until #10878, loads as +/// Normal: Pass Through isn't a mode the filter lists any more. +pub(super) fn layer_filter_mode_or_normal<'de, D: serde::Deserializer<'de>>(d: D) -> Result { + use serde::Deserialize; + let mode = photocraft_color::BlendMode::deserialize(d)?; + Ok(if mode == photocraft_color::BlendMode::PassThrough { photocraft_color::BlendMode::Normal } else { mode }) +} + fn one_u32() -> u32 { 1 } diff --git a/docs/control-protocol.md b/docs/control-protocol.md index 4a3c55d6ec..6cff9f5f2e 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?, effect?, mode?, color?, smart?}`, any subset. `by` is `kind`, `name`, `effect`, `mode`, `color`, `smartObject` 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; `effect` (#10880) is `bevelEmboss`, `stroke`, `innerShadow`, `innerGlow`, `satin`, `overlay` (Color, Gradient or Pattern Overlay), `outerGlow` or `dropShadow`, and lists the layers with that effect turned on; `mode` is a blend mode name (`Multiply`, `Pass Through`); `color` is a layer colour label id (`none`, `red`, `orange`, `yellow`, `green`, `seafoam`, `blue`, `indigo`, `magenta`, `fuchsia`, `violet`, `gray`; #5898); `smart` lists the Smart Object toggles that are on (`linked`: linked to a file, `missing`: linked to a file that was not there when the app last looked, `embedded`). Kind, Name and Smart Object filter only once a toggle is on or text is typed; Effect, Mode and Color always filter, by Bevel & Emboss, by Normal and by no colour 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. +- `ui.set` also accepts `layerFilter` (#5048), the Layers panel filter row: `{by?, kinds?, name?, effect?, mode?, color?, smart?}`, any subset. `by` is `kind`, `name`, `effect`, `mode`, `color`, `smartObject` 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; `effect` (#10880) is `bevelEmboss`, `stroke`, `innerShadow`, `innerGlow`, `satin`, `overlay` (Color, Gradient or Pattern Overlay), `outerGlow` or `dropShadow`, and lists the layers with that effect turned on; `mode` is one of the 27 layer blend modes (`Multiply`, `Screen`), not Pass Through, which the Mode list doesn't offer (#10878); `color` is a layer colour label id (`none`, `red`, `orange`, `yellow`, `green`, `seafoam`, `blue`, `indigo`, `magenta`, `fuchsia`, `violet`, `gray`; #5898); `smart` lists the Smart Object toggles that are on (`linked`: linked to a file, `missing`: linked to a file that was not there when the app last looked, `embedded`). Kind, Name and Smart Object filter only once a toggle is on or text is typed; Effect, Mode and Color always filter, by Bevel & Emboss, by Normal and by no colour 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. - `ui.set` also accepts the Histogram panel: `histogramPanel` `{view?, channel?, showChannelsInColor?, showStatistics?, source?}` (any subset, kept with the preferences): `view` is `compact`, `expanded` or `allChannels`; `channel` is `composite`, `red`, `green`, `blue`, `cyan`, `magenta`, `yellow`, `black`, `a`, `b`, `luminosity` or `colors` (one the document's mode lacks shows as its composite); `source` is `entireImage`, `selectedLayer` or `adjustmentComposite` (Entire Image is counted in Compact View, when the document has one layer, or when no adjustment layer is selected for Adjustment Composite). `histogramRange` is `[from, to]` (levels 0..255) or `null`: the dragged tonal range whose Count and Percentile the statistics show. `histogramRefresh: true` is Uncached Refresh: the current state is recounted at cache level 1. `ui.inspect` › `histogram` reports the options, the channel and source as they apply, the channels the document offers, whether the shown histogram is `current` (counted for the document's revision, source and cache level the panel wants now), its `cacheLevel`, `maxCacheLevel` (Preferences › Performance › Cache Levels), `preview` (an adjustment's preview is counted) and `stats` (`mean`, `stdDev`, `median`, `pixels`, `level`, `count`, `percentile`, `clipped` percent at 0 and 255). Histograms are counted while the panel is shown. - 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.