PhotoCraft: An open-source, photo editor written by scratch in pure Rust
fix(layers): mark adjustment layers kept as imported but not rendered (#6541)
VishnuByrrajud04871b5fd52
diff --git a/crates/engine/src/commands.rs b/crates/engine/src/commands.rsindex 9b4d4a747..5168de4ec 100644--- a/crates/engine/src/commands.rs+++ b/crates/engine/src/commands.rs@@ -1584,6 +1584,7 @@ pub fn adjustment_kind(a: &Adjustment) -> &'static str {Adjustment::GradientMap { .. } => "gradientMap",Adjustment::SelectiveColor { .. } => "selectiveColor",Adjustment::ColorLookup { .. } => "colorLookup",+ Adjustment::Unsupported { .. } => "unsupported",_ => "invert",}}diff --git a/crates/engine/src/inspect.rs b/crates/engine/src/inspect.rsindex 6068503ae..005c42885 100644--- a/crates/engine/src/inspect.rs+++ b/crates/engine/src/inspect.rs@@ -2,7 +2,7 @@use std::collections::HashMap;-use photocraft_doc::{Layer, LayerContent, SmartContentsId, SmartSource};+use photocraft_doc::{Adjustment, Layer, LayerContent, SmartContentsId, SmartSource};use serde_json::{Value, json};use crate::{DocState, Session};@@ -118,6 +118,11 @@ fn layer_sel(l: &Layer, selected: &[photocraft_doc::LayerId], instances: &HashMa// The same kind and parameters the adjustment commands take (`inBlack` 0..255, …),// not the internal model.v["adjustment"] = json!({"kind": crate::commands::adjustment_kind(a), "params": crate::adjust_params::to_params(a)});+ // Kept as imported and never rendered (#6541): agents and the Layers panel can tell.+ if let Adjustment::Unsupported { psd_key, .. } = a {+ v["adjustment"]["unsupported"] = json!(true);+ v["adjustment"]["psdKey"] = json!(psd_key);+ }}LayerContent::Smart(sm) => {v["smartFilters"] = Value::Array(@@ -210,6 +215,32 @@ mod tests {assert!(!adj.to_string().contains('_'), "{adj}");}+ /// #6541: an adjustment PhotoCraft keeps but cannot render is reported as such, not as an Invert.+ #[test]+ fn an_unsupported_adjustment_layer_is_reported_as_kept_not_rendered() {+ let mut s = Session::new();+ s.execute("file.new", json!({"width": 4, "height": 4})).unwrap();+ s.execute("layer.newAdjustmentLayer.invert", json!({})).unwrap();+ s.edit("unsupported fixture", |doc, active| {+ let l = Layer::new("Mystery", LayerContent::Adjustment(Adjustment::Unsupported { psd_key: "xyzw".into(), raw: vec![1, 2, 3] }));+ let id = l.id;+ doc.layers.push(l);+ *active = Some(id);+ Ok(())+ })+ .unwrap();+ let info = s.execute("document.inspect", json!({})).unwrap();+ let layers = info["layers"].as_array().unwrap();+ let unsupported = &layers[0]["adjustment"];+ assert_eq!(unsupported["kind"], "unsupported", "{unsupported}");+ assert_eq!(unsupported["unsupported"], json!(true));+ assert_eq!(unsupported["psdKey"], "xyzw");+ // A real Invert reports neither flag.+ let invert = &layers[1]["adjustment"];+ assert_eq!(invert["kind"], "invert");+ assert!(invert.get("unsupported").is_none(), "{invert}");+ }+#[test]fn document_inspect_reports_raster_and_vector_masks_when_nested() {let cases = [(false, None), (true, None), (false, Some(true)), (false, Some(false)), (true, Some(true))];diff --git a/crates/ui-egui/src/i18n/cs.tsv b/crates/ui-egui/src/i18n/cs.tsvindex 15879f60d..afd743a97 100644--- a/crates/ui-egui/src/i18n/cs.tsv+++ b/crates/ui-egui/src/i18n/cs.tsv@@ -3864,3 +3864,4 @@ navigator Zoom Zvětšení# Graphics Adapter preference (#1885)GPU adapter Adaptér GPU+ Not rendered: this adjustment ({key}) is kept as imported. Nevykresleno: tato úprava ({key}) je ponechána tak, jak byla importována.diff --git a/crates/ui-egui/src/i18n/de.tsv b/crates/ui-egui/src/i18n/de.tsvindex eb3ca7794..824bd17d9 100644--- a/crates/ui-egui/src/i18n/de.tsv+++ b/crates/ui-egui/src/i18n/de.tsv@@ -3259,3 +3259,4 @@ curves Smooth Glätten# Graphics Adapter preference (#1885)GPU adapter GPU-Adapter+ Not rendered: this adjustment ({key}) is kept as imported. Nicht dargestellt: Diese Einstellung ({key}) wird wie importiert beibehalten.diff --git a/crates/ui-egui/src/i18n/el.tsv b/crates/ui-egui/src/i18n/el.tsvindex bac53b53d..ee1ae3023 100644--- a/crates/ui-egui/src/i18n/el.tsv+++ b/crates/ui-egui/src/i18n/el.tsv@@ -3956,3 +3956,4 @@ curves Smooth Εξομάλυνση# Graphics Adapter preference (#1885)GPU adapter Προσαρμογέας GPU+ Not rendered: this adjustment ({key}) is kept as imported. Δεν αποδίδεται: αυτή η προσαρμογή ({key}) διατηρείται όπως εισήχθη.diff --git a/crates/ui-egui/src/i18n/es.tsv b/crates/ui-egui/src/i18n/es.tsvindex 8629fc3fd..c2461b5c9 100644--- a/crates/ui-egui/src/i18n/es.tsv+++ b/crates/ui-egui/src/i18n/es.tsv@@ -4218,3 +4218,4 @@ navigator Zoom Zoom# Graphics Adapter preference (#1885)GPU adapter Adaptador de GPU+ Not rendered: this adjustment ({key}) is kept as imported. No se renderiza: este ajuste ({key}) se conserva tal como se importó.diff --git a/crates/ui-egui/src/i18n/fr.tsv b/crates/ui-egui/src/i18n/fr.tsvindex fad669a4b..a99cf6c25 100644--- a/crates/ui-egui/src/i18n/fr.tsv+++ b/crates/ui-egui/src/i18n/fr.tsv@@ -3265,3 +3265,4 @@ curves Smooth Lisser# Graphics Adapter preference (#1885)GPU adapter Adaptateur GPU+ Not rendered: this adjustment ({key}) is kept as imported. Non rendu : ce réglage ({key}) est conservé tel qu'importé.diff --git a/crates/ui-egui/src/i18n/hu.tsv b/crates/ui-egui/src/i18n/hu.tsvindex c066f4271..e23044a52 100644--- a/crates/ui-egui/src/i18n/hu.tsv+++ b/crates/ui-egui/src/i18n/hu.tsv@@ -4175,3 +4175,4 @@ cameraRaw Yellow Sárga# Graphics Adapter preference (#1885)GPU adapter GPU-adapter+ Not rendered: this adjustment ({key}) is kept as imported. Nem jelenik meg: ez a korrekció ({key}) importált állapotában marad.diff --git a/crates/ui-egui/src/i18n/id.tsv b/crates/ui-egui/src/i18n/id.tsvindex 9e0012bd6..2bb622bbf 100644--- a/crates/ui-egui/src/i18n/id.tsv+++ b/crates/ui-egui/src/i18n/id.tsv@@ -3252,3 +3252,4 @@ curves Smooth Haluskan# Graphics Adapter preference (#1885)GPU adapter Adaptor GPU+ Not rendered: this adjustment ({key}) is kept as imported. Tidak dirender: penyesuaian ini ({key}) disimpan seperti saat diimpor.diff --git a/crates/ui-egui/src/i18n/it.tsv b/crates/ui-egui/src/i18n/it.tsvindex fe8d4cf8d..5b2cecec0 100644--- a/crates/ui-egui/src/i18n/it.tsv+++ b/crates/ui-egui/src/i18n/it.tsv@@ -4373,3 +4373,4 @@ shape Appearance Aspetto# Graphics Adapter preference (#1885)GPU adapter Adattatore GPU+ Not rendered: this adjustment ({key}) is kept as imported. Non renderizzato: questa regolazione ({key}) viene conservata come importata.diff --git a/crates/ui-egui/src/i18n/ja.tsv b/crates/ui-egui/src/i18n/ja.tsvindex 9b121c4c9..c32e2e2e8 100644--- a/crates/ui-egui/src/i18n/ja.tsv+++ b/crates/ui-egui/src/i18n/ja.tsv@@ -3934,3 +3934,4 @@ curves Smooth スムーズ# Graphics Adapter preference (#1885)GPU adapter GPU アダプター+ Not rendered: this adjustment ({key}) is kept as imported. レンダリングされません: この調整({key})はインポートされたまま保持されます。diff --git a/crates/ui-egui/src/i18n/ko.tsv b/crates/ui-egui/src/i18n/ko.tsvindex dc4bf58c9..b02ee4f1f 100644--- a/crates/ui-egui/src/i18n/ko.tsv+++ b/crates/ui-egui/src/i18n/ko.tsv@@ -3440,3 +3440,4 @@ curves Smooth 매끄럽게# Graphics Adapter preference (#1885)GPU adapter GPU 어댑터+ Not rendered: this adjustment ({key}) is kept as imported. 렌더링되지 않음: 이 조정({key})은 가져온 상태 그대로 유지됩니다.diff --git a/crates/ui-egui/src/i18n/nl.tsv b/crates/ui-egui/src/i18n/nl.tsvindex 7104d69ed..c4a12b56d 100644--- a/crates/ui-egui/src/i18n/nl.tsv+++ b/crates/ui-egui/src/i18n/nl.tsv@@ -4016,3 +4016,4 @@ curves Smooth Vloeiend maken# Graphics Adapter preference (#1885)GPU adapter GPU-adapter+ Not rendered: this adjustment ({key}) is kept as imported. Niet weergegeven: deze aanpassing ({key}) blijft behouden zoals geïmporteerd.diff --git a/crates/ui-egui/src/i18n/pl.tsv b/crates/ui-egui/src/i18n/pl.tsvindex 8abed62ba..61dbd88d5 100644--- a/crates/ui-egui/src/i18n/pl.tsv+++ b/crates/ui-egui/src/i18n/pl.tsv@@ -3856,3 +3856,4 @@ curves Smooth Wygładź# Graphics Adapter preference (#1885)GPU adapter Karta GPU+ Not rendered: this adjustment ({key}) is kept as imported. Nie jest renderowana: ta korekta ({key}) jest zachowana w postaci zaimportowanej.diff --git a/crates/ui-egui/src/i18n/pt-br.tsv b/crates/ui-egui/src/i18n/pt-br.tsvindex b21564e68..9f7a1f955 100644--- a/crates/ui-egui/src/i18n/pt-br.tsv+++ b/crates/ui-egui/src/i18n/pt-br.tsv@@ -4046,3 +4046,4 @@ layerLabel No Color Sem cor# Graphics Adapter preference (#1885)GPU adapter Adaptador de GPU+ Not rendered: this adjustment ({key}) is kept as imported. Não renderizado: este ajuste ({key}) é mantido como foi importado.diff --git a/crates/ui-egui/src/i18n/ru.tsv b/crates/ui-egui/src/i18n/ru.tsvindex ff6fc08de..a9191597b 100644--- a/crates/ui-egui/src/i18n/ru.tsv+++ b/crates/ui-egui/src/i18n/ru.tsv@@ -3231,3 +3231,4 @@ curves Smooth Сгладить# Graphics Adapter preference (#1885)GPU adapter Адаптер GPU+ Not rendered: this adjustment ({key}) is kept as imported. Не отображается: эта коррекция ({key}) сохранена как при импорте.diff --git a/crates/ui-egui/src/i18n/sr.tsv b/crates/ui-egui/src/i18n/sr.tsvindex 9a1ceff63..772965baa 100644--- a/crates/ui-egui/src/i18n/sr.tsv+++ b/crates/ui-egui/src/i18n/sr.tsv@@ -4329,3 +4329,4 @@ shape Appearance Izgled# Graphics Adapter preference (#1885)GPU adapter GPU adapter+ Not rendered: this adjustment ({key}) is kept as imported. Није приказано: ово прилагођавање ({key}) је задржано онако како је увезено.diff --git a/crates/ui-egui/src/i18n/tr.tsv b/crates/ui-egui/src/i18n/tr.tsvindex def688abc..967017ad7 100644--- a/crates/ui-egui/src/i18n/tr.tsv+++ b/crates/ui-egui/src/i18n/tr.tsv@@ -3986,3 +3986,4 @@ cameraData Lens Lens# Graphics Adapter preference (#1885)GPU adapter GPU bağdaştırıcısı+ Not rendered: this adjustment ({key}) is kept as imported. Görüntülenmiyor: bu ayarlama ({key}) içe aktarıldığı gibi korunuyor.diff --git a/crates/ui-egui/src/i18n/uk.tsv b/crates/ui-egui/src/i18n/uk.tsvindex e28ea0008..cd1ea38f6 100644--- a/crates/ui-egui/src/i18n/uk.tsv+++ b/crates/ui-egui/src/i18n/uk.tsv@@ -3965,3 +3965,4 @@ curves Smooth Згладити# Graphics Adapter preference (#1885)GPU adapter Адаптер GPU+ Not rendered: this adjustment ({key}) is kept as imported. Не відображається: це коригування ({key}) збережено як було імпортовано.diff --git a/crates/ui-egui/src/i18n/vi.tsv b/crates/ui-egui/src/i18n/vi.tsvindex 503cc1006..38c691ac7 100644--- a/crates/ui-egui/src/i18n/vi.tsv+++ b/crates/ui-egui/src/i18n/vi.tsv@@ -3744,3 +3744,4 @@ curves Smooth Làm mượt# Graphics Adapter preference (#1885)GPU adapter Bộ điều hợp GPU+ Not rendered: this adjustment ({key}) is kept as imported. Không được kết xuất: điều chỉnh này ({key}) được giữ nguyên như khi nhập.diff --git a/crates/ui-egui/src/i18n/zh-hans.tsv b/crates/ui-egui/src/i18n/zh-hans.tsvindex a030a8885..60ccc49c9 100644--- a/crates/ui-egui/src/i18n/zh-hans.tsv+++ b/crates/ui-egui/src/i18n/zh-hans.tsv@@ -2882,3 +2882,4 @@ curves Smooth 平滑# Graphics Adapter preference (#1885)GPU adapter GPU 适配器+ Not rendered: this adjustment ({key}) is kept as imported. 未渲染:此调整({key})按导入时的原样保留。diff --git a/crates/ui-egui/src/i18n/zh-hant.tsv b/crates/ui-egui/src/i18n/zh-hant.tsvindex 25a05a182..827b2528b 100644--- a/crates/ui-egui/src/i18n/zh-hant.tsv+++ b/crates/ui-egui/src/i18n/zh-hant.tsv@@ -2867,3 +2867,4 @@ curves Smooth 平滑# Graphics Adapter preference (#1885)GPU adapter GPU 介面卡+ Not rendered: this adjustment ({key}) is kept as imported. 未算繪:此調整({key})依匯入時的原樣保留。diff --git a/crates/ui-egui/src/layer_row_ui.rs b/crates/ui-egui/src/layer_row_ui.rsindex 4bed6a7cc..e2cc28297 100644--- a/crates/ui-egui/src/layer_row_ui.rs+++ b/crates/ui-egui/src/layer_row_ui.rs@@ -9,7 +9,7 @@use egui::{Align2, FontId, Galley, Painter, Pos2, Rect, Sense, Shape, Stroke, pos2, vec2};use photocraft_color::BlendMode;-use photocraft_doc::Layer;+use photocraft_doc::{Adjustment, Layer, LayerContent};use serde_json::{Value, json};use std::sync::Arc;@@ -30,6 +30,8 @@ pub const MIN_NAME_W: f32 = 64.0;/// A right-hand row indicator.#[derive(Clone, Copy, Debug, PartialEq, Eq)]pub enum Indicator {+ /// An adjustment PhotoCraft keeps as imported but cannot render (#6541).+ Unsupported,Lock,FxTriangle,Fx,@@ -68,9 +70,21 @@ pub fn layout(row: Rect, name_left: f32, items: &[(Indicator, f32)]) -> (Vec<(In(out, name_right)}+/// The PSD key of the adjustment `l` holds when PhotoCraft keeps it as imported but cannot+/// render it.+pub fn unsupported_key(l: &Layer) -> Option<&str> {+ match &l.content {+ LayerContent::Adjustment(Adjustment::Unsupported { psd_key, .. }) => Some(psd_key),+ _ => None,+ }+}+/// Width the always-shown indicators of `l` take at the row's right (blend label excluded).pub fn reserved_width(l: &Layer) -> f32 {let mut w = RIGHT_PAD;+ if unsupported_key(l).is_some() {+ w += ICON_W + GAP;+ }if l.locks.any() {w += ICON_W + GAP;}@@ -134,6 +148,10 @@ pub fn indicators(let fx_galley = has_fx.then(|| painter.layout_no_wrap("fx".into(), fx_font, t.text_dim));let blend_galley = show_blend.then(|| painter.layout_no_wrap(tl!(l.blend.label()).into(), blend_font, t.text_faint));let mut items = Vec::new();+ let unsupported = unsupported_key(l);+ if unsupported.is_some() {+ items.push((Indicator::Unsupported, ICON_W));+ }if locked {items.push((Indicator::Lock, ICON_W));}@@ -152,6 +170,12 @@ pub fn indicators(let cy = row.center().y;for &(kind, r) in &rects {match kind {+ Indicator::Unsupported => {+ icons::paint(ui, Rect::from_center_size(r.center(), vec2(ICON_W, ICON_W)), "triangle-alert", 12.0, t.warning);+ let key = unsupported.unwrap_or_default();+ let tip = crate::i18n::fmt(tl!("Not rendered: this adjustment ({key}) is kept as imported."), &[("key", key)]);+ ui.interact(r, ui.id().with(("row-unsupported", l.id.0)), Sense::hover()).on_hover_text(tip);+ }Indicator::Lock => icons::paint(ui, Rect::from_center_size(r.center(), vec2(ICON_W, ICON_W)), "lock", 12.0, t.text_faint),Indicator::Link => icons::paint(ui, Rect::from_center_size(r.center(), vec2(ICON_W, ICON_W)), "link-2", 12.0, t.text_faint),Indicator::Fx => {diff --git a/crates/ui-egui/src/panels.rs b/crates/ui-egui/src/panels.rsindex 18cef34c9..59c6e9dd7 100644--- a/crates/ui-egui/src/panels.rs+++ b/crates/ui-egui/src/panels.rs@@ -5285,6 +5285,10 @@ mod layer_pct_slider_tests;#[path = "fx_drag_tests.rs"]mod fx_drag_tests;+#[cfg(test)]+#[path = "unsupported_marker_tests.rs"]+mod unsupported_marker_tests;+#[cfg(test)]mod lock_tests {use super::*;diff --git a/crates/ui-egui/src/unsupported_marker_tests.rs b/crates/ui-egui/src/unsupported_marker_tests.rsnew file mode 100644index 000000000..dc748381e--- /dev/null+++ b/crates/ui-egui/src/unsupported_marker_tests.rs@@ -0,0 +1,42 @@+//! #6541: the Layers panel marks an adjustment layer PhotoCraft keeps as imported but cannot+//! render, so a picture that differs from Photoshop's has a visible reason.++use egui::vec2;+use egui_kittest::Harness;+use photocraft_doc::{Adjustment, Layer, LayerContent, LayerId};+use serde_json::json;++use crate::PhotocraftApp;+use crate::layer_row_ui::{Indicator, RowRects, recorded};++fn row(h: &Harness<'_, PhotocraftApp>, id: LayerId) -> RowRects {+ recorded(&h.ctx).into_iter().find(|r| r.layer == id.0).unwrap()+}++#[test]+fn an_unsupported_adjustment_row_carries_a_warning_marker() {+ let mut s = photocraft_engine::Session::new();+ s.execute("file.new", json!({"width": 64, "height": 48})).unwrap();+ let plain = LayerId(s.execute("layer.new.layer", json!({"name": "plain"})).unwrap()["layer"].as_u64().unwrap());+ let mystery = Layer::new("Mystery", LayerContent::Adjustment(Adjustment::Unsupported { psd_key: "xyzw".into(), raw: vec![1, 2, 3] }));+ let mystery_id = mystery.id;+ s.edit("unsupported fixture", |doc, active| {+ doc.layers.push(mystery);+ *active = Some(mystery_id);+ Ok(())+ })+ .unwrap();+ 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(s, crate::Services::default())+ });+ h.run_steps(8);+ let marked = row(&h, mystery_id);+ assert!(marked.indicators.iter().any(|(k, _)| *k == Indicator::Unsupported), "{:?}", marked.indicators);+ assert!(!row(&h, plain).indicators.iter().any(|(k, _)| *k == Indicator::Unsupported));+ // The marker takes room from the name, never overlaps it.+ let (_, marker) = marked.indicators.iter().find(|(k, _)| *k == Indicator::Unsupported).copied().unwrap();+ if let Some(name) = marked.name {+ assert!(name.right() <= marker.left(), "name {name:?} runs under the marker {marker:?}");+ }+}