Skip to content

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

Layers panel: dragging the vector mask to the Trash asks to delete just the mask (#3119) (#3125)

Valentin Klein6d08ae64006f
diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs
index f90a990d3..cf139aaed 100644
--- a/crates/ui-egui/src/dialogs.rs
+++ b/crates/ui-egui/src/dialogs.rs
@@ -316,7 +316,7 @@ pub fn show(app: &mut PhotocraftApp, ctx: &egui::Context) {
let clicked = if d.kind == DialogKind::Command && crate::prefs_ui::is_preferences(&fields) {
let changed = crate::prefs_ui::preferences_changed(app, &fields);
dialog_buttons(ui, &[ok, cancel, DialogButton::new(ButtonRole::Apply, tl!("Apply"), 84.0).enabled(changed)])
- } else if crate::mask_trash_prompt::owns(&fields) {
+ } else if crate::mask_trash_prompt::owns(&fields) && !crate::mask_trash_prompt::is_vector(&fields) {
// Photoshop: Apply / Cancel / Delete. Delete answers with the choice set.
let apply = DialogButton::new(ButtonRole::Default, tl!("Apply"), 84.0).enabled(crate::mask_trash_prompt::can_apply(&fields));
let delete = DialogButton::new(ButtonRole::Alternate, tl!("Delete"), 84.0);
diff --git a/crates/ui-egui/src/i18n/cs.tsv b/crates/ui-egui/src/i18n/cs.tsv
index 5c9b84666..1fe086a2c 100644
--- a/crates/ui-egui/src/i18n/cs.tsv
+++ b/crates/ui-egui/src/i18n/cs.tsv
@@ -3649,3 +3649,4 @@ navigator Zoom Zvětšení
(No neutral color exists for {mode} mode.) (Pro režim {mode} neexistuje neutrální barva.)
Apply mask to layer before removing? Použít masku na vrstvu před odstraněním?
The layer or its mask changed. Drag the mask onto the Trash again. Vrstva nebo její maska se změnila. Přetáhněte masku do koše znovu.
+ Delete the vector mask? Odstranit vektorovou masku?
diff --git a/crates/ui-egui/src/i18n/de.tsv b/crates/ui-egui/src/i18n/de.tsv
index a7bfaee5d..df62b59c1 100644
--- a/crates/ui-egui/src/i18n/de.tsv
+++ b/crates/ui-egui/src/i18n/de.tsv
@@ -2652,3 +2652,4 @@ cameraData Lens Objektiv
(No neutral color exists for {mode} mode.) (Für den Modus {mode} gibt es keine neutrale Farbe.)
Apply mask to layer before removing? Maske vor dem Entfernen auf die Ebene anwenden?
The layer or its mask changed. Drag the mask onto the Trash again. Die Ebene oder ihre Maske hat sich geändert. Ziehen Sie die Maske erneut in den Papierkorb.
+ Delete the vector mask? Vektormaske löschen?
diff --git a/crates/ui-egui/src/i18n/el.tsv b/crates/ui-egui/src/i18n/el.tsv
index a14b2b1de..0b029e240 100644
--- a/crates/ui-egui/src/i18n/el.tsv
+++ b/crates/ui-egui/src/i18n/el.tsv
@@ -3712,3 +3712,4 @@ cameraData Lens Φακός
(No neutral color exists for {mode} mode.) (Δεν υπάρχει ουδέτερο χρώμα για τη λειτουργία {mode}.)
Apply mask to layer before removing? Εφαρμογή της μάσκας στο επίπεδο πριν από την αφαίρεση;
The layer or its mask changed. Drag the mask onto the Trash again. Το επίπεδο ή η μάσκα του άλλαξε. Σύρετε ξανά τη μάσκα στον Κάδο.
+ Delete the vector mask? Διαγραφή της διανυσματικής μάσκας;
diff --git a/crates/ui-egui/src/i18n/es.tsv b/crates/ui-egui/src/i18n/es.tsv
index 999d5a562..b76cb612e 100644
--- a/crates/ui-egui/src/i18n/es.tsv
+++ b/crates/ui-egui/src/i18n/es.tsv
@@ -2693,3 +2693,4 @@ cameraData Lens Objetivo
(No neutral color exists for {mode} mode.) (No existe un color neutro para el modo {mode}.)
Apply mask to layer before removing? ¿Aplicar la máscara a la capa antes de eliminarla?
The layer or its mask changed. Drag the mask onto the Trash again. La capa o su máscara ha cambiado. Arrastre de nuevo la máscara a la papelera.
+ Delete the vector mask? ¿Eliminar la máscara vectorial?
diff --git a/crates/ui-egui/src/i18n/fr.tsv b/crates/ui-egui/src/i18n/fr.tsv
index 5c49f95c1..a40efe6d4 100644
--- a/crates/ui-egui/src/i18n/fr.tsv
+++ b/crates/ui-egui/src/i18n/fr.tsv
@@ -3030,3 +3030,4 @@ cameraData Lens Objectif
(No neutral color exists for {mode} mode.) (Il n’existe aucune couleur neutre pour le mode {mode}.)
Apply mask to layer before removing? Appliquer le masque au calque avant de le supprimer ?
The layer or its mask changed. Drag the mask onto the Trash again. Le calque ou son masque a changé. Faites de nouveau glisser le masque sur la corbeille.
+ Delete the vector mask? Supprimer le masque vectoriel ?
diff --git a/crates/ui-egui/src/i18n/id.tsv b/crates/ui-egui/src/i18n/id.tsv
index c86521f57..af8afbe49 100644
--- a/crates/ui-egui/src/i18n/id.tsv
+++ b/crates/ui-egui/src/i18n/id.tsv
@@ -3017,3 +3017,4 @@ cameraData Lens Lensa
(No neutral color exists for {mode} mode.) (Tidak ada warna netral untuk mode {mode}.)
Apply mask to layer before removing? Terapkan masker ke layer sebelum dihapus?
The layer or its mask changed. Drag the mask onto the Trash again. Layer atau maskernya berubah. Seret masker ke Tempat Sampah lagi.
+ Delete the vector mask? Hapus masker vektor?
diff --git a/crates/ui-egui/src/i18n/it.tsv b/crates/ui-egui/src/i18n/it.tsv
index 351e4cc7a..f1522efe0 100644
--- a/crates/ui-egui/src/i18n/it.tsv
+++ b/crates/ui-egui/src/i18n/it.tsv
@@ -2684,3 +2684,4 @@ cameraData Lens Obiettivo
(No neutral color exists for {mode} mode.) (Non esiste un colore neutro per il metodo {mode}.)
Apply mask to layer before removing? Applicare la maschera al livello prima di rimuoverla?
The layer or its mask changed. Drag the mask onto the Trash again. Il livello o la sua maschera è cambiato. Trascina di nuovo la maschera nel cestino.
+ Delete the vector mask? Eliminare la maschera vettoriale?
diff --git a/crates/ui-egui/src/i18n/ja.tsv b/crates/ui-egui/src/i18n/ja.tsv
index 302f28036..f2774bc65 100644
--- a/crates/ui-egui/src/i18n/ja.tsv
+++ b/crates/ui-egui/src/i18n/ja.tsv
@@ -3624,3 +3624,4 @@ cameraData Lens レンズ
(No neutral color exists for {mode} mode.) ({mode} モードには中間色がありません。)
Apply mask to layer before removing? 削除する前にマスクをレイヤーに適用しますか?
The layer or its mask changed. Drag the mask onto the Trash again. レイヤーまたはそのマスクが変更されました。もう一度マスクをゴミ箱にドラッグしてください。
+ Delete the vector mask? ベクトルマスクを削除しますか?
diff --git a/crates/ui-egui/src/i18n/ko.tsv b/crates/ui-egui/src/i18n/ko.tsv
index 0cb8cc8b7..21718cfd9 100644
--- a/crates/ui-egui/src/i18n/ko.tsv
+++ b/crates/ui-egui/src/i18n/ko.tsv
@@ -3197,3 +3197,4 @@ cameraData Lens 렌즈
(No neutral color exists for {mode} mode.) ({mode} 모드에는 중립 색상이 없습니다.)
Apply mask to layer before removing? 제거하기 전에 마스크를 레이어에 적용하시겠습니까?
The layer or its mask changed. Drag the mask onto the Trash again. 레이어 또는 마스크가 변경되었습니다. 마스크를 휴지통으로 다시 드래그하세요.
+ Delete the vector mask? 벡터 마스크를 삭제하시겠습니까?
diff --git a/crates/ui-egui/src/i18n/nl.tsv b/crates/ui-egui/src/i18n/nl.tsv
index 08d91dd69..2be4219f4 100644
--- a/crates/ui-egui/src/i18n/nl.tsv
+++ b/crates/ui-egui/src/i18n/nl.tsv
@@ -3774,3 +3774,4 @@ cameraData Lens Lens
(No neutral color exists for {mode} mode.) (Voor de modus {mode} bestaat geen neutrale kleur.)
Apply mask to layer before removing? Masker toepassen op laag voordat het wordt verwijderd?
The layer or its mask changed. Drag the mask onto the Trash again. De laag of het masker is gewijzigd. Sleep het masker opnieuw naar de prullenbak.
+ Delete the vector mask? Het vectormasker verwijderen?
diff --git a/crates/ui-egui/src/i18n/pl.tsv b/crates/ui-egui/src/i18n/pl.tsv
index eca048a06..55918649f 100644
--- a/crates/ui-egui/src/i18n/pl.tsv
+++ b/crates/ui-egui/src/i18n/pl.tsv
@@ -3626,3 +3626,4 @@ cameraData Lens Obiektyw
(No neutral color exists for {mode} mode.) (Dla trybu {mode} nie istnieje kolor neutralny.)
Apply mask to layer before removing? Zastosować maskę do warstwy przed usunięciem?
The layer or its mask changed. Drag the mask onto the Trash again. Warstwa lub jej maska uległa zmianie. Przeciągnij maskę ponownie do kosza.
+ Delete the vector mask? Usunąć maskę wektorową?
diff --git a/crates/ui-egui/src/i18n/pt-br.tsv b/crates/ui-egui/src/i18n/pt-br.tsv
index 51d250a35..f091f1448 100644
--- a/crates/ui-egui/src/i18n/pt-br.tsv
+++ b/crates/ui-egui/src/i18n/pt-br.tsv
@@ -3804,3 +3804,4 @@ layerLabel No Color Sem cor
(No neutral color exists for {mode} mode.) (Não existe cor neutra para o modo {mode}.)
Apply mask to layer before removing? Aplicar a máscara à camada antes de removê-la?
The layer or its mask changed. Drag the mask onto the Trash again. A camada ou a máscara mudou. Arraste a máscara para a Lixeira novamente.
+ Delete the vector mask? Excluir a máscara vetorial?
diff --git a/crates/ui-egui/src/i18n/ru.tsv b/crates/ui-egui/src/i18n/ru.tsv
index ea4c90e62..8eae98aa6 100644
--- a/crates/ui-egui/src/i18n/ru.tsv
+++ b/crates/ui-egui/src/i18n/ru.tsv
@@ -2959,3 +2959,4 @@ cameraData Lens Объектив
(No neutral color exists for {mode} mode.) (Для режима «{mode}» нет нейтрального цвета.)
Apply mask to layer before removing? Применить маску к слою перед удалением?
The layer or its mask changed. Drag the mask onto the Trash again. Слой или его маска изменились. Перетащите маску в корзину ещё раз.
+ Delete the vector mask? Удалить векторную маску?
diff --git a/crates/ui-egui/src/i18n/uk.tsv b/crates/ui-egui/src/i18n/uk.tsv
index cae6f36b1..f0985f308 100644
--- a/crates/ui-egui/src/i18n/uk.tsv
+++ b/crates/ui-egui/src/i18n/uk.tsv
@@ -3712,3 +3712,4 @@ cameraData Lens Об'єктив
(No neutral color exists for {mode} mode.) (Для режиму «{mode}» немає нейтрального кольору.)
Apply mask to layer before removing? Застосувати маску до шару перед видаленням?
The layer or its mask changed. Drag the mask onto the Trash again. Шар або його маска змінилися. Перетягніть маску до кошика ще раз.
+ Delete the vector mask? Видалити векторну маску?
diff --git a/crates/ui-egui/src/i18n/zh-hans.tsv b/crates/ui-egui/src/i18n/zh-hans.tsv
index e9c12285d..eba8f859f 100644
--- a/crates/ui-egui/src/i18n/zh-hans.tsv
+++ b/crates/ui-egui/src/i18n/zh-hans.tsv
@@ -2632,3 +2632,4 @@ cameraData Lens 镜头
(No neutral color exists for {mode} mode.) ({mode}模式不存在中性色。)
Apply mask to layer before removing? 移去之前将蒙版应用到图层吗?
The layer or its mask changed. Drag the mask onto the Trash again. 图层或其蒙版已更改。请再次将蒙版拖到垃圾桶。
+ Delete the vector mask? 要删除矢量蒙版吗?
diff --git a/crates/ui-egui/src/i18n/zh-hant.tsv b/crates/ui-egui/src/i18n/zh-hant.tsv
index 765e99827..0c742695e 100644
--- a/crates/ui-egui/src/i18n/zh-hant.tsv
+++ b/crates/ui-egui/src/i18n/zh-hant.tsv
@@ -2602,3 +2602,4 @@ cameraData Lens 鏡頭
(No neutral color exists for {mode} mode.) ({mode}模式沒有中性色。)
Apply mask to layer before removing? 移除之前將遮色片套用到圖層嗎?
The layer or its mask changed. Drag the mask onto the Trash again. 圖層或其遮色片已變更。請再次將遮色片拖曳到垃圾桶。
+ Delete the vector mask? 要刪除向量遮色片嗎?
diff --git a/crates/ui-egui/src/mask_thumbs_ui/tests.rs b/crates/ui-egui/src/mask_thumbs_ui/tests.rs
index b3282e826..f5ec70efb 100644
--- a/crates/ui-egui/src/mask_thumbs_ui/tests.rs
+++ b/crates/ui-egui/src/mask_thumbs_ui/tests.rs
@@ -175,7 +175,8 @@ fn dragging_a_layer_row_to_trash_still_deletes_the_layer_with_a_mask_targeted()
let mut h = harness(s, 0, 1.0, 290.0);
let mask = recorded(&h.ctx, masked).unwrap().0.into_iter().find(|(k, _)| *k == MaskKind::Pixel).unwrap().1;
click_with(&mut h, mask.center(), Modifiers::NONE);
- let from = crate::layer_row_ui::recorded(&h.ctx).into_iter().find(|r| r.layer == masked).unwrap().row.center();
+ // Grab the row by its name: its thumbnails drag their masks (#3113, #3119).
+ let from = crate::layer_row_ui::recorded(&h.ctx).into_iter().find(|r| r.layer == masked).unwrap().name.unwrap().center();
let to = h.get_by_label("Delete Layer Mask").rect().center();
h.hover_at(from);
h.run_steps(1);
@@ -243,6 +244,48 @@ fn dragging_the_mask_thumbnail_to_trash_asks_to_apply_or_delete_it() {
assert_eq!(pixels(&h), before);
}
+/// #3119: dragging the vector mask's thumbnail onto the Trash asks "Delete the vector mask?" and
+/// keeps the layer; Cancel keeps the mask, OK deletes only the vector mask in one step.
+#[test]
+fn dragging_the_vector_mask_thumbnail_to_trash_asks_to_delete_just_the_mask() {
+ let (s, masked, _) = session();
+ let mut h = harness(s, 0, 1.0, 290.0);
+ let drag_vector_mask = |h: &mut Harness<'_, PhotocraftApp>| {
+ let from = recorded(&h.ctx, masked).unwrap().0.into_iter().find(|(k, _)| *k == MaskKind::Vector).unwrap().1.center();
+ click_with(h, from, Modifiers::NONE);
+ let to = h.get_by_label("Delete Vector Mask").rect().center();
+ h.hover_at(from);
+ h.run_steps(1);
+ h.event(egui::Event::PointerButton { pos: from, button: PointerButton::Primary, pressed: true, modifiers: Modifiers::NONE });
+ h.run_steps(1);
+ for k in 1..=8 {
+ h.event(egui::Event::PointerMoved(from + (to - from) * (k as f32 / 8.0)));
+ h.run_steps(1);
+ }
+ h.event(egui::Event::PointerButton { pos: to, button: PointerButton::Primary, pressed: false, modifiers: Modifiers::NONE });
+ h.run_steps(3);
+ let st = h.state().session.active().unwrap();
+ assert!(st.doc.layer(photocraft_doc::LayerId(masked)).is_some(), "the layer is not deleted");
+ let d = h.state().ui.dialogs.iter().find(|d| crate::mask_trash_prompt::owns(&d.fields)).expect("the prompt is open");
+ assert_eq!(d.fields["message"], "Delete the vector mask?");
+ assert!(layer(h, masked).vector_mask.is_some(), "nothing changes before the answer");
+ d.id
+ };
+ let past = h.state().session.active().unwrap().history.past_len();
+ // Cancel keeps the vector mask.
+ let dialog = drag_vector_mask(&mut h);
+ crate::dialogs::cancel(h.state_mut(), dialog).unwrap();
+ assert!(layer(&h, masked).vector_mask.is_some());
+ assert_eq!(h.state().session.active().unwrap().history.past_len(), past);
+ // OK: one step, only the vector mask is gone.
+ let dialog = drag_vector_mask(&mut h);
+ crate::dialogs::confirm(h.state_mut(), dialog).unwrap();
+ let after = layer(&h, masked);
+ assert!(after.vector_mask.is_none());
+ assert!(after.mask.is_some(), "the layer mask stays");
+ assert_eq!(h.state().session.active().unwrap().history.past_len(), past + 1);
+}
+
#[test]
fn the_chain_toggles_linking_and_it_survives_psd() {
let (s, masked, _) = session();
diff --git a/crates/ui-egui/src/mask_trash_prompt.rs b/crates/ui-egui/src/mask_trash_prompt.rs
index be49a34ae..4e3b14b85 100644
--- a/crates/ui-egui/src/mask_trash_prompt.rs
+++ b/crates/ui-egui/src/mask_trash_prompt.rs
@@ -1,41 +1,61 @@
-//! A layer mask dragged onto the Layers panel's Trash asks first, as in Photoshop (#3113): "Apply
-//! mask to layer before removing?" Apply runs `layer.layerMask.apply`, Delete
-//! `layer.layerMask.delete`, Cancel keeps the mask. A click on the Trash still deletes the
+//! A mask dragged onto the Layers panel's Trash asks first, as in Photoshop. A layer mask (#3113):
+//! "Apply mask to layer before removing?" Apply runs `layer.layerMask.apply`, Delete
+//! `layer.layerMask.delete`, Cancel keeps the mask. A vector mask (#3119): "Delete the vector
+//! mask?" OK runs `layer.vectorMask.delete`, Cancel keeps it. A click on the Trash still deletes the
//! targeted mask at once (#2197).
//!
//! The prompt is an ordinary dialog in the UI state: `ui.inspect` shows it, `ui.dialog.confirm`
-//! applies, `ui.dialog.set` with `"choice": "delete"` then `ui.dialog.confirm` deletes, and
-//! `ui.dialog.cancel` keeps the mask.
+//! applies (or deletes the vector mask), `ui.dialog.set` with `"choice": "delete"` then
+//! `ui.dialog.confirm` deletes a layer mask, and `ui.dialog.cancel` keeps the mask.
use photocraft_doc::LayerId;
use serde_json::{Map, Value, json};
use crate::PhotocraftApp;
+use crate::mask_thumbs_ui::MaskKind;
use crate::state::DialogKind;
const MARK: &str = "__maskTrash";
+const LAYER_MASK_DELETE: &str = "layer.layerMask.delete";
+const VECTOR_MASK_DELETE: &str = "layer.vectorMask.delete";
pub fn owns(fields: &Map<String, Value>) -> bool {
fields.contains_key(MARK)
}
+/// Is this the vector mask's prompt (OK / Cancel) rather than the layer mask's (Apply / Cancel / Delete)?
+pub fn is_vector(fields: &Map<String, Value>) -> bool {
+ fields.get("kind").and_then(Value::as_str) == Some("vector")
+}
+
/// The action a mask thumbnail dropped on the Trash pushes; [`intercept`] turns it into the prompt.
-pub fn drop_action(layer: u64) -> (String, Value) {
- ("layer.layerMask.delete".into(), json!({"layer": layer, MARK: true}))
+pub fn drop_action(layer: u64, kind: MaskKind) -> (String, Value) {
+ let command = if kind == MaskKind::Vector { VECTOR_MASK_DELETE } else { LAYER_MASK_DELETE };
+ (command.into(), json!({"layer": layer, MARK: true}))
}
/// Opens the prompt for a [`drop_action`]; `None` for every other command.
pub fn intercept(app: &mut PhotocraftApp, command: &str, params: &Value) -> Option<Result<Value, String>> {
- if command != "layer.layerMask.delete" || params.get(MARK).and_then(Value::as_bool) != Some(true) {
+ let vector = match command {
+ LAYER_MASK_DELETE => false,
+ VECTOR_MASK_DELETE => true,
+ _ => return None,
+ };
+ if params.get(MARK).and_then(Value::as_bool) != Some(true) {
return None;
}
let layer = params.get("layer").and_then(Value::as_u64)?;
let state = app.session.active()?;
- state.doc.layer(LayerId(layer)).filter(|l| l.mask.is_some())?;
- // Apply needs a pixel layer (Layer › Layer Mask › Apply is greyed out otherwise).
- let can_apply = app.session.is_enabled_with("layer.layerMask.apply", &json!({"layer": layer}));
- let fields = json!({MARK: true, "__label": "Delete Layer Mask", "message": "Apply mask to layer before removing?",
- "document": state.doc.id.0, "layer": layer, "canApply": can_apply, "choice": if can_apply { "apply" } else { "delete" }});
+ state.doc.layer(LayerId(layer)).filter(|l| if vector { l.vector_mask.is_some() } else { l.mask.is_some() })?;
+ let fields = if vector {
+ json!({MARK: true, "kind": "vector", "__label": "Delete Vector Mask", "message": "Delete the vector mask?",
+ "document": state.doc.id.0, "layer": layer})
+ } else {
+ // Apply needs a pixel layer (Layer › Layer Mask › Apply is greyed out otherwise).
+ let can_apply = app.session.is_enabled_with("layer.layerMask.apply", &json!({"layer": layer}));
+ json!({MARK: true, "kind": "pixel", "__label": "Delete Layer Mask", "message": "Apply mask to layer before removing?",
+ "document": state.doc.id.0, "layer": layer, "canApply": can_apply, "choice": if can_apply { "apply" } else { "delete" }})
+ };
if app.ui.dialogs.iter().any(|d| owns(&d.fields)) {
return Some(Ok(json!({"confirmationPending": true})));
}
@@ -44,7 +64,8 @@ pub fn intercept(app: &mut PhotocraftApp, command: &str, params: &Value) -> Opti
}
pub fn body(ui: &mut egui::Ui, fields: &Map<String, Value>) {
- ui.label(tl!(fields.get("message").and_then(Value::as_str).unwrap_or("Apply mask to layer before removing?")));
+ let fallback = if is_vector(fields) { "Delete the vector mask?" } else { "Apply mask to layer before removing?" };
+ ui.label(tl!(fields.get("message").and_then(Value::as_str).unwrap_or(fallback)));
}
/// Apply is the default button; it's greyed out where the mask can't be applied.
@@ -52,14 +73,23 @@ pub fn can_apply(fields: &Map<String, Value>) -> bool {
fields.get("canApply").and_then(Value::as_bool).unwrap_or(false)
}
-/// Runs the answer: `choice` "delete" deletes the mask, anything else applies it.
+/// Runs the answer: the vector mask is deleted; for a layer mask `choice` "delete" deletes it and
+/// anything else applies it.
pub fn confirm(app: &mut PhotocraftApp, fields: &Map<String, Value>) -> Result<Value, String> {
let state = app.session.active().ok_or(tl!("The document is closed"))?;
+ let vector = is_vector(fields);
let layer = fields.get("layer").and_then(Value::as_u64);
let same = fields.get("document").and_then(Value::as_u64) == Some(state.doc.id.0);
- let Some(layer) = layer.filter(|id| same && state.doc.layer(LayerId(*id)).is_some_and(|l| l.mask.is_some())) else {
+ let has_mask = |l: &photocraft_doc::Layer| if vector { l.vector_mask.is_some() } else { l.mask.is_some() };
+ let Some(layer) = layer.filter(|id| same && state.doc.layer(LayerId(*id)).is_some_and(has_mask)) else {
return Err(tl!("The layer or its mask changed. Drag the mask onto the Trash again.").into());
};
- let command = if fields.get("choice").and_then(Value::as_str) == Some("delete") { "layer.layerMask.delete" } else { "layer.layerMask.apply" };
+ let command = if vector {
+ VECTOR_MASK_DELETE
+ } else if fields.get("choice").and_then(Value::as_str) == Some("delete") {
+ LAYER_MASK_DELETE
+ } else {
+ "layer.layerMask.apply"
+ };
app.run_command(command, json!({"layer": layer}))
}
diff --git a/crates/ui-egui/src/panels.rs b/crates/ui-egui/src/panels.rs
index e38a97886..6a87a8317 100644
--- a/crates/ui-egui/src/panels.rs
+++ b/crates/ui-egui/src/panels.rs
@@ -5,6 +5,7 @@ use photocraft_color::BlendMode;
use photocraft_doc::{Layer, LayerContent, LayerId};
use serde_json::{Value, json};
+use crate::mask_thumbs_ui::MaskKind;
use crate::state::Tool;
use crate::theme::{self, Tokens};
use crate::{PhotocraftApp, icons, widgets};
@@ -2196,7 +2197,7 @@ fn layers(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
// An fx drag that never saw its release (the panel was hidden) must not outlive the button.
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::<u64>(mask_drag_key()));
+ ctx.data_mut(|d| d.remove::<MaskDrag>(mask_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 dragging = held && ctx.input(|i| i.pointer.primary_down());
@@ -2269,20 +2270,21 @@ fn layers(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
let in_selection = selection.iter().any(|s| s.0 == id);
(id, in_selection)
});
- // An effect row can be dropped on Delete too (#3102), and a layer mask's thumbnail (#3113).
+ // 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);
- let mask_footer_drag = ctx.data(|d| d.get_temp::<u64>(mask_drag_key()));
- if mask_footer_drag.is_some()
+ 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())
{
- crate::layer_transfer::ghost(&ctx, p, tl!("Layer Mask"));
+ let label = if kind == MaskKind::Vector { tl!("Vector Mask") } else { tl!("Layer Mask") };
+ crate::layer_transfer::ghost(&ctx, p, label);
}
// End any layer drag after every row has had a chance to accept the drop.
if ctx.input(|i| i.pointer.any_released()) {
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::<u64>(mask_drag_key()));
+ ctx.data_mut(|d| d.remove::<MaskDrag>(mask_drag_key()));
}
widgets::panel_footer(ui, |ui| {
let active_layer = active.and_then(|id| doc.layer(id));
@@ -2302,11 +2304,12 @@ 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));
- // Photoshop asks "Apply mask to layer before removing?" (`mask_trash_prompt`).
- if let Some(layer) = mask_footer_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
&& dropped_on(ui, &trash)
{
- actions.push(crate::mask_trash_prompt::drop_action(layer));
+ actions.push(crate::mask_trash_prompt::drop_action(layer, kind));
}
// A click follows the selected thumbnail; name that action for screen readers even
// though dropping a whole layer row onto the same button always deletes the layer.
@@ -2564,11 +2567,12 @@ fn layer_row(
// Photoshop's default (medium) thumbnails: 32 pt rows.
let row_h = if t.pro { 32.0 } else { 46.0 };
let (rect, resp) = ui.allocate_exact_size(vec2(ui.available_width(), row_h), Sense::click_and_drag());
- // A drag from the layer mask's thumbnail drags the mask, not the layer (#3113).
+ // A drag from a mask's thumbnail drags that mask, not the layer (#3113, #3119).
let mask_drag = starts_mask_drag(ctx, l, &resp);
- if mask_drag {
- ctx.data_mut(|d| d.insert_temp(mask_drag_key(), l.id.0));
+ if let Some(kind) = mask_drag {
+ ctx.data_mut(|d| d.insert_temp::<MaskDrag>(mask_drag_key(), (l.id.0, kind)));
}
+ 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);
if resp.drag_started() && !mask_drag {
@@ -3541,7 +3545,7 @@ fn layer_drag_and_drop(
let t = Tokens::get(ctx);
let key = egui::Id::new("layer-drag");
// A drag from the mask thumbnail (`starts_mask_drag`) moves the mask, not the layer.
- let mask_drag = ctx.data(|d| d.get_temp::<u64>(mask_drag_key())) == Some(l.id.0);
+ let mask_drag = ctx.data(|d| d.get_temp::<MaskDrag>(mask_drag_key())).is_some_and(|(id, _)| id == l.id.0);
if resp.drag_started() && !mask_drag {
ctx.data_mut(|d| d.insert_temp(key, l.id.0));
}
@@ -3661,19 +3665,26 @@ fn layer_drop_zone(
/// row, all of them).
type FxDrag = (u64, Option<usize>);
-/// The layer whose mask thumbnail is being dragged (#3113).
+/// A mask thumbnail being dragged: the layer and which of its masks (#3113, #3119).
+type MaskDrag = (u64, MaskKind);
+
fn mask_drag_key() -> egui::Id {
egui::Id::new("mask-drag")
}
-/// Does the row's drag start on its layer mask's thumbnail (where it was drawn last frame)?
-fn starts_mask_drag(ctx: &egui::Context, l: &Layer, resp: &egui::Response) -> bool {
- if !resp.drag_started() || l.mask.is_none() {
- return false;
+/// Which mask's thumbnail (where it was drawn last frame) the row's drag starts on, if any.
+fn starts_mask_drag(ctx: &egui::Context, l: &Layer, resp: &egui::Response) -> Option<MaskKind> {
+ if !resp.drag_started() {
+ return None;
}
- let Some(p) = ctx.input(|i| i.pointer.press_origin()) else { return false };
- crate::mask_thumbs_ui::recorded(ctx, l.id.0)
- .is_some_and(|(thumbs, _)| thumbs.iter().any(|(k, r)| *k == crate::mask_thumbs_ui::MaskKind::Pixel && r.contains(p)))
+ let p = ctx.input(|i| i.pointer.press_origin())?;
+ let (thumbs, _) = crate::mask_thumbs_ui::recorded(ctx, l.id.0)?;
+ let kind = thumbs.iter().find(|(_, r)| r.contains(p))?.0;
+ let present = match kind {
+ MaskKind::Pixel => l.mask.is_some(),
+ MaskKind::Vector => l.vector_mask.is_some(),
+ };
+ present.then_some(kind)
}
fn fx_drag_key() -> egui::Id {