PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Keep Layers Panel menu and options; extract sub-row scaling and fill masks
abc2cb44c52a013ad7
diff --git a/crates/engine/src/commands.rs b/crates/engine/src/commands.rsindex ad78fe6df..9bb9ed37d 100644--- a/crates/engine/src/commands.rs+++ b/crates/engine/src/commands.rs@@ -282,7 +282,7 @@ pub(crate) fn layer_panel_option(s: &Session, key: &str, fallback: bool) -> bool/// mask, which makes a Solid Color fill a shape (#1419); without one, the selection becomes its/// layer mask ([`selection_mask`]); without either, a white mask reveals the whole layer (#1768)./// A path that isn't there is an error.-pub(crate) fn mask_new_layer(doc: &Document, l: &mut Layer, p: &Value, cmd: &str, default_mask: bool) -> Result<()> {+pub(crate) fn mask_new_layer(doc: &Document, l: &mut Layer, p: &Value, cmd: &str) -> Result<()> {let path = match p.get("path") {None | Some(Value::Null) => None,Some(Value::String(n)) if crate::vector_cmds::is_work(Some(n)) => Some(doc.work_path.clone().ok_or_else(|| bad(cmd, "no work path"))?),@@ -293,9 +293,7 @@ pub(crate) fn mask_new_layer(doc: &Document, l: &mut Layer, p: &Value, cmd: &str};match path {Some(path) => l.vector_mask = Some(photocraft_doc::VectorMask::new(path)),- None => {- l.mask = selection_mask(doc)?.or_else(|| default_mask.then(LayerMask::reveal_all)).map(|mask| mask_at_depth(mask, doc.depth)).transpose()?;- }+ None => l.mask = Some(mask_at_depth(selection_mask(doc)?.unwrap_or_else(LayerMask::reveal_all), doc.depth)?),}Ok(())}@@ -309,7 +307,7 @@ fn new_adjustment(s: &mut Session, adj: Adjustment, p: &Value, cmd: &str) -> Reslet name = adj.label().to_string();let id = s.edit(&label, |doc, active| {let mut l = Layer::new(doc.next_layer_name(&name), LayerContent::Adjustment(adj));- mask_new_layer(doc, &mut l, p, cmd, true)?;+ mask_new_layer(doc, &mut l, p, cmd)?;let id = doc.insert_above(*active, l);*active = Some(id);Ok(id)@@ -800,11 +798,10 @@ fn build() -> Vec<CommandSpec> {has_doc,|s, p| {let c = color_param(p, "color", s.tools.foreground);- let default_mask = layer_panel_option(s, "useDefaultMasksOnFillLayers", true);let id = s.edit("New Color Fill Layer", |doc, active| {let fill = Fill::Solid(Color::rgba(c[0], c[1], c[2], c[3])).in_mode(doc.mode);let mut l = Layer::new(doc.next_layer_name("Color Fill"), LayerContent::Fill(fill));- mask_new_layer(doc, &mut l, p, "layer.newFillLayer.solidColor", default_mask)?;+ mask_new_layer(doc, &mut l, p, "layer.newFillLayer.solidColor")?;let id = doc.insert_above(*active, l);*active = Some(id);Ok(id)@@ -825,7 +822,6 @@ fn build() -> Vec<CommandSpec> {let angle = f32_or(p, "angle", 90.0);let style = crate::layer_style::gradient_style(p.get("style").and_then(Value::as_str).unwrap_or("linear"));let reverse = p.get("reverse").and_then(Value::as_bool).unwrap_or(false);- let default_mask = layer_panel_option(s, "useDefaultMasksOnFillLayers", true);let id = s.edit("New Gradient Fill Layer", |doc, active| {let fill = Fill::gradient(vec![(0.0, Color::rgba(a[0], a[1], a[2], a[3])), (1.0, Color::rgba(b[0], b[1], b[2], b[3]))],@@ -836,7 +832,7 @@ fn build() -> Vec<CommandSpec> {).in_mode(doc.mode);let mut l = Layer::new(doc.next_layer_name("Gradient Fill"), LayerContent::Fill(fill));- mask_new_layer(doc, &mut l, p, "layer.newFillLayer.gradient", default_mask)?;+ mask_new_layer(doc, &mut l, p, "layer.newFillLayer.gradient")?;let id = doc.insert_above(*active, l);*active = Some(id);Ok(id)diff --git a/crates/engine/src/layer_multi_cmds.rs b/crates/engine/src/layer_multi_cmds.rsindex 654c2c8ec..f5fccfc3a 100644--- a/crates/engine/src/layer_multi_cmds.rs+++ b/crates/engine/src/layer_multi_cmds.rs@@ -2518,19 +2518,6 @@ mod layers_panel_parity_tests {assert!(s.active().unwrap().fx_collapsed.contains(&target));}- #[test]- fn fill_layers_respect_use_default_masks_option() {- let (mut s, _) = new_session();- option(&mut s, "useDefaultMasksOnFillLayers", false);- let new = s.execute("layer.newFillLayer.solidColor", json!({"color": "#112233"})).unwrap();- let id = LayerId(new["layer"].as_u64().unwrap());- assert!(s.active().unwrap().doc.layer(id).unwrap().mask.is_none());- option(&mut s, "useDefaultMasksOnFillLayers", true);- let new = s.execute("layer.newFillLayer.gradient", json!({})).unwrap();- let id = LayerId(new["layer"].as_u64().unwrap());- assert!(s.active().unwrap().doc.layer(id).unwrap().mask.is_some());- }-#[test]fn expand_new_effects_is_view_state_and_keeps_edit_history_clean() {let (mut s, ids) = new_session();diff --git a/crates/engine/src/pattern_cmds.rs b/crates/engine/src/pattern_cmds.rsindex a56590ad2..21bee1283 100644--- a/crates/engine/src/pattern_cmds.rs+++ b/crates/engine/src/pattern_cmds.rs@@ -307,18 +307,12 @@ pub(crate) fn placement(p: &Value) -> (f32, f32, bool, (f32, f32)) {/// The edit of `layer.newFillLayer.pattern`: a Pattern Fill layer of `pat` placed as `p` asks,/// above `active`. The Pattern Fill dialog previews it on a copy of the document.-pub(crate) fn insert_fill_layer(- doc: &mut Document,- active: &mut Option<photocraft_doc::LayerId>,- pat: &Pattern,- p: &Value,- default_mask: bool,-) -> Result<photocraft_doc::LayerId> {+pub(crate) fn insert_fill_layer(doc: &mut Document, active: &mut Option<photocraft_doc::LayerId>, pat: &Pattern, p: &Value) -> Result<photocraft_doc::LayerId> {let (scale, angle, link, phase) = placement(p);ensure_in_doc(doc, pat);let fill = Fill::Pattern { name: pat.name.clone(), scale, id: pat.id.clone(), angle, link, phase };let mut l = Layer::new(doc.next_layer_name("Pattern Fill"), LayerContent::Fill(fill));- crate::commands::mask_new_layer(doc, &mut l, p, "layer.newFillLayer.pattern", default_mask)?;+ crate::commands::mask_new_layer(doc, &mut l, p, "layer.newFillLayer.pattern")?;let id = doc.insert_above(*active, l);*active = Some(id);Ok(id)@@ -326,8 +320,7 @@ pub(crate) fn insert_fill_layer(fn new_fill_layer(s: &mut Session, p: &Value) -> Result<Value> {let pat = resolve_param(s, "layer.newFillLayer.pattern", p)?;- let default_mask = crate::commands::layer_panel_option(s, "useDefaultMasksOnFillLayers", true);- let id = s.edit("New Pattern Fill Layer", |doc, active| insert_fill_layer(doc, active, &pat, p, default_mask))?;+ let id = s.edit("New Pattern Fill Layer", |doc, active| insert_fill_layer(doc, active, &pat, p))?;Ok(json!({"layer": id.0, "pattern": pat.id}))}diff --git a/crates/engine/src/pattern_fill_cmds.rs b/crates/engine/src/pattern_fill_cmds.rsindex 36adffcf0..daa7e9660 100644--- a/crates/engine/src/pattern_fill_cmds.rs+++ b/crates/engine/src/pattern_fill_cmds.rs@@ -124,8 +124,7 @@ pub fn preview(s: &Session, cmd: &str, p: &Value) -> Result<Document> {CREATE => {let pat = crate::pattern_cmds::resolve_param(s, CREATE, p)?;let mut active = st.active_layer;- let default_mask = crate::commands::layer_panel_option(s, "useDefaultMasksOnFillLayers", true);- crate::pattern_cmds::insert_fill_layer(&mut doc, &mut active, &pat, p, default_mask)?;+ crate::pattern_cmds::insert_fill_layer(&mut doc, &mut active, &pat, p)?;}other => return Err(EngineError::BadParams { cmd: other.into(), msg: "no Pattern Fill preview for this command".into() }),}@@ -217,35 +216,6 @@ mod tests {assert!(preview(&s, "edit.fill", &json!({})).is_err());}- #[test]- fn create_preview_and_commit_honor_default_masks_option() {- for depth in [8, 16, 32] {- for default_mask in [false, true] {- let mut s = Session::new();- s.execute("file.new", json!({"width": 40, "height": 30, "depth": depth})).unwrap();- s.edit_prefs(|prefs| {- prefs.dialogs.insert("ui.layersPanelOptions".into(), json!({"useDefaultMasksOnFillLayers": default_mask}));- });- let before = s.active().unwrap().doc.clone();- let count = s.active().unwrap().history.entries().len();- let p = json!({"pattern": "Grid", "scale": 50});- let shown = preview(&s, CREATE, &p).unwrap();- assert!(Arc::ptr_eq(&before, &s.active().unwrap().doc));- assert_eq!(s.active().unwrap().history.entries().len(), count);- let previewed = shown.layers.iter().find(|l| matches!(l.content, LayerContent::Fill(Fill::Pattern { .. }))).unwrap();- assert_eq!(previewed.mask.is_some(), default_mask);- let id = LayerId(s.execute(CREATE, p).unwrap()["layer"].as_u64().unwrap());- let committed = s.active().unwrap().doc.layer(id).unwrap();- assert_eq!(committed.mask, previewed.mask);- assert_eq!(committed.content, previewed.content);- s.undo();- assert_eq!(*s.active().unwrap().doc, *before);- s.redo();- assert_eq!(s.active().unwrap().doc.layer(id).unwrap().mask.is_some(), default_mask);- }- }- }-#[test]fn bad_params_and_targets_are_errors_not_panics() {let (mut s, id) = session(8);diff --git a/crates/ui-egui/src/i18n/cs.tsv b/crates/ui-egui/src/i18n/cs.tsvindex bc0113ebf..bcb7e0070 100644--- a/crates/ui-egui/src/i18n/cs.tsv+++ b/crates/ui-egui/src/i18n/cs.tsv@@ -2594,7 +2594,6 @@ cameraData Lens ObjektivShow Layers Zobrazit vrstvyThumbnail Contents Obsah miniaturThumbnail Size Velikost miniatur- Use Default Masks on Fill Layers Používat výchozí masky u vrstev výplněExpand New Effects Rozbalovat nové efektyAdd “copy” to Copied Layers and Groups Přidávat „kopie“ ke kopírovaným vrstvám a skupinámPreview on canvas when reordering layers Zobrazovat náhled na plátně při změně pořadí vrstevdiff --git a/crates/ui-egui/src/i18n/de.tsv b/crates/ui-egui/src/i18n/de.tsvindex 73d817922..fa5e8d5cb 100644--- a/crates/ui-egui/src/i18n/de.tsv+++ b/crates/ui-egui/src/i18n/de.tsv@@ -2624,7 +2624,6 @@ cameraData Lens ObjektivShow Layers Ebenen einblendenThumbnail Contents MiniaturinhaltThumbnail Size Miniaturgröße- Use Default Masks on Fill Layers Standardmasken für Füllebenen verwendenExpand New Effects Neue Effekte aufklappenAdd “copy” to Copied Layers and Groups „Kopie“ zu kopierten Ebenen und Gruppen hinzufügenPreview on canvas when reordering layers Vorschau auf der Arbeitsfläche beim Neuanordnen von Ebenendiff --git a/crates/ui-egui/src/i18n/el.tsv b/crates/ui-egui/src/i18n/el.tsvindex ed2d9ea23..789a9c7a9 100644--- a/crates/ui-egui/src/i18n/el.tsv+++ b/crates/ui-egui/src/i18n/el.tsv@@ -3681,7 +3681,6 @@ cameraData Lens ΦακόςShow Layers Εμφάνιση επιπέδωνThumbnail Contents Περιεχόμενο μικρογραφιώνThumbnail Size Μέγεθος μικρογραφιών- Use Default Masks on Fill Layers Χρήση προεπιλεγμένων μασκών σε επίπεδα γεμίσματοςExpand New Effects Ανάπτυξη νέων εφέAdd “copy” to Copied Layers and Groups Προσθήκη «αντίγραφο» σε αντιγραμμένα επίπεδα και ομάδεςPreview on canvas when reordering layers Προεπισκόπηση στον καμβά κατά την αναδιάταξη επιπέδωνdiff --git a/crates/ui-egui/src/i18n/es.tsv b/crates/ui-egui/src/i18n/es.tsvindex 7ea34ccc9..a729292a9 100644--- a/crates/ui-egui/src/i18n/es.tsv+++ b/crates/ui-egui/src/i18n/es.tsv@@ -2665,7 +2665,6 @@ cameraData Lens ObjetivoShow Layers Mostrar capasThumbnail Contents Contenido de miniaturasThumbnail Size Tamaño de miniaturas- Use Default Masks on Fill Layers Usar máscaras predeterminadas en capas de rellenoExpand New Effects Expandir nuevos efectosAdd “copy” to Copied Layers and Groups Añadir «copia» a las capas y grupos duplicadosPreview on canvas when reordering layers Previsualizar en el lienzo al reordenar capasdiff --git a/crates/ui-egui/src/i18n/fr.tsv b/crates/ui-egui/src/i18n/fr.tsvindex 846ba14b0..3ee30e25b 100644--- a/crates/ui-egui/src/i18n/fr.tsv+++ b/crates/ui-egui/src/i18n/fr.tsv@@ -3000,7 +3000,6 @@ cameraData Lens ObjectifShow Layers Afficher les calquesThumbnail Contents Contenu des vignettesThumbnail Size Taille des vignettes- Use Default Masks on Fill Layers Utiliser les masques par défaut sur les calques de remplissageExpand New Effects Développer les nouveaux effetsAdd “copy” to Copied Layers and Groups Ajouter « copie » aux calques et groupes dupliquésPreview on canvas when reordering layers Prévisualiser sur la zone de travail lors du réagencement des calquesdiff --git a/crates/ui-egui/src/i18n/id.tsv b/crates/ui-egui/src/i18n/id.tsvindex ec089c2a3..f3b54c243 100644--- a/crates/ui-egui/src/i18n/id.tsv+++ b/crates/ui-egui/src/i18n/id.tsv@@ -2987,7 +2987,6 @@ cameraData Lens LensaShow Layers Tampilkan LapisanThumbnail Contents Isi Gambar MiniThumbnail Size Ukuran Gambar Mini- Use Default Masks on Fill Layers Gunakan Masker Default pada Lapisan IsianExpand New Effects Perluas Efek BaruAdd “copy” to Copied Layers and Groups Tambahkan “salinan” ke Lapisan dan Grup yang DisalinPreview on canvas when reordering layers Pratinjau pada kanvas saat mengurutkan ulang lapisandiff --git a/crates/ui-egui/src/i18n/it.tsv b/crates/ui-egui/src/i18n/it.tsvindex afa0df18f..57332dd07 100644--- a/crates/ui-egui/src/i18n/it.tsv+++ b/crates/ui-egui/src/i18n/it.tsv@@ -2656,7 +2656,6 @@ cameraData Lens ObiettivoShow Layers Mostra livelliThumbnail Contents Contenuto miniatureThumbnail Size Dimensione miniature- Use Default Masks on Fill Layers Usa maschere predefinite sui livelli di riempimentoExpand New Effects Espandi nuovi effettiAdd “copy” to Copied Layers and Groups Aggiungi «copia» ai livelli e ai gruppi duplicatiPreview on canvas when reordering layers Anteprima sulla tela durante il riordino dei livellidiff --git a/crates/ui-egui/src/i18n/ja.tsv b/crates/ui-egui/src/i18n/ja.tsvindex 700f3919e..88fa61f2e 100644--- a/crates/ui-egui/src/i18n/ja.tsv+++ b/crates/ui-egui/src/i18n/ja.tsv@@ -3595,7 +3595,6 @@ cameraData Lens レンズShow Layers レイヤーを表示Thumbnail Contents サムネールの内容Thumbnail Size サムネールのサイズ- Use Default Masks on Fill Layers 塗りつぶしレイヤーにデフォルトのマスクを使用Expand New Effects 新しい効果を展開Add “copy” to Copied Layers and Groups コピーしたレイヤーとグループの名前に「コピー」を追加Preview on canvas when reordering layers レイヤーの並べ替え時にカンバスでプレビューdiff --git a/crates/ui-egui/src/i18n/ko.tsv b/crates/ui-egui/src/i18n/ko.tsvindex e8d6c3ffb..e31501b8d 100644--- a/crates/ui-egui/src/i18n/ko.tsv+++ b/crates/ui-egui/src/i18n/ko.tsv@@ -3167,7 +3167,6 @@ cameraData Lens 렌즈Show Layers 레이어 표시Thumbnail Contents 축소판 내용Thumbnail Size 축소판 크기- Use Default Masks on Fill Layers 칠 레이어에 기본 마스크 사용Expand New Effects 새 효과 펼치기Add “copy” to Copied Layers and Groups 복사한 레이어 및 그룹에 “복사” 추가Preview on canvas when reordering layers 레이어 순서 변경 시 캔버스에서 미리보기diff --git a/crates/ui-egui/src/i18n/nl.tsv b/crates/ui-egui/src/i18n/nl.tsvindex c3dd81b30..fe08dd075 100644--- a/crates/ui-egui/src/i18n/nl.tsv+++ b/crates/ui-egui/src/i18n/nl.tsv@@ -3740,7 +3740,6 @@ cameraData Lens LensShow Layers Lagen tonenThumbnail Contents Inhoud van miniaturenThumbnail Size Grootte van miniaturen- Use Default Masks on Fill Layers Standaardmaskers gebruiken op opvullagenExpand New Effects Nieuwe effecten uitvouwenAdd “copy” to Copied Layers and Groups „kopie” toevoegen aan gekopieerde lagen en groepenPreview on canvas when reordering layers Voorvertoning op canvas bij herschikken van lagendiff --git a/crates/ui-egui/src/i18n/pl.tsv b/crates/ui-egui/src/i18n/pl.tsvindex e273ba32b..3bb0dbe81 100644--- a/crates/ui-egui/src/i18n/pl.tsv+++ b/crates/ui-egui/src/i18n/pl.tsv@@ -3597,7 +3597,6 @@ cameraData Lens ObiektywShow Layers Pokaż warstwyThumbnail Contents Zawartość miniaturekThumbnail Size Rozmiar miniaturek- Use Default Masks on Fill Layers Użyj domyślnych masek na warstwach wypełnieniaExpand New Effects Rozwijaj nowe efektyAdd “copy” to Copied Layers and Groups Dodawaj „kopia” do skopiowanych warstw i grupPreview on canvas when reordering layers Podgląd na obszarze roboczym podczas zmiany kolejności warstwdiff --git a/crates/ui-egui/src/i18n/pt-br.tsv b/crates/ui-egui/src/i18n/pt-br.tsvindex 7365a389d..25331f5f2 100644--- a/crates/ui-egui/src/i18n/pt-br.tsv+++ b/crates/ui-egui/src/i18n/pt-br.tsv@@ -3004,7 +3004,6 @@ cameraData Lens LenteShow Layers Mostrar camadasThumbnail Contents Conteúdo das miniaturasThumbnail Size Tamanho das miniaturas- Use Default Masks on Fill Layers Usar máscaras padrão nas camadas de preenchimentoExpand New Effects Expandir novos efeitosAdd “copy” to Copied Layers and Groups Adicionar “cópia” às camadas e grupos copiadosPreview on canvas when reordering layers Pré-visualizar na tela ao reordenar camadasdiff --git a/crates/ui-egui/src/i18n/ru.tsv b/crates/ui-egui/src/i18n/ru.tsvindex 5a7abd5b4..a36277b34 100644--- a/crates/ui-egui/src/i18n/ru.tsv+++ b/crates/ui-egui/src/i18n/ru.tsv@@ -2923,7 +2923,6 @@ cameraData Lens ОбъективShow Layers Показать слоиThumbnail Contents Содержимое миниатюрThumbnail Size Размер миниатюр- Use Default Masks on Fill Layers Использовать маски по умолчанию для слоёв-заливокExpand New Effects Раскрывать новые эффектыAdd “copy” to Copied Layers and Groups Добавлять «копия» к дублированным слоям и группамPreview on canvas when reordering layers Предпросмотр на холсте при изменении порядка слоёвdiff --git a/crates/ui-egui/src/i18n/uk.tsv b/crates/ui-egui/src/i18n/uk.tsvindex b55771d33..afb006e3b 100644--- a/crates/ui-egui/src/i18n/uk.tsv+++ b/crates/ui-egui/src/i18n/uk.tsv@@ -3671,7 +3671,6 @@ cameraData Lens Об'єктивShow Layers Показати шариThumbnail Contents Вміст мініатюрThumbnail Size Розмір мініатюр- Use Default Masks on Fill Layers Використовувати типові маски для шарів заливкиExpand New Effects Розгортати нові ефектиAdd “copy” to Copied Layers and Groups Додавати «копія» до скопійованих шарів і групPreview on canvas when reordering layers Попередній перегляд на полотні під час зміни порядку шарівdiff --git a/crates/ui-egui/src/i18n/zh-hans.tsv b/crates/ui-egui/src/i18n/zh-hans.tsvindex 27b5e0de6..052f096fb 100644--- a/crates/ui-egui/src/i18n/zh-hans.tsv+++ b/crates/ui-egui/src/i18n/zh-hans.tsv@@ -2595,7 +2595,6 @@ cameraData Lens 镜头Show Layers 显示图层Thumbnail Contents 缩略图内容Thumbnail Size 缩略图大小- Use Default Masks on Fill Layers 在填充图层上使用默认蒙版Expand New Effects 展开新效果Add “copy” to Copied Layers and Groups 为复制的图层和组添加“副本”Preview on canvas when reordering layers 重新排列图层时在画布上预览diff --git a/crates/ui-egui/src/i18n/zh-hant.tsv b/crates/ui-egui/src/i18n/zh-hant.tsvindex b69bd18fd..79a67f681 100644--- a/crates/ui-egui/src/i18n/zh-hant.tsv+++ b/crates/ui-egui/src/i18n/zh-hant.tsv@@ -2565,7 +2565,6 @@ cameraData Lens 鏡頭Show Layers 顯示圖層Thumbnail Contents 縮圖內容Thumbnail Size 縮圖大小- Use Default Masks on Fill Layers 在填色圖層使用預設遮色片Expand New Effects 展開新效果Add “copy” to Copied Layers and Groups 為複製的圖層和群組加上「副本」Preview on canvas when reordering layers 重新排列圖層時在畫布上預覽diff --git a/crates/ui-egui/src/layers_panel_ui.rs b/crates/ui-egui/src/layers_panel_ui.rsindex 181f60adf..43c2df5c0 100644--- a/crates/ui-egui/src/layers_panel_ui.rs+++ b/crates/ui-egui/src/layers_panel_ui.rs@@ -232,8 +232,6 @@ fn options_body(ui: &mut Ui, draft: &mut LayersPanelOptions) {ui.add_space(4.0);});ui.add_space(9.0);- ui.checkbox(&mut draft.use_default_masks_on_fill_layers, tl!("Use Default Masks on Fill Layers"));- ui.add_space(3.0);ui.checkbox(&mut draft.expand_new_effects, tl!("Expand New Effects"));ui.add_space(3.0);ui.checkbox(&mut draft.add_copy_to_copied_layers_and_groups, tl!("Add “copy” to Copied Layers and Groups"));@@ -344,7 +342,6 @@ mod tests {assert_eq!(options.thumbnail_size, LayerThumbnailSize::Medium);assert_eq!(options.thumbnail_contents, LayerThumbnailContents::EntireDocument);assert!(options.show_filters);- assert!(options.use_default_masks_on_fill_layers);assert!(options.expand_new_effects);assert!(options.add_copy_to_copied_layers_and_groups);assert!(options.preview_on_canvas_when_reordering_layers);@@ -384,25 +381,6 @@ mod tests {assert!(restored.layers_panel_dialog.is_none());}- #[test]- fn disabling_default_fill_masks_never_targets_an_absent_mask() {- let mut session = photocraft_engine::Session::new();- session.execute("file.new", json!({"width": 32, "height": 24})).unwrap();- let mut app = PhotocraftApp::new(session, crate::Services::default());- app.ui.layers_panel_options.use_default_masks_on_fill_layers = false;- persist_options(&mut app);- app.run("layer.newFillLayer.solidColor", json!({"color": "#778899"})).unwrap();- let layer = app.session.active().and_then(|st| st.active_layer.and_then(|id| st.doc.layer(id))).unwrap();- assert!(layer.mask.is_none());- assert!(!app.ui.mask_target && !app.ui.vector_mask_target);- app.ui.layers_panel_options.use_default_masks_on_fill_layers = true;- persist_options(&mut app);- app.run("layer.newFillLayer.gradient", json!({})).unwrap();- let layer = app.session.active().and_then(|st| st.active_layer.and_then(|id| st.doc.layer(id))).unwrap();- assert!(layer.mask.is_some());- assert!(app.ui.mask_target);- }-#[test]fn prefs_options_save_and_restore_all_switches() {let mut session = photocraft_engine::Session::new();@@ -412,7 +390,6 @@ mod tests {thumbnail_size: LayerThumbnailSize::Large,thumbnail_contents: LayerThumbnailContents::LayerBounds,show_filters: false,- use_default_masks_on_fill_layers: false,expand_new_effects: false,add_copy_to_copied_layers_and_groups: false,preview_on_canvas_when_reordering_layers: false,diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rsindex 08851883a..843855159 100644--- a/crates/ui-egui/src/lib.rs+++ b/crates/ui-egui/src/lib.rs@@ -954,24 +954,13 @@ impl PhotocraftApp {jobs_ui::run(self, id, params)};let creates_adjustment_or_fill = id.starts_with("layer.newAdjustmentLayer.") || id.starts_with("layer.newFillLayer.");- if r.is_ok() && ADDS_LAYER_MASK.contains(&id) {- // Adding an explicit mask targets it, as in Photoshop (#2166).+ if r.is_ok() && (ADDS_LAYER_MASK.contains(&id) || creates_adjustment_or_fill) {+ // Adding a layer mask targets it, as in Photoshop (#2166).self.ui.mask_target = true;self.ui.vector_mask_target = false;- self.ui.properties_layer = None;- } else if r.is_ok() && creates_adjustment_or_fill {- // Panel Options may suppress a fill layer's default mask. Never target a- // nonexistent mask; an active path creates a vector mask instead.- let masks = self- .session- .active()- .and_then(|st| st.active_layer.and_then(|id| st.doc.layer(id)))- .map(|layer| (layer.mask.is_some(), layer.vector_mask.is_some()))- .unwrap_or((false, false));- self.ui.mask_target = masks.0;- self.ui.vector_mask_target = !masks.0 && masks.1;- // Keep Properties on the new layer contents, as on main (#3369).- self.ui.properties_layer = self.session.active().and_then(|st| st.active_layer).map(|l| l.0);+ // Properties still shows the new adjustment or fill layer's settings, not its mask,+ // as in Photoshop (#3369): clicking the mask thumbnail switches it to the mask.+ self.ui.properties_layer = if creates_adjustment_or_fill { self.session.active().and_then(|st| st.active_layer).map(|l| l.0) } else { None };}if r.is_ok() && id == "select.toWorkPath" {// Make Work Path selects the new work path in the Paths panel, as in Photoshop.diff --git a/crates/ui-egui/src/panels.rs b/crates/ui-egui/src/panels.rsindex 483539ae4..87336ce04 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: usirows.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: usilet 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: usirect.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.rsindex 89b70e927..99deaa60f 100644--- a/crates/ui-egui/src/smart_ui.rs+++ b/crates/ui-egui/src/smart_ui.rs@@ -1,11 +1,10 @@//! 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::{Color32, Rect, Sense, Stroke, pos2, vec2};+use egui::{Align2, 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};@@ -33,18 +32,6 @@ 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)>) {@@ -53,11 +40,10 @@ 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(), row_height), Sense::click());+ let (rect, resp) = ui.allocate_exact_size(vec2(ui.available_width(), 22.0), Sense::click());if resp.hovered() {ui.painter().rect_filled(rect, 0.0, t.hover.gamma_multiply(0.35));}@@ -75,7 +61,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 {@@ -84,24 +70,12 @@ 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() && 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));+ if index.is_none() {+ let sw = Rect::from_center_size(pos2(x - 12.0, rect.center().y), vec2(14.0, 10.0));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);}- 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()));+ 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 });if let Some(i) = index&& resp.double_clicked(){@@ -147,33 +121,3 @@ pub fn confirm_command(fields: &serde_json::Map<String, Value>, 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();- assert!(matches!(session.active().unwrap().doc.layers.last().unwrap().content, LayerContent::Smart(_)));- let mut h = Harness::builder().with_size(vec2(1440.0, 950.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"] {- let rect = h.get_by_label(label).rect();- assert!((rect.height() - expected).abs() < 1.0, "{setting:?}: {label} was {rect:?}, expected {expected}");- }- }- }-}diff --git a/crates/ui-egui/src/state.rs b/crates/ui-egui/src/state.rsindex 9a257c729..4fb519ef6 100644--- a/crates/ui-egui/src/state.rs+++ b/crates/ui-egui/src/state.rs@@ -28,7 +28,6 @@ pub struct LayersPanelOptions {pub thumbnail_size: LayerThumbnailSize,pub thumbnail_contents: LayerThumbnailContents,pub show_filters: bool,- pub use_default_masks_on_fill_layers: bool,pub expand_new_effects: bool,pub add_copy_to_copied_layers_and_groups: bool,pub preview_on_canvas_when_reordering_layers: bool,@@ -41,7 +40,6 @@ impl LayersPanelOptions {thumbnail_size: LayerThumbnailSize::Medium,thumbnail_contents: LayerThumbnailContents::EntireDocument,show_filters: true,- use_default_masks_on_fill_layers: true,expand_new_effects: true,add_copy_to_copied_layers_and_groups: true,preview_on_canvas_when_reordering_layers: true,