From dc79b3a06aba2590c6ce3911bbbc9e42c402ef8f Mon Sep 17 00:00:00 2001 From: RickiNano <81099017+RickiNano@users.noreply.github.com> Date: Thu, 26 Nov 2026 17:06:55 +0100 Subject: [PATCH] Layers panel: name an Indexed document's Background row "Index" in italics (#16763) In Indexed Color the Background row of the Layers panel reads "Index" in italics. The stored layer name and file export are unchanged; other modes keep the "Background" row. --- .../panels/indexed_background_name_tests.rs | 46 +++++++++++++++++++ crates/ui-egui/src/panels/layers_tree.rs | 11 ++++- 2 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 crates/ui-egui/src/panels/indexed_background_name_tests.rs diff --git a/crates/ui-egui/src/panels/indexed_background_name_tests.rs b/crates/ui-egui/src/panels/indexed_background_name_tests.rs new file mode 100644 index 0000000000..869f1d33f6 --- /dev/null +++ b/crates/ui-egui/src/panels/indexed_background_name_tests.rs @@ -0,0 +1,46 @@ +//! The Layers panel's Background row in an Indexed Color document (#16763): it reads "Index" in italics, while the +//! stored layer name stays "Background"; other modes keep the "Background" row. +use craft::layers::ui::tree::{LayerInfo, LayerTree}; +use serde_json::json; + +use super::PhotoLayers; +use crate::PhotocraftApp; + +/// A new RGB document with its Background. +fn rgb_app() -> Box { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + app.run("file.new", json!({"width": 32, "height": 24})).unwrap(); + app +} + +fn indexed_app() -> Box { + let mut app = rgb_app(); + app.run("image.mode.indexedColor", json!({"palette": "exact", "forced": "none", "dither": "none"})).unwrap(); + app +} + +/// The Background's stored name and the panel row the Layers panel builds for it. +fn background_row(app: &PhotocraftApp) -> (String, LayerInfo) { + let st = app.session.active().expect("a document"); + let layer = st.doc.walk().into_iter().map(|(_, _, l)| l).find(|l| st.doc.is_background(l.id)).expect("the document has a Background"); + let info = PhotoLayers::new(app, st, &Default::default(), false, None).info(&layer.id); + (layer.name.clone(), info) +} + +#[test] +fn an_indexed_documents_background_row_reads_index_in_italics() { + let app = indexed_app(); + let (stored, row) = background_row(&app); + assert_eq!(row.name, "Index"); + assert!(row.italic, "the Index row is italic"); + assert!(row.background, "the row is still the Background"); + assert_eq!(stored, "Background", "the stored layer name is unchanged"); +} + +#[test] +fn an_rgb_documents_background_row_keeps_its_name() { + let app = rgb_app(); + let (stored, row) = background_row(&app); + assert_eq!(row.name, stored); + assert!(!row.italic, "the Background row stays upright"); +} diff --git a/crates/ui-egui/src/panels/layers_tree.rs b/crates/ui-egui/src/panels/layers_tree.rs index 185695197b..7e2d6c7afa 100644 --- a/crates/ui-egui/src/panels/layers_tree.rs +++ b/crates/ui-egui/src/panels/layers_tree.rs @@ -19,7 +19,7 @@ use craft::ui::list::ThumbSize; use craft::ui::patterns::blend_keys::{BlendKeyEntry, blend_entries}; use craft::ui::primitives::textures::{Revision, ThumbRender, ThumbRequest, ThumbSource, thumb_image}; use craft::ui::runtime::env::Label; -use photocraft_color::BlendMode; +use photocraft_color::{BlendMode, ColorMode}; use photocraft_doc::{Document, Effect, Fill, LabelColor, Layer, LayerContent, LayerId}; use photocraft_engine::DocState; use serde_json::{Value, json}; @@ -323,7 +323,10 @@ impl LayerTree for PhotoLayers { LayerContent::Smart(_) => LayerKind::SmartObject, } }; - let mut info = LayerInfo::new(l.name.clone(), kind); + // An Indexed Color document's Background row reads "Index" in italics; the stored name stays (#16763). + let index_row = doc.mode == ColorMode::Indexed && doc.is_background(l.id); + let mut info = LayerInfo::new(if index_row { tl!("Index").to_string() } else { l.name.clone() }, kind); + info.italic = index_row; info.visible = l.visible; let index = doc.layers.index(); info.dimmed = !l.visible || std::iter::successors(index.parent(*id), |p| index.parent(*p)).any(|p| self.layer(&p).is_some_and(|g| !g.visible)); @@ -806,3 +809,7 @@ impl ThumbSource> for PhotoThumbs<'_> { pub(crate) fn select_pixels(layer: LayerId) -> Value { json!({"channel": "transparency", "layer": layer.0, "operation": "new"}) } + +#[cfg(test)] +#[path = "indexed_background_name_tests.rs"] +mod indexed_background_name_tests;