From 2d5d90178bff01be90ce991eadb2728b2aa8b152 Mon Sep 17 00:00:00 2001 From: Raghav Krishna Date: Tue, 3 Nov 2026 14:40:36 +0530 Subject: [PATCH] Crop: name the Fill by Delete Cropped Pixels, and show Selection in the preset dropdown The Fill dropdown's first entry now reads Background (default) with Delete Cropped Pixels on, and Transparent (default) with it off, as the reference application does; both keep crop_content_aware false, so only the label changes. Its translations carry over from Background (Default). The crop preset dropdown shows a checked Selection entry above Ratio while the frame is the untouched default frame made from a selection's bounds. It is a label: choosing it changes nothing, and editing the frame or picking a ratio removes it. Tests live in tools/crop_options_labels_tests.rs (#10872). --- crates/ui-egui/src/control/dispatch.rs | 3 +- crates/ui-egui/src/i18n/ar.tsv | 1 + crates/ui-egui/src/i18n/cs.tsv | 1 + crates/ui-egui/src/i18n/da.tsv | 1 + crates/ui-egui/src/i18n/de.tsv | 1 + crates/ui-egui/src/i18n/el.tsv | 1 + crates/ui-egui/src/i18n/es.tsv | 1 + crates/ui-egui/src/i18n/fi.tsv | 1 + crates/ui-egui/src/i18n/fr.tsv | 1 + crates/ui-egui/src/i18n/hu.tsv | 1 + crates/ui-egui/src/i18n/id.tsv | 1 + crates/ui-egui/src/i18n/it.tsv | 1 + crates/ui-egui/src/i18n/ja.tsv | 1 + crates/ui-egui/src/i18n/ko.tsv | 1 + crates/ui-egui/src/i18n/nb.tsv | 1 + crates/ui-egui/src/i18n/nl.tsv | 1 + crates/ui-egui/src/i18n/pl.tsv | 1 + crates/ui-egui/src/i18n/pt-br.tsv | 1 + crates/ui-egui/src/i18n/ru.tsv | 1 + crates/ui-egui/src/i18n/sr.tsv | 1 + crates/ui-egui/src/i18n/sv.tsv | 1 + crates/ui-egui/src/i18n/tr.tsv | 1 + crates/ui-egui/src/i18n/uk.tsv | 1 + crates/ui-egui/src/i18n/vi.tsv | 1 + crates/ui-egui/src/i18n/zh-hans.tsv | 1 + crates/ui-egui/src/i18n/zh-hant.tsv | 1 + crates/ui-egui/src/panels/options_bar.rs | 7 +- crates/ui-egui/src/tools.rs | 3 + .../src/tools/crop_options_labels_tests.rs | 137 ++++++++++++++++++ crates/ui-egui/src/tools/crop_presets.rs | 20 ++- crates/ui-egui/src/tools/crop_ui.rs | 17 ++- docs/control-protocol.md | 2 +- 32 files changed, 208 insertions(+), 6 deletions(-) create mode 100644 crates/ui-egui/src/tools/crop_options_labels_tests.rs diff --git a/crates/ui-egui/src/control/dispatch.rs b/crates/ui-egui/src/control/dispatch.rs index 3c7b22dda0..6aaa64c5f8 100644 --- a/crates/ui-egui/src/control/dispatch.rs +++ b/crates/ui-egui/src/control/dispatch.rs @@ -470,7 +470,8 @@ impl CropSet { let overlay = crop_overlay_param(p)?; let overlay_show = crop_overlay_show_param(p)?; let orientation = crop_orientation_param(p)?; - // The Crop tool's Fill (#3823): "background" (Background (Default)) or "contentAware". + // The Crop tool's Fill (#3823): "background" (Background (default), or Transparent + // (default) with Delete Cropped Pixels off) or "contentAware". let content_aware = crop_fill_param(p)?; // The Crop tool's gear menu: Show Cropped Area and the shield (#1919). let shield = merged_object(&app.ui.tool_options.crop_shield, p.get("cropShield"), "cropShield")?; diff --git a/crates/ui-egui/src/i18n/ar.tsv b/crates/ui-egui/src/i18n/ar.tsv index 0c67a91ec6..e85040dd55 100644 --- a/crates/ui-egui/src/i18n/ar.tsv +++ b/crates/ui-egui/src/i18n/ar.tsv @@ -3281,6 +3281,7 @@ curves Smooth تنعيم Step {step} is waiting for its dialog الخطوة {step} بانتظار مربع الحوار الخاص بها @plural {n} action|{n} actions {n} إجراء|{n} إجراء|{n} إجراءان|{n} إجراءات|{n} إجراءً|{n} إجراء Background (Default) الخلفية (الافتراضية) + Background (default) الخلفية (الافتراضية) Content-Aware Fill تعبئة مراعية للمحتوى # Batch / Image Processor Include All Subfolders تضمين كل المجلدات الفرعية diff --git a/crates/ui-egui/src/i18n/cs.tsv b/crates/ui-egui/src/i18n/cs.tsv index 8cd95ed30d..40d56bca30 100644 --- a/crates/ui-egui/src/i18n/cs.tsv +++ b/crates/ui-egui/src/i18n/cs.tsv @@ -3899,6 +3899,7 @@ navigator Zoom Zvětšení Step {step} is waiting for its dialog Krok {step} čeká na svůj dialog @plural {n} action|{n} actions {n} akce|{n} akce|{n} akcí Background (Default) Pozadí (výchozí) + Background (default) Pozadí (výchozí) Include All Subfolders Zahrnout všechny podsložky Auto Add/Delete Automaticky přidat/odstranit Don't also tick Mirror Image in Print Settings…: the two flips cancel out. Nezapínejte současně zrcadlení v nastavení tisku: obě převrácení se navzájem zruší. diff --git a/crates/ui-egui/src/i18n/da.tsv b/crates/ui-egui/src/i18n/da.tsv index 46e71ed2cf..3e72d5feec 100644 --- a/crates/ui-egui/src/i18n/da.tsv +++ b/crates/ui-egui/src/i18n/da.tsv @@ -3199,6 +3199,7 @@ curves Smooth Udjævn Step {step} is waiting for its dialog Trin {step} venter på sin dialog @plural {n} action|{n} actions {n} handling|{n} handlinger Background (Default) Baggrund (standard) + Background (default) Baggrund (standard) Content-Aware Fill Indholdsbevidst udfyldning # Batch / Image Processor Include All Subfolders Medtag alle undermapper diff --git a/crates/ui-egui/src/i18n/de.tsv b/crates/ui-egui/src/i18n/de.tsv index 45fb326bea..2ab5b10fb6 100644 --- a/crates/ui-egui/src/i18n/de.tsv +++ b/crates/ui-egui/src/i18n/de.tsv @@ -3297,6 +3297,7 @@ curves Smooth Glätten Step {step} is waiting for its dialog Schritt {step} wartet auf seinen Dialog @plural {n} action|{n} actions {n} Aktion|{n} Aktionen Background (Default) Hintergrund (Standard) + Background (default) Hintergrund (Standard) Content-Aware Fill Inhaltsbasiert füllen Include All Subfolders Alle Unterordner einschließen Auto Add/Delete Autom. hinzuf./löschen diff --git a/crates/ui-egui/src/i18n/el.tsv b/crates/ui-egui/src/i18n/el.tsv index 8f20dd6705..fa1b396502 100644 --- a/crates/ui-egui/src/i18n/el.tsv +++ b/crates/ui-egui/src/i18n/el.tsv @@ -3982,6 +3982,7 @@ curves Smooth Εξομάλυνση Step {step} is waiting for its dialog Το βήμα {step} περιμένει το παράθυρο διαλόγου του @plural {n} action|{n} actions {n} ενέργεια|{n} ενέργειες Background (Default) Φόντο (προεπιλογή) + Background (default) Φόντο (προεπιλογή) Include All Subfolders Συμπερίληψη όλων των υποφακέλων Auto Add/Delete Αυτόματη προσθήκη/διαγραφή Don't also tick Mirror Image in Print Settings…: the two flips cancel out. Μην ενεργοποιείτε επίσης τον κατοπτρισμό στις ρυθμίσεις εκτύπωσης: οι δύο αναστροφές αλληλοαναιρούνται. diff --git a/crates/ui-egui/src/i18n/es.tsv b/crates/ui-egui/src/i18n/es.tsv index 6b365ce2be..6af427b4ef 100644 --- a/crates/ui-egui/src/i18n/es.tsv +++ b/crates/ui-egui/src/i18n/es.tsv @@ -4195,6 +4195,7 @@ navigator Zoom Zoom Step {step} is waiting for its dialog El paso {step} está esperando su cuadro de diálogo @plural {n} action|{n} actions {n} acción|{n} acciones Background (Default) Fondo (predeterminado) + Background (default) Fondo (predeterminado) Include All Subfolders Incluir todas las subcarpetas Auto Add/Delete Añadir/eliminar automáticamente Don't also tick Mirror Image in Print Settings…: the two flips cancel out. No actives también Imagen especular en Ajustes de impresión: las dos inversiones se anulan. diff --git a/crates/ui-egui/src/i18n/fi.tsv b/crates/ui-egui/src/i18n/fi.tsv index b08a224b27..ba4a12ad14 100644 --- a/crates/ui-egui/src/i18n/fi.tsv +++ b/crates/ui-egui/src/i18n/fi.tsv @@ -3200,6 +3200,7 @@ curves Smooth Tasoita Step {step} is waiting for its dialog Vaihe {step} odottaa valintaikkunaansa @plural {n} action|{n} actions {n} toiminto|{n} toimintoa Background (Default) Tausta (oletus) + Background (default) Tausta (oletus) Content-Aware Fill Sisältötietoinen täyttö # Batch / Image Processor Include All Subfolders Sisällytä kaikki alikansiot diff --git a/crates/ui-egui/src/i18n/fr.tsv b/crates/ui-egui/src/i18n/fr.tsv index 89bdec45d4..a53afabb79 100644 --- a/crates/ui-egui/src/i18n/fr.tsv +++ b/crates/ui-egui/src/i18n/fr.tsv @@ -3288,6 +3288,7 @@ curves Smooth Lisser Step {step} is waiting for its dialog L’étape {step} attend sa boîte de dialogue @plural {n} action|{n} actions {n} action|{n} actions Background (Default) Arrière-plan (par défaut) + Background (default) Arrière-plan (par défaut) Content-Aware Fill Remplissage d'après le contenu Include All Subfolders Inclure tous les sous-dossiers Auto Add/Delete Ajout/suppr. auto diff --git a/crates/ui-egui/src/i18n/hu.tsv b/crates/ui-egui/src/i18n/hu.tsv index c5a61baed8..646b5b3b77 100644 --- a/crates/ui-egui/src/i18n/hu.tsv +++ b/crates/ui-egui/src/i18n/hu.tsv @@ -3208,6 +3208,7 @@ cameraRaw Yellow Sárga Constrain proportions Arányok megtartása Constraints Megkötések Background (Default) Háttér (alapértelmezett) + Background (default) Háttér (alapértelmezett) Content-Aware Fill Tartalomérzékeny kitöltés Content-Aware Move Tool Tartalomérzékeny mozgatás Contract Szűkítés diff --git a/crates/ui-egui/src/i18n/id.tsv b/crates/ui-egui/src/i18n/id.tsv index e5058af2c9..cdbbc19b75 100644 --- a/crates/ui-egui/src/i18n/id.tsv +++ b/crates/ui-egui/src/i18n/id.tsv @@ -3293,6 +3293,7 @@ curves Smooth Haluskan Step {step} is waiting for its dialog Langkah {step} menunggu dialognya @plural {n} action|{n} actions {n} tindakan Background (Default) Background (Default) + Background (default) Background (Default) Content-Aware Fill Isi Content-Aware Include All Subfolders Sertakan semua subfolder Auto Add/Delete Tambah/Hapus Otomatis diff --git a/crates/ui-egui/src/i18n/it.tsv b/crates/ui-egui/src/i18n/it.tsv index 367c7267f5..c0400d25e4 100644 --- a/crates/ui-egui/src/i18n/it.tsv +++ b/crates/ui-egui/src/i18n/it.tsv @@ -4245,6 +4245,7 @@ navigator Zoom Zoom Step {step} is waiting for its dialog Il passaggio {step} attende la sua finestra di dialogo @plural {n} action|{n} actions {n} azione|{n} azioni Background (Default) Sfondo (predefinito) + Background (default) Sfondo (predefinito) Include All Subfolders Includi tutte le sottocartelle Auto Add/Delete Aggiungi/elimina automaticamente Don't also tick Mirror Image in Print Settings…: the two flips cancel out. Non attivare anche Immagine speculare nelle impostazioni di stampa: le due inversioni si annullano. diff --git a/crates/ui-egui/src/i18n/ja.tsv b/crates/ui-egui/src/i18n/ja.tsv index 2eee5145a2..78ea846de8 100644 --- a/crates/ui-egui/src/i18n/ja.tsv +++ b/crates/ui-egui/src/i18n/ja.tsv @@ -3900,6 +3900,7 @@ curves Smooth スムーズ Step {step} is waiting for its dialog ステップ {step} はダイアログを待っています @plural {n} action|{n} actions アクション {n} 個 Background (Default) 背景(既定) + Background (default) 背景(既定) Include All Subfolders すべてのサブフォルダーを含める Forward Warp 前方ワープ Twirl Clockwise 時計回りに渦巻き diff --git a/crates/ui-egui/src/i18n/ko.tsv b/crates/ui-egui/src/i18n/ko.tsv index 43f7dea83e..6b0aef8d45 100644 --- a/crates/ui-egui/src/i18n/ko.tsv +++ b/crates/ui-egui/src/i18n/ko.tsv @@ -3488,6 +3488,7 @@ curves Smooth 매끄럽게 Step {step} is waiting for its dialog {step}단계가 대화 상자를 기다리고 있습니다 @plural {n} action|{n} actions 액션 {n}개 Background (Default) 배경(기본값) + Background (default) 배경(기본값) Include All Subfolders 모든 하위 폴더 포함 Auto Add/Delete 자동 추가/삭제 Don't also tick Mirror Image in Print Settings…: the two flips cancel out. 인쇄 설정에서도 이미지 반전을 켜지 마세요. 두 번 반전하면 원래대로 돌아갑니다. diff --git a/crates/ui-egui/src/i18n/nb.tsv b/crates/ui-egui/src/i18n/nb.tsv index d7232004b6..7f72f7b98e 100644 --- a/crates/ui-egui/src/i18n/nb.tsv +++ b/crates/ui-egui/src/i18n/nb.tsv @@ -3199,6 +3199,7 @@ curves Smooth Jevn ut Step {step} is waiting for its dialog Trinn {step} venter på dialogen sin @plural {n} action|{n} actions {n} handling|{n} handlinger Background (Default) Bakgrunn (standard) + Background (default) Bakgrunn (standard) Content-Aware Fill Innholdsbasert fyll # Batch / Image Processor Include All Subfolders Ta med alle undermapper diff --git a/crates/ui-egui/src/i18n/nl.tsv b/crates/ui-egui/src/i18n/nl.tsv index 7ad2900a28..2a380e5407 100644 --- a/crates/ui-egui/src/i18n/nl.tsv +++ b/crates/ui-egui/src/i18n/nl.tsv @@ -4041,6 +4041,7 @@ curves Smooth Vloeiend maken Step {step} is waiting for its dialog Stap {step} wacht op zijn dialoogvenster @plural {n} action|{n} actions {n} handeling|{n} handelingen Background (Default) Achtergrond (standaard) + Background (default) Achtergrond (standaard) Include All Subfolders Alle submappen opnemen Auto Add/Delete Automatisch toevoegen/verwijderen Don't also tick Mirror Image in Print Settings…: the two flips cancel out. Schakel niet ook Spiegelbeeld in bij de afdrukinstellingen: de twee spiegelingen heffen elkaar op. diff --git a/crates/ui-egui/src/i18n/pl.tsv b/crates/ui-egui/src/i18n/pl.tsv index fe13d8f177..2a08607c53 100644 --- a/crates/ui-egui/src/i18n/pl.tsv +++ b/crates/ui-egui/src/i18n/pl.tsv @@ -3898,6 +3898,7 @@ curves Smooth Wygładź Step {step} is waiting for its dialog Krok {step} czeka na swoje okno dialogowe @plural {n} action|{n} actions {n} operacja|{n} operacje|{n} operacji Background (Default) Tło (domyślne) + Background (default) Tło (domyślne) Include All Subfolders Uwzględnij wszystkie podfoldery Auto Add/Delete Automatyczne dodawanie/usuwanie Don't also tick Mirror Image in Print Settings…: the two flips cancel out. Nie włączaj też odbicia lustrzanego w ustawieniach druku: oba odbicia wzajemnie się znoszą. diff --git a/crates/ui-egui/src/i18n/pt-br.tsv b/crates/ui-egui/src/i18n/pt-br.tsv index f12a596d1a..5ec84de54b 100644 --- a/crates/ui-egui/src/i18n/pt-br.tsv +++ b/crates/ui-egui/src/i18n/pt-br.tsv @@ -4081,6 +4081,7 @@ layerLabel No Color Sem cor Step {step} is waiting for its dialog A etapa {step} está aguardando sua caixa de diálogo @plural {n} action|{n} actions {n} ação|{n} ações Background (Default) Plano de fundo (padrão) + Background (default) Plano de fundo (padrão) Include All Subfolders Incluir todas as subpastas Auto Add/Delete Adicionar/excluir automaticamente Don't also tick Mirror Image in Print Settings…: the two flips cancel out. Não ative também a imagem espelhada nas configurações de impressão: as duas inversões se anulam. diff --git a/crates/ui-egui/src/i18n/ru.tsv b/crates/ui-egui/src/i18n/ru.tsv index 60f3929e5f..6a3544d2e1 100644 --- a/crates/ui-egui/src/i18n/ru.tsv +++ b/crates/ui-egui/src/i18n/ru.tsv @@ -3245,6 +3245,7 @@ curves Smooth Сгладить Step {step} is waiting for its dialog Шаг {step} ожидает своего диалога @plural {n} action|{n} actions {n} операция|{n} операции|{n} операций Background (Default) Фон (по умолчанию) + Background (default) Фон (по умолчанию) Content-Aware Fill Заливка с учётом содержимого Include All Subfolders Включить все вложенные папки Auto Add/Delete Автодобавление/удаление diff --git a/crates/ui-egui/src/i18n/sr.tsv b/crates/ui-egui/src/i18n/sr.tsv index 2ebc6c2e70..98a1023c3f 100644 --- a/crates/ui-egui/src/i18n/sr.tsv +++ b/crates/ui-egui/src/i18n/sr.tsv @@ -3860,6 +3860,7 @@ layerLabel No Color Bez boje Color Table Tabela boja Conditional Mode Change Uslovna promena režima Background (Default) Pozadina (podrazumevano) + Background (default) Pozadina (podrazumevano) Content-Aware Fill Popuna prema sadržaju Convert to Linked Pretvori u povezani Convert to Profile Pretvori u profil diff --git a/crates/ui-egui/src/i18n/sv.tsv b/crates/ui-egui/src/i18n/sv.tsv index b9c3721765..39a74b3bc0 100644 --- a/crates/ui-egui/src/i18n/sv.tsv +++ b/crates/ui-egui/src/i18n/sv.tsv @@ -3197,6 +3197,7 @@ curves Smooth Jämna ut Step {step} is waiting for its dialog Steg {step} väntar på sin dialogruta @plural {n} action|{n} actions {n} åtgärd|{n} åtgärder Background (Default) Bakgrund (standard) + Background (default) Bakgrund (standard) Content-Aware Fill Innehållsmedveten fyllning # Batch / Image Processor Include All Subfolders Ta med alla undermappar diff --git a/crates/ui-egui/src/i18n/tr.tsv b/crates/ui-egui/src/i18n/tr.tsv index 007d756f89..5768a7e91e 100644 --- a/crates/ui-egui/src/i18n/tr.tsv +++ b/crates/ui-egui/src/i18n/tr.tsv @@ -3374,6 +3374,7 @@ cameraRaw Color Renk Condensed Dar Conditional Mode Change Koşullu Mod Değişikliği Background (Default) Arka plan (varsayılan) + Background (default) Arka plan (varsayılan) Content-Aware Fill İçeriğe Duyarlı Dolgu Convert Frames > Video Layers Kareleri Dönüştür > Video Katmanları Convert to Linked Bağlantılıya Dönüştür diff --git a/crates/ui-egui/src/i18n/uk.tsv b/crates/ui-egui/src/i18n/uk.tsv index 68128b8584..9e940c611c 100644 --- a/crates/ui-egui/src/i18n/uk.tsv +++ b/crates/ui-egui/src/i18n/uk.tsv @@ -3984,6 +3984,7 @@ curves Smooth Згладити Step {step} is waiting for its dialog Крок {step} очікує на свій діалог @plural {n} action|{n} actions {n} операція|{n} операції|{n} операцій Background (Default) Фон (типовий) + Background (default) Фон (типовий) Include All Subfolders Включити всі вкладені папки Auto Add/Delete Автододавання/видалення Don't also tick Mirror Image in Print Settings…: the two flips cancel out. Не вмикайте також дзеркальне відображення в параметрах друку: два відображення скасовують одне одного. diff --git a/crates/ui-egui/src/i18n/vi.tsv b/crates/ui-egui/src/i18n/vi.tsv index d868ab099a..7cf065dfd9 100644 --- a/crates/ui-egui/src/i18n/vi.tsv +++ b/crates/ui-egui/src/i18n/vi.tsv @@ -3744,6 +3744,7 @@ curves Smooth Làm mượt Clear History Xóa lịch sử History Options… Tùy chọn lịch sử… Background (Default) Nền (mặc định) + Background (default) Nền (mặc định) Allow Non-Linear History Cho phép lịch sử không tuyến tính Make Layer Visibility Changes Undoable Cho phép hoàn tác thay đổi hiển thị lớp Presentation Trình bày diff --git a/crates/ui-egui/src/i18n/zh-hans.tsv b/crates/ui-egui/src/i18n/zh-hans.tsv index d9b554acfa..006ce02399 100644 --- a/crates/ui-egui/src/i18n/zh-hans.tsv +++ b/crates/ui-egui/src/i18n/zh-hans.tsv @@ -2938,6 +2938,7 @@ curves Smooth 平滑 Step {step} is waiting for its dialog 步骤 {step} 正在等待其对话框 @plural {n} action|{n} actions {n} 个动作 Background (Default) 背景(默认) + Background (default) 背景(默认) Content-Aware Fill 内容识别填充 Include All Subfolders 包含所有子文件夹 Auto Add/Delete 自动添加/删除 diff --git a/crates/ui-egui/src/i18n/zh-hant.tsv b/crates/ui-egui/src/i18n/zh-hant.tsv index 9379418b9e..3bd2d7e071 100644 --- a/crates/ui-egui/src/i18n/zh-hant.tsv +++ b/crates/ui-egui/src/i18n/zh-hant.tsv @@ -2899,6 +2899,7 @@ curves Smooth 平滑 Step {step} is waiting for its dialog 步驟 {step} 正在等待其對話框 @plural {n} action|{n} actions {n} 個動作 Background (Default) 背景(預設) + Background (default) 背景(預設) Content-Aware Fill 內容感知填滿 Include All Subfolders 包含所有子資料夾 Auto Add/Delete 自動增加/刪除 diff --git a/crates/ui-egui/src/panels/options_bar.rs b/crates/ui-egui/src/panels/options_bar.rs index fc67eccaca..16ddcd5ce9 100644 --- a/crates/ui-egui/src/panels/options_bar.rs +++ b/crates/ui-egui/src/panels/options_bar.rs @@ -508,14 +508,17 @@ fn selection_specific_options(app: &mut PhotocraftApp, ui: &mut egui::Ui, tool: let pick_shield_color = crate::crop_shield::options_button(&mut o.crop_shield, ui); widgets::checkbox(ui, &mut o.crop_delete, tl!("Delete Cropped Pixels")); // Fill: what a turned or extending crop puts where the image doesn't reach - // (#3823). Generative Expand is not offered. + // (#3823). Generative Expand is not offered. The first entry names the outcome as in + // Photoshop: the background colour, or transparency with Delete Cropped Pixels off + // (#10872); both store `crop_content_aware: false`. ui.label(tl!("Fill:")); + let delete_cropped_pixels = o.crop_delete; widgets::dropdown( ui, "crop-fill", tl!("Fill:"), &mut o.crop_content_aware, - &[(false, tl!("Background (Default)")), (true, tl!("Content-Aware Fill"))], + &[(false, crate::crop_ui::fill_label(delete_cropped_pixels)), (true, tl!("Content-Aware Fill"))], 150.0, ); if crate::crop_ui::preset_ratio(app) != before_ratio { diff --git a/crates/ui-egui/src/tools.rs b/crates/ui-egui/src/tools.rs index e15ab5385c..e53d2ecb0b 100644 --- a/crates/ui-egui/src/tools.rs +++ b/crates/ui-egui/src/tools.rs @@ -53,3 +53,6 @@ pub(super) mod type_transform; pub mod vector_ui; pub mod warp_preview; pub mod zoom_tool; + +#[cfg(test)] +mod crop_options_labels_tests; diff --git a/crates/ui-egui/src/tools/crop_options_labels_tests.rs b/crates/ui-egui/src/tools/crop_options_labels_tests.rs new file mode 100644 index 0000000000..905b60aea6 --- /dev/null +++ b/crates/ui-egui/src/tools/crop_options_labels_tests.rs @@ -0,0 +1,137 @@ +//! #10872: the Crop options bar's Fill entry follows Delete Cropped Pixels, and the preset +//! dropdown shows the temporary "Selection" entry while the frame is the untouched selection's. +//! +//! Kept in its own module so the batch that lands the crop-parity items does not touch the shared +//! `tests.rs` files. + +use egui_kittest::Harness; +use photocraft_doc::{Color, ColorMode, Document, SampleType, Size}; +use serde_json::json; + +use crate::state::Tool; +use crate::{PhotocraftApp, Services, crop_presets, crop_ui}; + +fn app() -> PhotocraftApp { + let doc = Document::with_background("crop labels", Size::new(200, 100), ColorMode::Rgb, SampleType::U8, Color::WHITE); + let mut s = photocraft_engine::Session::new(); + s.add_document(doc, None); + let mut app = PhotocraftApp::new(s, Services::default()); + app.ui.tool = Tool::Crop; + app +} + +/// Every text shape the harness drew this frame, popups included. +fn drawn(h: &Harness<'_, State>) -> Vec { + fn collect(shape: &egui::Shape, text: &mut Vec) { + match shape { + egui::Shape::Text(shape) => text.push(shape.galley.job.text.clone()), + egui::Shape::Vec(shapes) => shapes.iter().for_each(|shape| collect(shape, text)), + _ => {} + } + } + let mut text = Vec::new(); + for shape in &h.output().shapes { + collect(&shape.shape, &mut text); + } + text +} + +/// The preset dropdown alone, so the only ComboBox in the harness is ours. +fn dropdown_harness(app: PhotocraftApp) -> Harness<'static, PhotocraftApp> { + Harness::builder().with_size(egui::vec2(460.0, 900.0)).with_max_steps(64).build_ui_state(|ui, app: &mut PhotocraftApp| crop_presets::dropdown(app, ui), app) +} + +#[test] +fn the_fill_label_follows_delete_cropped_pixels() { + assert_eq!(crop_ui::fill_label(true), "Background (default)"); + assert_eq!(crop_ui::fill_label(false), "Transparent (default)"); +} + +#[test] +fn the_options_bar_shows_the_fill_label_for_the_checkbox() { + let mut h = Harness::builder() + .with_size(egui::vec2(1400.0, 300.0)) + .with_max_steps(64) + // The whole options bar has number fields the app itself does not name for accessibility. + .with_accessibility_check(false) + .build_eframe(|cc| { + PhotocraftApp::setup_context(&cc.egui_ctx, Default::default()); + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Services::default()); + app.run("file.new", json!({"name": "crop fill", "width": 200, "height": 100})).expect("new document"); + app.ui.tool = Tool::Crop; + app + }); + h.run_steps(6); + h.state_mut().ui.tool_options.crop_delete = false; + h.run_steps(2); + assert!(drawn(&h).iter().any(|t| t == "Transparent (default)"), "off: {:?}", drawn(&h)); + h.state_mut().ui.tool_options.crop_delete = true; + h.run_steps(2); + assert!(drawn(&h).iter().any(|t| t == "Background (default)"), "on: {:?}", drawn(&h)); +} + +#[test] +fn the_selection_entry_stands_only_on_the_untouched_selection_frame() { + // A selection when the Crop tool is picked: the default frame is its bounds, and the entry + // names it. + let mut selected = app(); + selected.run("select.all", json!({})).expect("select all"); + crop_ui::ensure_frame(&mut selected); + assert!(selected.crop.default_frame && selected.crop.frame_from_selection); + assert!(crop_presets::shows_selection(&selected)); + + // Editing the frame clears the default-frame state, as the first press or drag does. + selected.crop.default_frame = false; + assert!(!crop_presets::shows_selection(&selected)); + + // No selection: the default frame is the whole canvas, which has no Selection entry. + let mut plain = app(); + crop_ui::ensure_frame(&mut plain); + assert!(plain.crop.default_frame && !plain.crop.frame_from_selection); + assert!(!crop_presets::shows_selection(&plain)); + + // Cancelling drops the frame, so the entry goes with it. + let mut cancelled = app(); + cancelled.run("select.all", json!({})).expect("select all"); + crop_ui::ensure_frame(&mut cancelled); + crop_ui::cancel(&mut cancelled); + assert!(!crop_presets::shows_selection(&cancelled)); +} + +/// The dropdown itself lists "Selection" above Ratio while it stands, and not after the frame is +/// edited. +#[test] +fn the_preset_dropdown_lists_selection_while_the_frame_is_the_selections() { + use egui::accesskit::Role; + use egui_kittest::kittest::Queryable; + + let mut selected = app(); + selected.run("select.all", json!({})).expect("select all"); + crop_ui::ensure_frame(&mut selected); + let mut h = dropdown_harness(selected); + h.run(); + h.get_by_role(Role::ComboBox).click(); + h.run(); + assert!(drawn(&h).iter().any(|t| t == "Selection"), "open list: {:?}", drawn(&h)); + + h.state_mut().crop.default_frame = false; + h.run(); + assert!(!drawn(&h).iter().any(|t| t == "Selection"), "edited frame: {:?}", drawn(&h)); +} + +/// A picked ratio takes the check mark instead of the temporary entry. +#[test] +fn a_picked_ratio_hides_the_selection_entry() { + use egui::accesskit::Role; + use egui_kittest::kittest::Queryable; + + let mut selected = app(); + selected.run("select.all", json!({})).expect("select all"); + crop_ui::ensure_frame(&mut selected); + selected.ui.tool_options.crop_ratio = "1:1".into(); + let mut h = dropdown_harness(selected); + h.run(); + h.get_by_role(Role::ComboBox).click(); + h.run(); + assert!(!drawn(&h).iter().any(|t| t == "Selection"), "a picked ratio: {:?}", drawn(&h)); +} diff --git a/crates/ui-egui/src/tools/crop_presets.rs b/crates/ui-egui/src/tools/crop_presets.rs index 85077aea88..05cb9a1e87 100644 --- a/crates/ui-egui/src/tools/crop_presets.rs +++ b/crates/ui-egui/src/tools/crop_presets.rs @@ -37,6 +37,9 @@ const KEYS: [&str; 5] = ["crop_ratio", "crop_width", "crop_height", "crop_resolu /// One entry of the preset dropdown (and of the Crop tool's canvas menu). #[derive(Clone, Debug, PartialEq)] pub(crate) enum Choice { + /// The temporary "Selection" entry (#10872): the untouched frame came from a selection's + /// bounds. Picking it changes nothing; it labels the frame the crop is still showing. + Selection, /// A built-in key (`crop_ratio` value, size preset or Front Image), see [`crop_size::chosen`]. Builtin(String), /// A saved crop preset, by name. @@ -132,11 +135,21 @@ fn button_label(o: &ToolOptions, builtin: &[(String, &'static str)], users: &[(S tl!(label).to_string() } +/// Whether the preset dropdown shows its temporary "Selection" entry (#10872): the frame is the +/// untouched default one and it came from a selection's bounds. Editing the frame clears +/// `default_frame`, so the entry goes away; Photoshop shows it checked while it stands. +pub(crate) fn shows_selection(app: &PhotocraftApp) -> bool { + app.crop.default_frame && app.crop.frame_from_selection +} + /// The options bar's preset dropdown: the built-in entries ([`crop_size::dropdown_options`]), the /// saved crop presets before Front Image, then New Crop Preset… and Delete Crop Preset…. pub fn dropdown(app: &mut PhotocraftApp, ui: &mut egui::Ui) { let builtin = crop_size::dropdown_options(); let users = user_presets(app); + // The temporary "Selection" entry stands above Ratio while the untouched frame is the + // selection's and no ratio presets it (#10872); a picked ratio takes the check mark instead. + let selection_entry = shows_selection(app) && app.ui.tool_options.crop_ratio.is_empty(); let o = &app.ui.tool_options; let label = button_label(o, &builtin, &users); let current_user = current_user(app); @@ -146,9 +159,12 @@ pub fn dropdown(app: &mut PhotocraftApp, ui: &mut egui::Ui) { let combo = craft_ui::ComboBox::from_id_salt("crop-ratio").selected_text(label).width(140.0).height(420.0).icon(crate::widgets::chevron_icon).show_ui(ui, |ui| { crate::press_menu::above_parent_ui(parent_layer, ui); + if selection_entry && ui.selectable_label(true, tl!("Selection")).clicked() { + chosen = Some(Choice::Selection); + } let (before, after): (Vec<_>, Vec<_>) = builtin.iter().partition(|(k, _)| k != crop_size::FRONT); for (k, l) in &before { - if ui.selectable_label(current_user.is_none() && *k == o.crop_ratio, tl!(l)).clicked() { + if ui.selectable_label(!selection_entry && current_user.is_none() && *k == o.crop_ratio, tl!(l)).clicked() { chosen = Some(Choice::Builtin(k.clone())); } } @@ -179,6 +195,8 @@ pub fn dropdown(app: &mut PhotocraftApp, ui: &mut egui::Ui) { /// What picking a dropdown entry does; the Crop tool's canvas menu picks through it too. pub(crate) fn apply_choice(app: &mut PhotocraftApp, choice: Choice) { match choice { + // The frame is already the selection's: the entry is a label, not a preset (#10872). + Choice::Selection => {} Choice::Builtin(k) => { app.ui.tool_options.crop_ratio = k; // A size preset or Front Image fills W x H x Resolution (#2443). diff --git a/crates/ui-egui/src/tools/crop_ui.rs b/crates/ui-egui/src/tools/crop_ui.rs index 3a05ba2cc7..9d494204ea 100644 --- a/crates/ui-egui/src/tools/crop_ui.rs +++ b/crates/ui-egui/src/tools/crop_ui.rs @@ -49,6 +49,9 @@ pub struct CropState { /// `UiState::crop_rect` is the untouched default frame ([`ensure_frame`]): a drag inside it /// draws a new frame (as in Photoshop) instead of moving it, and committing it does nothing. pub default_frame: bool, + /// That untouched default frame came from a selection's bounds (not the whole canvas): the + /// preset dropdown names it "Selection" until the frame is edited (#10872). + pub frame_from_selection: bool, /// The document (index and size) the default frame was made for. frame_for: Option<(usize, u32, u32)>, /// The frame is being edited (pressed since it was made): the canvas shows what lies past it. @@ -339,6 +342,14 @@ pub fn set_space(app: &mut PhotocraftApp, down: bool) { app.crop.space = down; } +/// The options bar's Fill entry (#10872): what a turned or extending crop puts where the image +/// doesn't reach. With Delete Cropped Pixels on that is the background colour; with it off it is +/// transparency, as in Photoshop. Both are the stored `false` of `crop_content_aware`; only the +/// label changes. +pub fn fill_label(delete_cropped_pixels: bool) -> &'static str { + if delete_cropped_pixels { tl!("Background (default)") } else { tl!("Transparent (default)") } +} + /// As in Photoshop, the Crop tool always shows a frame: on picking the tool, and after a crop is /// cancelled or committed, it frames the selection's bounds, or the whole canvas. In default mode /// the view then follows the frame being edited (`crop_mode::sync`). @@ -356,6 +367,7 @@ fn frame(app: &mut PhotocraftApp) { if app.crop.default_frame { app.ui.crop_rect = None; app.crop.default_frame = false; + app.crop.frame_from_selection = false; } if app.ui.crop_rect.is_some() && !keeps_pending(app) { commit_on_leave(app); @@ -380,12 +392,15 @@ fn frame(app: &mut PhotocraftApp) { let Some(st) = app.session.active() else { return }; let canvas = st.doc.bounds(); // Computed once per new frame, not per frame drawn. - let r = st.doc.selection.as_ref().map(|s| s.content_bounds().intersect(&canvas)).filter(|b| !b.is_empty()).unwrap_or(canvas); + let selection = st.doc.selection.as_ref().map(|s| s.content_bounds().intersect(&canvas)).filter(|b| !b.is_empty()); + let from_selection = selection.is_some(); + let r = selection.unwrap_or(canvas); if r.is_empty() { return; } app.ui.crop_rect = Some([f64::from(r.x0), f64::from(r.y0), f64::from(r.x1), f64::from(r.y1)]); app.crop.default_frame = true; + app.crop.frame_from_selection = from_selection; app.crop.frame_for = key; app.crop.editing = false; app.crop.undo.clear(); diff --git a/docs/control-protocol.md b/docs/control-protocol.md index 609363ca9d..c33f45f52c 100644 --- a/docs/control-protocol.md +++ b/docs/control-protocol.md @@ -61,7 +61,7 @@ The transport is `apps/photocraft/src/control_server.rs`, and the handlers are i - `ui.set` also accepts the Eyedropper options bar (#1649): `eyedropperSampleSize` (`"point"` or 1, 3, 5, 11, 31, 51, 101: the side of the averaged square, shared by the Eyedropper, a painting tool's Alt-click eyedropper, the Curves/Color Picker eyedroppers and the Info panel), `eyedropperSample` (`current`, `currentAndBelow`, `all`, `allNoAdjustments`, `currentAndBelowNoAdjustments`) and `eyedropperRing` (boolean, Show Sampling Ring). `ui.inspect` reports them under `toolOptions` (`eyedropper_size`, `eyedropper_sample`, `eyedropper_ring`). The engine command `document.sampleColor {x, y, size, sampleLayer}` returns the colour such a sample picks, as four floats 0..1 (not 0..255). - `ui.set` also accepts the Crop tool's overlay menu (#1919): `cropOverlay` (`thirds`, `grid`, `diagonal`, `triangle`, `goldenRatio`, `goldenSpiral`), `cropOverlayShow` (`auto`: only while the crop box is dragged, Photoshop's default; `always`; `never`) and `cropOverlayOrientation` (0..3; Triangle has two orientations and Golden Spiral four, the others ignore it). `ui.inspect` reports them under `toolOptions` (`crop_overlay`, `crop_overlay_show`, `crop_overlay_orientation`). In the app, O cycles the overlay and ⇧O its orientation while the Crop tool shows a box. - `ui.set` also accepts the Pen tools' options bar (#1397): `penMode` (`path` or `shape`) and `penPathOp`, the Path Operations menu (`newLayer`, `combine`, `subtract`, `intersect`, `exclude`): how the next Pen, Freeform Pen or Curvature Pen path joins the selected shape layer (Shape mode; `newLayer` makes a new one) or the targeted vector mask, selected path or Work Path (Path mode, where `newLayer` combines). `ui.inspect` reports them under `toolOptions` (`vector_mode`, `pen_path_op`). Merge Shape Components is the engine command `path.mergeShapeComponents` (work, saved or `layer` path) or `layer.combineShapes.mergeShapeComponents` (shape layers). -- `ui.set` also accepts `cropFill` (`background`, Photoshop's Background (Default), or `contentAware`), the Crop tool's Fill dropdown (#3823): with `contentAware`, committing a turned or extending frame passes `contentAware: true` to `image.crop`, which fills the area the image doesn't cover from its surroundings. `ui.inspect` reports it as `toolOptions.crop_content_aware`. +- `ui.set` also accepts `cropFill` (`background`, the Fill dropdown's first entry, which reads Background (default), or Transparent (default) with Delete Cropped Pixels off, or `contentAware`), the Crop tool's Fill dropdown (#3823, #10872): with `contentAware`, committing a turned or extending frame passes `contentAware: true` to `image.crop`, which fills the area the image doesn't cover from its surroundings. `ui.inspect` reports it as `toolOptions.crop_content_aware`. Both gradient modes use the current preset, including its opacity stops. Select `Foreground to Transparent` through `gradient.presets.select`, or pass custom `stops` and `transparency: [[0,100],[1,0]]` (location 0..1, opacity 0..100). Use `applyToLayer: false` to edit only the tool preset. Classic gradient drags dispatch `paint.gradient` without overriding them. - `ui.set` also accepts the Crop tool's gear menu (#1919) as `cropShield`, an object patching any of `show_cropped_area` (Show Cropped Area; off hides everything outside the box behind the canvas colour, H in the app), `enabled` (Enable Crop Shield), `color` (`matchCanvas`, the pasteboard colour, or `custom`), `custom_color` (`[r, g, b]`, 0..255), `opacity` (0..100, default 75), `auto_adjust` (Auto Adjust Opacity: half the opacity while the box is dragged), `classic_mode` (Use Classic Mode, default off: the box turns and moves over the image; off is Photoshop's default mode, where the box stays upright and the view turns and pans the image behind it while the Crop tool shows a frame, P in the app; in both modes picking the tool turns a rotated view upright about its centre, Classic Mode keeping the camera upright with the frame drawn turned, and the view stays upright after a commit or cancel; Classic Mode greys out Show Cropped Area, which then acts as on, and Auto Center Preview) and `auto_center_preview` (default on: in default mode a box being resized keeps its centre where it is on screen, also after a pan, a drawn one moves to the middle of the canvas, and X re-centres it; a move never re-centres the box). `ui.inspect` reports it as `toolOptions.crop_shield`. The pending frame (`crop_rect`, `crop_angle`: its turn on the image) and the `image.crop` a commit runs are the same in both modes. - `ui.dialog.open {kind, fields?}` (kinds `newDocument`, `about`, `layerStyle {effect?}`, `colorPicker {target: foreground|background}`, `command {command}` (`layer.new.group` / `layer.new.groupFromLayers` open the New Group dialog: fields `name`, `color`, `mode`, `opacity`), `newCropPreset` / `deleteCropPreset`: the Crop tool's New / Delete Crop Preset… dialogs, fields `name` and `selected: [names]`; crop presets are `crop` tool presets, so `tool.presets.new/list/edit {"tool":"crop"}` drive them too) / `ui.dialog.set {dialog, field, value}` / `ui.dialog.confirm {dialog, wait?}` / `ui.dialog.cancel {dialog}`. Like `ui.menu.invoke`, `ui.dialog.confirm` waits for a background job its command starts (a filter dialog's OK) and replies with the result; `"wait": false` replies `{job, pending: true}` at once