Skip to content

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

Layers panel: Clip Thumbnails to Layer Bounds (#4281) (#4312)

badaaif4fb866942c94
diff --git a/crates/engine/src/prefs.rs b/crates/engine/src/prefs.rs
index f5f31c11e..17c6a47df 100644
--- a/crates/engine/src/prefs.rs
+++ b/crates/engine/src/prefs.rs
@@ -272,6 +272,9 @@ pub struct Interface {
pub dynamic_color_sliders: bool,
/// Draw menu item colours set with Edit › Menus.
pub show_menu_colors: bool,
+ /// Layers panel thumbnails frame the layer's own pixels instead of the whole canvas, so small
+ /// objects in a large document stay visible (Photoshop's Clip Thumbnails to Layer Bounds; #4281).
+ pub clip_thumbnails_to_layer_bounds: bool,
pub show_tooltips: bool,
/// Menus, popups and collapsing sections fade and slide, and scroll areas glide to a new
/// position. Off, everything changes at once (a reduced-motion mode; #1218, #3273).
@@ -309,6 +312,7 @@ impl Default for Interface {
show_channels_in_color: false,
dynamic_color_sliders: true,
show_menu_colors: true,
+ clip_thumbnails_to_layer_bounds: false,
show_tooltips: true,
enable_animations: true,
show_bounding_box_when_dragging_layer: false,
diff --git a/crates/ui-egui/src/i18n/cs.tsv b/crates/ui-egui/src/i18n/cs.tsv
index fa4be01a7..4d651a097 100644
--- a/crates/ui-egui/src/i18n/cs.tsv
+++ b/crates/ui-egui/src/i18n/cs.tsv
@@ -1907,6 +1907,8 @@
Camera Raw Defaults Výchozí nastavení Camera Raw
Canvas border Okraj plátna
Show canvas dots Zobrazit tečky plátna
+ Clip thumbnails to layer bounds Oříznout miniatury na hranice vrstvy
+ Clip Thumbnails to Layer Bounds Oříznout miniatury na hranice vrstvy
Canvas color Barva plátna
Canvas custom color Vlastní barva plátna
Color picker Výběr barvy
diff --git a/crates/ui-egui/src/i18n/de.tsv b/crates/ui-egui/src/i18n/de.tsv
index 2421904e2..b1d214b15 100644
--- a/crates/ui-egui/src/i18n/de.tsv
+++ b/crates/ui-egui/src/i18n/de.tsv
@@ -1881,6 +1881,8 @@
Camera Raw Defaults Camera-Raw-Standardeinstellungen
Canvas border Zeichenflächenrand
Show canvas dots Punkte der Zeichenfläche anzeigen
+ Clip thumbnails to layer bounds Miniaturbilder auf Ebenenbegrenzung beschneiden
+ Clip Thumbnails to Layer Bounds Miniaturbilder auf Ebenenbegrenzung beschneiden
Canvas color Zeichenflächenfarbe
Canvas custom color Benutzerdefinierte Zeichenflächenfarbe
Color picker Farbwähler
diff --git a/crates/ui-egui/src/i18n/el.tsv b/crates/ui-egui/src/i18n/el.tsv
index 01009641e..6bc441d0e 100644
--- a/crates/ui-egui/src/i18n/el.tsv
+++ b/crates/ui-egui/src/i18n/el.tsv
@@ -1655,6 +1655,8 @@
Camera Raw Defaults Προεπιλογές Camera Raw
Canvas border Περίγραμμα καμβά
Show canvas dots Εμφάνιση κουκκίδων καμβά
+ Clip thumbnails to layer bounds Περικοπή μικρογραφιών στα όρια του επιπέδου
+ Clip Thumbnails to Layer Bounds Περικοπή μικρογραφιών στα όρια του επιπέδου
Canvas color Χρώμα καμβά
Canvas custom color Προσαρμοσμένο χρώμα καμβά
Color picker Επιλογέας χρώματος
diff --git a/crates/ui-egui/src/i18n/es.tsv b/crates/ui-egui/src/i18n/es.tsv
index d37295184..aa947f228 100644
--- a/crates/ui-egui/src/i18n/es.tsv
+++ b/crates/ui-egui/src/i18n/es.tsv
@@ -1894,6 +1894,8 @@
Camera Raw Defaults Valores predeterminados de Camera Raw
Canvas border Borde del lienzo
Show canvas dots Mostrar puntos del lienzo
+ Clip thumbnails to layer bounds Recortar miniaturas a los límites de la capa
+ Clip Thumbnails to Layer Bounds Recortar miniaturas a los límites de la capa
Canvas color Color del lienzo
Canvas custom color Color personalizado del lienzo
Color picker Selector de color
diff --git a/crates/ui-egui/src/i18n/fr.tsv b/crates/ui-egui/src/i18n/fr.tsv
index 547411e9a..d597d4444 100644
--- a/crates/ui-egui/src/i18n/fr.tsv
+++ b/crates/ui-egui/src/i18n/fr.tsv
@@ -1863,6 +1863,8 @@
Camera Raw Defaults Valeurs par défaut de Camera Raw
Canvas border Bordure du canevas
Show canvas dots Afficher les points du canevas
+ Clip thumbnails to layer bounds Rogner les vignettes aux limites du calque
+ Clip Thumbnails to Layer Bounds Rogner les vignettes aux limites du calque
Canvas color Couleur du canevas
Canvas custom color Couleur personnalisée du canevas
Color picker Sélecteur de couleurs
diff --git a/crates/ui-egui/src/i18n/hu.tsv b/crates/ui-egui/src/i18n/hu.tsv
index d6d33ec2d..ded1a41a0 100644
--- a/crates/ui-egui/src/i18n/hu.tsv
+++ b/crates/ui-egui/src/i18n/hu.tsv
@@ -3534,6 +3534,8 @@ cameraRaw Yellow Sárga
shortcut billentyűparancs
Shortcut Billentyűparancs
Show canvas dots Vászonpontok megjelenítése
+ Clip thumbnails to layer bounds Bélyegképek levágása a réteg határaira
+ Clip Thumbnails to Layer Bounds Bélyegképek levágása a réteg határaira
Show channels in color Csatornák megjelenítése színesen
Show crosshair in brush tip Szálkereszt az ecsethegyben
Show extension panels Bővítménypanelek megjelenítése
diff --git a/crates/ui-egui/src/i18n/id.tsv b/crates/ui-egui/src/i18n/id.tsv
index b1652dd9e..1f9e9f555 100644
--- a/crates/ui-egui/src/i18n/id.tsv
+++ b/crates/ui-egui/src/i18n/id.tsv
@@ -1857,6 +1857,8 @@
Camera Raw Defaults Default Camera Raw
Canvas border Border kanvas
Show canvas dots Tampilkan titik kanvas
+ Clip thumbnails to layer bounds Pangkas thumbnail ke batas layer
+ Clip Thumbnails to Layer Bounds Pangkas Thumbnail ke Batas Layer
Canvas color Warna kanvas
Canvas custom color Warna kustom kanvas
Color picker Pemilih warna
diff --git a/crates/ui-egui/src/i18n/it.tsv b/crates/ui-egui/src/i18n/it.tsv
index e410c2af3..85313e7c6 100644
--- a/crates/ui-egui/src/i18n/it.tsv
+++ b/crates/ui-egui/src/i18n/it.tsv
@@ -1889,6 +1889,8 @@
Camera Raw Defaults Predefiniti Camera Raw
Canvas border Bordo quadro
Show canvas dots Mostra punti del quadro
+ Clip thumbnails to layer bounds Ritaglia le miniature ai limiti del livello
+ Clip Thumbnails to Layer Bounds Ritaglia le miniature ai limiti del livello
Canvas color Colore quadro
Canvas custom color Colore personalizzato quadro
Color picker Selettore colore
diff --git a/crates/ui-egui/src/i18n/ja.tsv b/crates/ui-egui/src/i18n/ja.tsv
index 1d0865132..19ae9575e 100644
--- a/crates/ui-egui/src/i18n/ja.tsv
+++ b/crates/ui-egui/src/i18n/ja.tsv
@@ -1891,6 +1891,8 @@
Camera Raw Defaults Camera Raw の既定値
Canvas border カンバスの境界
Show canvas dots カンバスのドットを表示
+ Clip thumbnails to layer bounds サムネールをレイヤーの境界でクリップ
+ Clip Thumbnails to Layer Bounds サムネールをレイヤーの境界でクリップ
Canvas color カンバスの色
Canvas custom color カンバスのカスタム色
Color picker カラーピッカー
diff --git a/crates/ui-egui/src/i18n/ko.tsv b/crates/ui-egui/src/i18n/ko.tsv
index e199608b9..2371720eb 100644
--- a/crates/ui-egui/src/i18n/ko.tsv
+++ b/crates/ui-egui/src/i18n/ko.tsv
@@ -1857,6 +1857,8 @@
Camera Raw Defaults Camera Raw 기본값
Canvas border 캔버스 테두리
Show canvas dots 캔버스 점 표시
+ Clip thumbnails to layer bounds 썸네일을 레이어 경계로 자르기
+ Clip Thumbnails to Layer Bounds 썸네일을 레이어 경계로 자르기
Canvas color 캔버스 색상
Canvas custom color 캔버스 사용자 정의 색상
Color picker 색상 피커
diff --git a/crates/ui-egui/src/i18n/nl.tsv b/crates/ui-egui/src/i18n/nl.tsv
index 9ac977446..a6ba4b854 100644
--- a/crates/ui-egui/src/i18n/nl.tsv
+++ b/crates/ui-egui/src/i18n/nl.tsv
@@ -1863,6 +1863,8 @@
Camera Raw Defaults Standaardwaarden Camera Raw
Canvas border Canvasrand
Show canvas dots Canvasstippen tonen
+ Clip thumbnails to layer bounds Miniaturen bijsnijden tot laaggrenzen
+ Clip Thumbnails to Layer Bounds Miniaturen bijsnijden tot laaggrenzen
Canvas color Canvaskleur
Canvas custom color Aangepaste canvaskleur
Color picker Kleurkiezer
diff --git a/crates/ui-egui/src/i18n/pl.tsv b/crates/ui-egui/src/i18n/pl.tsv
index 016e564eb..ae92d2152 100644
--- a/crates/ui-egui/src/i18n/pl.tsv
+++ b/crates/ui-egui/src/i18n/pl.tsv
@@ -1885,6 +1885,8 @@
Camera Raw Defaults Domyślne ustawienia Camera Raw
Canvas border Obramowanie płótna
Show canvas dots Pokaż kropki płótna
+ Clip thumbnails to layer bounds Przycinaj miniatury do granic warstwy
+ Clip Thumbnails to Layer Bounds Przycinaj miniatury do granic warstwy
Canvas color Kolor płótna
Canvas custom color Własny kolor płótna
Color picker Próbnik kolorów
diff --git a/crates/ui-egui/src/i18n/pt-br.tsv b/crates/ui-egui/src/i18n/pt-br.tsv
index 154fd3010..10176e31e 100644
--- a/crates/ui-egui/src/i18n/pt-br.tsv
+++ b/crates/ui-egui/src/i18n/pt-br.tsv
@@ -1858,6 +1858,8 @@
Camera Raw Defaults Padrões do Camera Raw
Canvas border Borda da tela de pintura
Show canvas dots Mostrar pontos da tela de pintura
+ Clip thumbnails to layer bounds Recortar miniaturas aos limites da camada
+ Clip Thumbnails to Layer Bounds Recortar miniaturas aos limites da camada
Canvas color Cor da tela de pintura
Canvas custom color Cor personalizada da tela de pintura
Color picker Seletor de cores
diff --git a/crates/ui-egui/src/i18n/ru.tsv b/crates/ui-egui/src/i18n/ru.tsv
index 6466c415c..f74b9f485 100644
--- a/crates/ui-egui/src/i18n/ru.tsv
+++ b/crates/ui-egui/src/i18n/ru.tsv
@@ -2304,6 +2304,8 @@
Camera Raw Defaults Значения Camera Raw по умолчанию
Canvas border Рамка холста
Show canvas dots Показывать точки холста
+ Clip thumbnails to layer bounds Обрезать миниатюры по границам слоя
+ Clip Thumbnails to Layer Bounds Обрезать миниатюры по границам слоя
Canvas color Цвет холста
Canvas custom color Свой цвет холста
Classic Классическая
diff --git a/crates/ui-egui/src/i18n/sr.tsv b/crates/ui-egui/src/i18n/sr.tsv
index aa5923532..9aebfe1f5 100644
--- a/crates/ui-egui/src/i18n/sr.tsv
+++ b/crates/ui-egui/src/i18n/sr.tsv
@@ -1842,6 +1842,8 @@
Camera Raw Defaults Podrazumevana Camera Raw podešavanja
Canvas border Ivica platna
Show canvas dots Prikaži tačke na platnu
+ Clip thumbnails to layer bounds Iseci sličice prema granicama sloja
+ Clip Thumbnails to Layer Bounds Iseci sličice prema granicama sloja
Canvas color Boja platna
Canvas custom color Prilagođena boja platna
Color picker Birač boja
diff --git a/crates/ui-egui/src/i18n/tr.tsv b/crates/ui-egui/src/i18n/tr.tsv
index 08be1125a..d6076ec35 100644
--- a/crates/ui-egui/src/i18n/tr.tsv
+++ b/crates/ui-egui/src/i18n/tr.tsv
@@ -1839,6 +1839,8 @@
Camera Raw Defaults Camera Raw Varsayılanları
Canvas border Kanvas kenarlığı
Show canvas dots Kanvas noktalarını göster
+ Clip thumbnails to layer bounds Küçük resimleri katman sınırlarına kırp
+ Clip Thumbnails to Layer Bounds Küçük resimleri katman sınırlarına kırp
Canvas color Kanvas rengi
Canvas custom color Kanvas özel rengi
Color picker Renk seçici
diff --git a/crates/ui-egui/src/i18n/uk.tsv b/crates/ui-egui/src/i18n/uk.tsv
index 98e0c6ff4..7255c24f1 100644
--- a/crates/ui-egui/src/i18n/uk.tsv
+++ b/crates/ui-egui/src/i18n/uk.tsv
@@ -2277,6 +2277,8 @@
Camera Raw Defaults Типові параметри Camera Raw
Canvas border Межа полотна
Show canvas dots Показувати крапки полотна
+ Clip thumbnails to layer bounds Обрізати мініатюри до меж шару
+ Clip Thumbnails to Layer Bounds Обрізати мініатюри до меж шару
Canvas color Колір полотна
Canvas custom color Довільний колір полотна
Classic Класична
diff --git a/crates/ui-egui/src/i18n/vi.tsv b/crates/ui-egui/src/i18n/vi.tsv
index 3857c4431..d6a82f203 100644
--- a/crates/ui-egui/src/i18n/vi.tsv
+++ b/crates/ui-egui/src/i18n/vi.tsv
@@ -2661,6 +2661,8 @@ shape Appearance Diện mạo
Brush preview color Màu xem trước cọ
Cache levels Mức bộ nhớ đệm
Show canvas dots Hiện chấm vùng vẽ
+ Clip thumbnails to layer bounds Cắt hình thu nhỏ theo biên của lớp
+ Clip Thumbnails to Layer Bounds Cắt hình thu nhỏ theo biên của lớp
Color picker Bộ chọn màu
Color space Không gian màu
Column width Độ rộng cột
diff --git a/crates/ui-egui/src/i18n/zh-hans.tsv b/crates/ui-egui/src/i18n/zh-hans.tsv
index ad3f2204d..d912da2c5 100644
--- a/crates/ui-egui/src/i18n/zh-hans.tsv
+++ b/crates/ui-egui/src/i18n/zh-hans.tsv
@@ -1904,6 +1904,8 @@
Camera Raw Defaults Camera Raw 默认设置
Canvas border 画布边框
Show canvas dots 显示画布圆点
+ Clip thumbnails to layer bounds 将缩略图裁剪到图层边界
+ Clip Thumbnails to Layer Bounds 将缩略图裁剪到图层边界
Canvas color 画布颜色
Canvas custom color 画布自定颜色
Color picker 拾色器
diff --git a/crates/ui-egui/src/i18n/zh-hant.tsv b/crates/ui-egui/src/i18n/zh-hant.tsv
index 9330c7426..a92587214 100644
--- a/crates/ui-egui/src/i18n/zh-hant.tsv
+++ b/crates/ui-egui/src/i18n/zh-hant.tsv
@@ -1897,6 +1897,8 @@
Camera Raw Defaults Camera Raw 預設值
Canvas border 畫布邊框
Show canvas dots 顯示畫布圓點
+ Clip thumbnails to layer bounds 將縮圖裁切至圖層邊界
+ Clip Thumbnails to Layer Bounds 將縮圖裁切至圖層邊界
Canvas color 畫布顏色
Canvas custom color 畫布自訂顏色
Color picker 檢色器
diff --git a/crates/ui-egui/src/layer_row_ui.rs b/crates/ui-egui/src/layer_row_ui.rs
index 7ac725a7c..5a6e60f79 100644
--- a/crates/ui-egui/src/layer_row_ui.rs
+++ b/crates/ui-egui/src/layer_row_ui.rs
@@ -203,6 +203,16 @@ pub fn panel_menu(app: &mut crate::PhotocraftApp, ui: &mut egui::Ui) {
}
ui.close();
}
+ ui.separator();
+ // Photoshop's Clip Thumbnails to Layer Bounds: frame each layer's pixels, not the canvas (#4281).
+ let mut clip = app.session.prefs().interface.clip_thumbnails_to_layer_bounds;
+ if crate::widgets::checkbox(ui, &mut clip, tl!("Clip Thumbnails to Layer Bounds")).changed() {
+ if let Err(e) = app.run("prefs.set", json!({"path": "interface.clipThumbnailsToLayerBounds", "value": clip})) {
+ app.ui.status = e;
+ app.ui.status_error = true;
+ }
+ ui.close();
+ }
}
fn rects_id() -> egui::Id {
diff --git a/crates/ui-egui/src/layer_thumb_bounds_tests.rs b/crates/ui-egui/src/layer_thumb_bounds_tests.rs
new file mode 100644
index 000000000..66ea820cd
--- /dev/null
+++ b/crates/ui-egui/src/layer_thumb_bounds_tests.rs
@@ -0,0 +1,75 @@
+//! #4281: Clip Thumbnails to Layer Bounds. A small object in a large document fills its Layers
+//! panel thumbnail instead of being a speck in an empty canvas-sized one.
+
+use egui::vec2;
+use egui_kittest::Harness;
+use photocraft_doc::LayerId;
+use photocraft_geom::Rect;
+use serde_json::json;
+
+use crate::PhotocraftApp;
+use crate::mask_thumbs_ui::THUMB_LAYER;
+
+fn harness() -> (Harness<'static, PhotocraftApp>, u64) {
+ let mut s = photocraft_engine::Session::new();
+ s.execute("file.new", json!({"width": 2000, "height": 1000})).unwrap();
+ let id = s.execute("layer.new.layer", json!({"name": "Speck"})).unwrap()["layer"].as_u64().unwrap();
+ s.execute("select.rect", json!({"x": 100, "y": 200, "width": 20, "height": 10})).unwrap();
+ s.execute("edit.fill", json!({"color": "#ff0000"})).unwrap();
+ s.execute("select.deselect", json!({})).unwrap();
+ let mut h = Harness::builder().with_size(vec2(1440.0, 1000.0)).with_max_steps(64).build_eframe(move |cc| {
+ PhotocraftApp::setup_context(&cc.egui_ctx, Default::default());
+ PhotocraftApp::new(s, crate::Services::default())
+ });
+ let ctx = h.ctx.clone();
+ let (req, _rx) = crate::control::ControlRequest::new("ui.set", json!({"dockTabs": {"layers": 0}}));
+ crate::control::handle(h.state_mut(), &ctx, &req);
+ h.run_steps(8);
+ (h, id)
+}
+
+fn frame(h: &Harness<'_, PhotocraftApp>, id: u64) -> Rect {
+ *h.state().thumb_frames.get(&LayerId(id)).expect("layer thumbnail drawn")
+}
+
+fn texture_area(h: &Harness<'_, PhotocraftApp>, id: u64) -> usize {
+ let (_, tex) = h.state().thumbs.get(&(LayerId(id), THUMB_LAYER)).expect("layer thumbnail drawn");
+ let [w, h] = tex.size();
+ w * h
+}
+
+#[test]
+fn layer_thumbnails_frame_the_canvas_by_default() {
+ let (h, id) = harness();
+ assert!(!h.state().session.prefs().interface.clip_thumbnails_to_layer_bounds);
+ assert_eq!(frame(&h, id), Rect::new(0, 0, 2000, 1000));
+}
+
+#[test]
+fn clipped_layer_thumbnails_frame_the_layer_pixels() {
+ let (mut h, id) = harness();
+ let before = h.state().thumbs.get(&(LayerId(id), THUMB_LAYER)).map(|(r, _)| *r).unwrap();
+ h.state_mut().run("prefs.set", json!({"path": "interface.clipThumbnailsToLayerBounds", "value": true})).unwrap();
+ h.run_steps(4);
+ assert_eq!(frame(&h, id), Rect::new(100, 200, 120, 210), "framed on the filled rect");
+ let after = h.state().thumbs.get(&(LayerId(id), THUMB_LAYER)).map(|(r, _)| *r).unwrap();
+ assert_ne!(before, after, "toggling the preference rebuilds the thumbnail");
+ assert_eq!(texture_area(&h, id), 64 * 64, "still a 64 px square texture");
+
+ h.state_mut().run("prefs.set", json!({"path": "interface.clipThumbnailsToLayerBounds", "value": false})).unwrap();
+ h.run_steps(4);
+ assert_eq!(frame(&h, id), Rect::new(0, 0, 2000, 1000), "and back to the canvas");
+}
+
+#[test]
+fn empty_and_off_canvas_layers_keep_the_canvas_frame() {
+ let canvas = Rect::new(0, 0, 50, 40);
+ let raster = photocraft_raster::Surface::new(photocraft_color::PixelFormat::RGBA8);
+ let mut empty = photocraft_doc::Layer::new("Empty", photocraft_doc::LayerContent::Raster(raster));
+ assert_eq!(crate::layer_thumb_frame(&empty, canvas, true), canvas);
+ empty.surface_mut().unwrap().write_pixel(-10, -10, &[1.0, 0.0, 0.0, 1.0]);
+ assert_eq!(crate::layer_thumb_frame(&empty, canvas, true), canvas, "pixels only off the canvas");
+ empty.surface_mut().unwrap().write_pixel(45, 5, &[1.0, 0.0, 0.0, 1.0]);
+ assert_eq!(crate::layer_thumb_frame(&empty, canvas, true), Rect::new(0, 0, 46, 6), "the layer bounds, cut to the canvas");
+ assert_eq!(crate::layer_thumb_frame(&empty, canvas, false), canvas);
+}
diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs
index 1bc1eb56f..5e7ab5e87 100644
--- a/crates/ui-egui/src/lib.rs
+++ b/crates/ui-egui/src/lib.rs
@@ -624,6 +624,9 @@ pub struct PhotocraftApp {
pub fps: f32,
last_frame_time: f64,
thumbs: HashMap<(photocraft_doc::LayerId, u8), (u64, egui::TextureHandle)>,
+ /// The document area each layer thumbnail in `thumbs` frames (the canvas, or the layer's
+ /// bounds with Clip Thumbnails to Layer Bounds; #4281).
+ thumb_frames: HashMap<photocraft_doc::LayerId, photocraft_geom::Rect>,
/// History snapshot thumbnails by (document, snapshot id): a snapshot never changes, so each
/// is made once (`snapshot_thumb`, #2966).
snapshot_thumbs: HashMap<(DocId, u64), egui::TextureHandle>,
@@ -829,6 +832,7 @@ impl PhotocraftApp {
fps: 0.0,
last_frame_time: 0.0,
thumbs: HashMap::new(),
+ thumb_frames: HashMap::new(),
snapshot_thumbs: HashMap::new(),
thumb_documents: Vec::new(),
bounds_cache: HashMap::new(),
@@ -2084,6 +2088,7 @@ impl PhotocraftApp {
// Native files can restore IDs: retain the union across all open documents, rather
// than deleting an ID just because one document containing it was closed.
self.thumbs.retain(|key, _| live.contains(key));
+ self.thumb_frames.retain(|id, _| live.contains(&(*id, mask_thumbs_ui::THUMB_LAYER)));
}
self.thumb_documents = documents.iter().map(|st| (st.doc.id, std::sync::Arc::downgrade(&st.doc))).collect();
}
@@ -2109,25 +2114,31 @@ impl PhotocraftApp {
self.checker = None;
}
- /// Cached 64px thumbnail of a pixel-ish layer, laid out in document space.
- pub fn layer_thumb(&mut self, ctx: &egui::Context, doc: &Document, layer: &photocraft_doc::Layer) -> egui::TextureId {
+ /// Cached 64px thumbnail of a pixel-ish layer, letterboxed in a square, and the document
+ /// area it frames: the canvas, or with Clip Thumbnails to Layer Bounds the layer's pixels.
+ pub fn layer_thumb(&mut self, ctx: &egui::Context, doc: &Document, layer: &photocraft_doc::Layer) -> (egui::TextureId, photocraft_geom::Rect) {
+ let clip = self.session.prefs().interface.clip_thumbnails_to_layer_bounds;
// Key by content, not document revision: COW tiles change pointer only when their pixels
// change, so unrelated edits (e.g. painting another layer) don't rebuild this thumbnail.
- let rev = layer.surface().map_or(0, surface_fingerprint) ^ (doc.size.width as u64) << 40;
+ let rev = layer.surface().map_or(0, surface_fingerprint) ^ (doc.size.width as u64) << 40 ^ u64::from(clip) << 63;
let key = (layer.id, mask_thumbs_ui::THUMB_LAYER);
if let Some((r, tex)) = self.thumbs.get(&key)
&& *r == rev
+ && let Some(frame) = self.thumb_frames.get(&layer.id)
{
- return tex.id();
+ return (tex.id(), *frame);
}
+ let canvas = doc.bounds();
+ let frame = layer_thumb_frame(layer, canvas, clip);
let mut px = [0.0f32; 8];
- let img = thumb_image(doc, 64, |x, y| {
+ let img = thumb_image(frame, 64, |x, y| {
let Some(s) = layer.surface() else { return [0.0; 4] };
let n = s.channels();
s.read_pixel(x, y, &mut px[..n]);
photocraft_raster::to_rgba(&s.format(), &px[..n])
});
- self.store_thumb(ctx, key, rev, img)
+ self.thumb_frames.insert(layer.id, frame);
+ (self.store_thumb(ctx, key, rev, img), frame)
}
/// The History panel thumbnail of snapshot `snap` of document `doc` (#2966): its composite,
@@ -2162,7 +2173,7 @@ impl PhotocraftApp {
return tex.id();
}
let mut v = [0.0f32; 1];
- let img = thumb_image(doc, 64, |x, y| {
+ let img = thumb_image(doc.bounds(), 64, |x, y| {
mask.surface.read_pixel(x, y, &mut v);
[v[0], v[0], v[0], 1.0]
});
@@ -2201,9 +2212,20 @@ pub fn surface_fingerprint(s: &photocraft_raster::Surface) -> u64 {
h
}
-/// Square thumbnail of the canvas area, letterboxed, sampling `f(x, y)` in document space.
-fn thumb_image(doc: &Document, side: usize, mut f: impl FnMut(i32, i32) -> [f32; 4]) -> egui::ColorImage {
- let (w, h) = (doc.size.width.max(1) as f32, doc.size.height.max(1) as f32);
+/// The document area a layer thumbnail frames: the canvas, or with `clip` the layer's pixels on
+/// it (the canvas again when it has none there, so an empty layer still shows the page shape).
+fn layer_thumb_frame(layer: &photocraft_doc::Layer, canvas: photocraft_geom::Rect, clip: bool) -> photocraft_geom::Rect {
+ if !clip {
+ return canvas;
+ }
+ let bounds = layer.surface().map_or(photocraft_geom::Rect::EMPTY, photocraft_compose::bounds::content_bounds).intersect(&canvas);
+ if bounds.is_empty() { canvas } else { bounds }
+}
+
+/// Square thumbnail of the document area `frame`, letterboxed, sampling `f(x, y)` in document
+/// space.
+fn thumb_image(frame: photocraft_geom::Rect, side: usize, mut f: impl FnMut(i32, i32) -> [f32; 4]) -> egui::ColorImage {
+ let (w, h) = (frame.width().max(1) as f32, frame.height().max(1) as f32);
let scale = w.max(h) / side as f32;
let (ox, oy) = ((side as f32 - w / scale) / 2.0, (side as f32 - h / scale) / 2.0);
let mut px = vec![egui::Color32::TRANSPARENT; side * side];
@@ -2214,7 +2236,7 @@ fn thumb_image(doc: &Document, side: usize, mut f: impl FnMut(i32, i32) -> [f32;
if dx < 0.0 || dy < 0.0 || dx >= w || dy >= h {
continue;
}
- let c = f(dx as i32, dy as i32);
+ let c = f(frame.x0.saturating_add(dx as i32), frame.y0.saturating_add(dy as i32));
let q = |v: f32| (v.clamp(0.0, 1.0) * 255.0 + 0.5) as u8;
px[ty * side + tx] = egui::Color32::from_rgba_unmultiplied(q(c[0]), q(c[1]), q(c[2]), q(c[3]));
}
@@ -2589,6 +2611,8 @@ mod blur_pins_tests;
#[cfg(test)]
mod move_outline_tests;
+#[cfg(test)]
+mod layer_thumb_bounds_tests;
#[cfg(test)]
mod mask_thumb_refresh_tests;
diff --git a/crates/ui-egui/src/panels.rs b/crates/ui-egui/src/panels.rs
index 191001c39..45a49ebfa 100644
--- a/crates/ui-egui/src/panels.rs
+++ b/crates/ui-egui/src/panels.rs
@@ -3022,10 +3022,11 @@ fn draw_layer_thumb(app: &mut PhotocraftApp, ctx: &egui::Context, ui: &egui::Ui,
_ => {
// Keep row layout and outside thumbnail decorations when the image is clipped.
if ui.is_rect_visible(rect) {
- // The texture is a letterboxed square: draw only the part the document fills.
- let (fitted, uv) = layer_thumb_fit(rect, doc.size.width, doc.size.height);
+ // The texture is a letterboxed square: draw only the part its frame (the document,
+ // or the layer's bounds) fills.
+ let (tex, frame) = app.layer_thumb(ctx, doc, l);
+ let (fitted, uv) = layer_thumb_fit(rect, frame.width(), frame.height());
widgets::checker(p, fitted, 5.0);
- let tex = app.layer_thumb(ctx, doc, l);
p.image(tex, fitted, uv, Color32::WHITE);
}
}
@@ -3069,7 +3070,7 @@ fn history(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
let ctx = ui.ctx().clone();
if let Some(layer) = doc.layers.first() {
widgets::checker(ui.painter(), thumb, 4.0);
- let tex = app.layer_thumb(&ctx, &doc, layer);
+ let (tex, _) = app.layer_thumb(&ctx, &doc, layer);
ui.painter().image(tex, thumb, Rect::from_min_max(egui::Pos2::ZERO, pos2(1.0, 1.0)), Color32::WHITE);
}
ui.painter().rect_stroke(thumb, 0.0, Stroke::new(1.0, t.separator), StrokeKind::Outside);
diff --git a/docs/scorecard.md b/docs/scorecard.md
index a902efcb9..c64fecb5f 100644
--- a/docs/scorecard.md
+++ b/docs/scorecard.md
@@ -9,7 +9,7 @@ Generated by `cargo xtask scorecard` from `perf/budgets.toml`, `perf/baseline.js
| [Performance](#performance) | 3 | 22 | 22 | 56 scenarios: 3 within budget, 22 over budget or failing, 9 tracked only, 17 not run, 5 not measurable yet (baseline 2026-10-05) |
| [File compatibility](#file-compatibility) | 7 | 13 | 7 | io corpus: oracle ≥ 146/170, round trip ≥ 169/170; psd-tools corpus: oracle ≥ 241/309, round trip ≥ 308/309; photoshop oracles: oracle ≥ 149/256, round trip ≥ 258/256 |
| [Tools](#tools) | 32 | 11 | 0 | |
-| [Workspace and UI](#workspace-and-ui) | 13 | 6 | 4 | settings that do nothing: 26 of 160 (target 0) |
+| [Workspace and UI](#workspace-and-ui) | 13 | 6 | 4 | settings that do nothing: 26 of 161 (target 0) |
| [Type](#type) | 4 | 3 | 2 | |
| [Automation](#automation) | 5 | 2 | 4 | 631 of 631 menu items live (100.0%) |
| [Reliability](#reliability) | 5 | 2 | 0 | never-crash lints on 28 of 28 crates; panic_hunt present |
@@ -176,7 +176,7 @@ Corpus floors (`crates/io/tests/corpus.rs`): the enforced minimums; the corpus t
## Workspace and UI
-**Settings that do nothing: 26 of 160** (target 0, #204). Counted by the prefs audit (`xtask/src/scorecard.rs`): a `Preferences` field counts as read when code outside the prefs model (`prefs.rs` except its `impl Session` blocks; tests excluded; the schema-driven dialog never names a field) accesses `section.field`, or `.section` and `.field` in the same file, or calls a section method that reads `self.field`. It is a heuristic lower bound: a generic name can look read when it isn't.
+**Settings that do nothing: 26 of 161** (target 0, #204). Counted by the prefs audit (`xtask/src/scorecard.rs`): a `Preferences` field counts as read when code outside the prefs model (`prefs.rs` except its `impl Session` blocks; tests excluded; the schema-driven dialog never names a field) accesses `section.field`, or `.section` and `.field` in the same file, or calls a section method that reads `self.field`. It is a heuristic lower bound: a generic name can look read when it isn't.
Unread: `general.color_picker`, `general.animated_zoom`, `general.zoom_resizes_windows`, `workspace.auto_show_hidden_panels`, `workspace.enable_floating_document_window_docking`, `file_handling.save_in_background`, `performance.cache_levels`, `performance.legacy_compositing`, `scratch_disks.disks`, `units_and_rulers.column_width`, `units_and_rulers.gutter`, `plug_ins.show_extension_panels`, `plug_ins.allow_scripts_to_connect`, `plug_ins.generator_enabled`, `type_.text_engine`, `type_.recent_fonts`, `enhanced_controls.scrubby_slider_acceleration`, `enhanced_controls.touch_gestures`, `raw_defaults.color_space`, `raw_defaults.bit_depth`, `raw_defaults.resolution`, `raw_defaults.sharpen_for`, `raw_defaults.open_as_smart_object`, `raw_defaults.apply_auto_tone`, `integrations.allow_agent_control`, `integrations.control_port`.
diff --git a/docs/ui-parity.md b/docs/ui-parity.md
index 202b9b89a..14dd5f3d9 100644
--- a/docs/ui-parity.md
+++ b/docs/ui-parity.md
@@ -1,6 +1,6 @@
# UI parity: tools, handles, modifiers and feel
-> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-14 · **Change:** minor (Pen ⇧ 45°; last selected tool restored at launch; Layers panel filter-type dropdown with Kind, Name and Mode, #5048; Free Transform box and marching ants follow the selection, #5297; History: the trash deletes the selected snapshot, rows drag onto the trash, #5324; smart filter reordering by drag; smart object perspective row corrected to done, #426; Free Transform H/V skew fields; toolbar tool shortcuts can be reassigned; ⇧-dragged guides land on ruler ticks; layer and selection keys; tool keys; spring-loaded tool letters; type formatting keys; Pen Auto Add/Delete, #4144; smart filter rows; stale missing-tool rows corrected: Color Replacement, Red Eye and the Add/Delete Anchor Point pair are live toolbar tools, Frame landed; no percentage changed) · **Target:** Adobe Photoshop 2026
+> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-14 · **Change:** minor (Clip Thumbnails to Layer Bounds; Pen ⇧ 45°; last selected tool restored at launch; Layers panel filter-type dropdown with Kind, Name and Mode, #5048; Free Transform box and marching ants follow the selection, #5297; History: the trash deletes the selected snapshot, rows drag onto the trash, #5324; smart filter reordering by drag; smart object perspective row corrected to done, #426; Free Transform H/V skew fields; toolbar tool shortcuts can be reassigned; ⇧-dragged guides land on ruler ticks; layer and selection keys; tool keys; spring-loaded tool letters; type formatting keys; Pen Auto Add/Delete, #4144; smart filter rows; stale missing-tool rows corrected: Color Replacement, Red Eye and the Add/Delete Anchor Point pair are live toolbar tools, Frame landed; no percentage changed) · **Target:** Adobe Photoshop 2026
How PhotoCraft's direct manipulation compares with Photoshop 2026 (27.11.0): the toolbox, the
handles and modifier keys of each gesture, nudging, snapping, numeric precision, navigation,
@@ -214,6 +214,7 @@ Paragraph; the rest open as in-app floating windows.
| Layers panel: wheel steps blend modes, drop on New/Trash | partial | UI-217-14 |
| Layers panel filter-type dropdown (Kind, Name, Effect, Mode, Attribute, Color, Smart Object, Selected, Artboard) | partial | Kind, Name and Mode; the other six missing. `layer_filter_ui.rs`, `ui.set {layerFilter}` (#5048) |
| Smart filter rows: click selects, drag onto another smart object moves, ⌥-drag copies, drag onto Delete removes | done | `smart_ui.rs`, `layer.smartFilter.transfer` (#4271) |
+| Layers panel: Clip Thumbnails to Layer Bounds (panel menu, `interface.clipThumbnailsToLayerBounds`) | done (2026-10-12) | `layer_thumb_bounds_tests.rs`; #4281. Thumbnail size and the Panel Options dialog to come |
| Smart filter rows: drag up or down the stack to reorder (a line marks the drop; the bottom filter is applied first) | done | `smart_ui.rs` `reorder_drop`, `layer.smartFilter.move` |
## Revision history
@@ -237,6 +238,7 @@ Paragraph; the rest open as in-app floating windows.
| 2026-10-12 | minor | Toolbar tool shortcuts can be reassigned, removed and reset in Keyboard Shortcuts (#4086); capture, restart, group cycling, conflict and text-focus regressions |
| 2026-10-12 | minor | Smart filter rows can be selected, and dragged (⌥: copied) onto another smart object or onto Delete (#4271) |
| 2026-10-12 | minor | Free Transform options bar: H and V skew fields; a sheared box reads as skew instead of a taller H |
+| 2026-10-12 | minor | Layers panel: Clip Thumbnails to Layer Bounds frames each layer's pixels instead of the canvas (#4281) |
| 2026-10-13 | minor | Smart filter rows can be dragged up or down their stack to reorder the filters |
| 2026-10-11 | minor | Pen ⇧ 45° done: ⇧-click puts the next anchor on the nearest 45° ray, ⇧-drag turns its handles in 45° steps (TOOL-214-10 done, #3751) |
| 2026-10-14 | minor | Last selected tool restored across launches; temporary overrides excluded, explicit Eraser choices retained, and final selection flushed on normal exit |