From fc61bdeae7e5209d91e6e93bdf1b111f66c7cd27 Mon Sep 17 00:00:00 2001 From: kubuntugamer Date: Sun, 29 Nov 2026 11:55:56 -0600 Subject: [PATCH 1/2] fix(ui): name the targeted channel in the document tab title (#17711) The tab says "(Top, RGB/8)" while an alpha channel or one colour channel is targeted, and drops the layer's name in Quick Mask mode. Photoshop names the paint target there: the alpha channel's own name, the colour channel's, or the Quick Mask after the layer. --- crates/ui-egui/src/canvas/tabs.rs | 26 ++++-- crates/ui-egui/src/canvas/tabs_tests.rs | 2 +- .../src/tab_title_channel_target_tests.rs | 79 +++++++++++++++++++ 3 files changed, 101 insertions(+), 6 deletions(-) create mode 100644 crates/ui-egui/src/tab_title_channel_target_tests.rs diff --git a/crates/ui-egui/src/canvas/tabs.rs b/crates/ui-egui/src/canvas/tabs.rs index 43429927a7..aec296c345 100644 --- a/crates/ui-egui/src/canvas/tabs.rs +++ b/crates/ui-egui/src/canvas/tabs.rs @@ -223,20 +223,32 @@ pub(crate) fn tab_context_items(doc: DocId, index: usize, count: usize, has_path } /// Photoshop's tab title: "name @ 50% (Layer 1, RGB/8)" at `zoom` percent, with "(Layer 1, Layer Mask/8)" when the -/// mask is targeted and "(Quick Mask/8)" in Quick Mask mode; the Background layer's name is omitted. The tab's -/// modified mark shows unsaved changes, so the text carries none. +/// mask is targeted, "(Layer 1, Quick Mask/8)" in Quick Mask mode and "(Layer 1, Red/8)" or "(Layer 1, Alpha 1/8)" +/// when a single colour or alpha channel is; the Background layer's name is omitted. The tab's modified mark shows +/// unsaved changes, so the text carries none. pub(crate) fn tab_title_at(app: &PhotocraftApp, i: usize, zoom: f32) -> String { - use photocraft_engine::channel_cmds::ChannelTarget; + use photocraft_engine::channel_cmds::{self, ChannelTarget}; let Some(st) = app.session.documents().get(i) else { return String::new() }; // Quick Mask mode targets the mask, not the layer (see `paint_target`): painting and Free - // Transform change the red overlay, so the tab says so, as Photoshop's does. + // Transform change the red overlay, so the tab names it after the layer, as Photoshop's does. let quick_mask = st.doc.quick_mask.is_some() && st.channel_view.target == ChannelTarget::Composite; - let active_layer = st.active_layer.and_then(|id| st.doc.layer(id)).filter(|l| !quick_mask && !st.doc.is_background(l.id)); + let active_layer = st.active_layer.and_then(|id| st.doc.layer(id)).filter(|l| !st.doc.is_background(l.id)); let mask = app.session.active_index() == Some(i) && app.ui.mask_target && active_layer.is_some_and(|l| l.mask.is_some()); + // A single channel target names that channel, as Photoshop does (#17711): the Channels panel's + // colour names ("Red", "Cyan", "Lightness") or the alpha channel's own name. Two colour + // channels together are not measured and keep the mode's name. + let alone = |k: usize| st.channel_view.selected_colors.iter().all(|&c| c == k); + let channel = match st.channel_view.target { + ChannelTarget::Alpha(k) => st.doc.channels.get(k).map(|c| c.name.clone()), + ChannelTarget::Color(k) if alone(k) => channel_cmds::color_names(st.doc.mode).get(k).map(|name| (*name).to_string()), + _ => None, + }; let model = if quick_mask { tl!("Quick Mask").to_string() } else if mask { tl!("Layer Mask").to_string() + } else if let Some(name) = &channel { + name.clone() } else { mode_label(&st.doc).to_string() }; @@ -293,3 +305,7 @@ mod file_info_copyright_title_tests; #[cfg(test)] #[path = "tab_indexed_bitmap_label_tests.rs"] mod tab_indexed_bitmap_label_tests; + +#[cfg(test)] +#[path = "../tab_title_channel_target_tests.rs"] +mod tab_title_channel_target_tests; diff --git a/crates/ui-egui/src/canvas/tabs_tests.rs b/crates/ui-egui/src/canvas/tabs_tests.rs index 04b89e638d..cee5d62ee4 100644 --- a/crates/ui-egui/src/canvas/tabs_tests.rs +++ b/crates/ui-egui/src/canvas/tabs_tests.rs @@ -131,7 +131,7 @@ fn quick_mask_mode_names_the_quick_mask_in_the_tab() { h.state_mut().run("select.editInQuickMaskMode", json!({"on": true})).unwrap(); let detail = title(&h); assert!(detail.contains("Quick Mask"), "Quick Mask mode is named: {detail}"); - assert!(!detail.contains("Layer 1") && !detail.contains("RGB"), "the layer is not the target: {detail}"); + assert!(detail.contains("Layer 1") && !detail.contains("RGB"), "the quick mask replaces the mode, the layer stays: {detail}"); h.state_mut().run("select.editInQuickMaskMode", json!({"on": false})).unwrap(); let detail = title(&h); diff --git a/crates/ui-egui/src/tab_title_channel_target_tests.rs b/crates/ui-egui/src/tab_title_channel_target_tests.rs new file mode 100644 index 0000000000..7efa6cded5 --- /dev/null +++ b/crates/ui-egui/src/tab_title_channel_target_tests.rs @@ -0,0 +1,79 @@ +//! #17711: the document tab names the paint target after the layer — the targeted colour channel +//! ("(Top, Red/8)"), the targeted alpha channel by its own name ("(Top, Alpha 1/8)") and the Quick +//! Mask ("(Top, Quick Mask/8)"); the layer mask and the composite keep their titles. + +use serde_json::json; + +use crate::PhotocraftApp; + +use super::tab_title_at; + +/// The tab's title of a document named "oracle" with a pixel layer "Top" active, so a channel or +/// mask target still has a layer name to show. +fn app(depth: u8) -> Box { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + app.run("file.new", json!({"width": 400, "height": 300, "name": "oracle", "depth": depth})).unwrap(); + app.run("layer.new.layer", json!({"name": "Top"})).unwrap(); + app +} + +/// The tab's title; the tab's modified mark is not part of the text. +fn title(app: &PhotocraftApp) -> String { + tab_title_at(app, 0, 100.0) +} + +/// A layer mask on "Top", targeted as the Layers panel's thumbnail click does. +fn mask_targeted(app: &mut PhotocraftApp) { + let top = app.session.active().unwrap().active_layer.unwrap(); + app.run("layer.layerMask.revealAll", json!({"layer": top.0})).unwrap(); + app.run("channel.target", json!({"channel": "mask"})).unwrap(); +} + +#[test] +fn a_targeted_alpha_channel_is_named_after_the_layer() { + let mut app = app(8); + assert_eq!(title(&app), "oracle @ 100% (Top, RGB/8)"); + // A new channel is targeted as it is made, as in Photoshop. + app.run("channel.new", json!({})).unwrap(); + assert_eq!(title(&app), "oracle @ 100% (Top, Alpha 1/8)"); + app.run("channel.rename", json!({"channel": 0, "name": "Spot 1"})).unwrap(); + assert_eq!(title(&app), "oracle @ 100% (Top, Spot 1/8)", "the channel's own name, not a fixed one"); +} + +#[test] +fn a_targeted_colour_channel_is_named() { + let mut app = app(8); + for (channel, name) in [("red", "Red"), ("green", "Green"), ("blue", "Blue")] { + app.run("channel.target", json!({"channel": channel})).unwrap(); + assert_eq!(title(&app), format!("oracle @ 100% (Top, {name}/8)")); + } + app.run("channel.target", json!({"channel": "composite"})).unwrap(); + assert_eq!(title(&app), "oracle @ 100% (Top, RGB/8)", "the composite keeps the mode"); +} + +#[test] +fn quick_mask_names_the_layer_and_the_mask() { + let mut app = app(8); + app.run("select.editInQuickMaskMode", json!({"on": true})).unwrap(); + assert_eq!(title(&app), "oracle @ 100% (Top, Quick Mask/8)"); + app.run("select.editInQuickMaskMode", json!({"on": false})).unwrap(); + assert_eq!(title(&app), "oracle @ 100% (Top, RGB/8)", "leaving Quick Mask brings back the mode"); +} + +#[test] +fn a_layer_mask_target_keeps_its_title() { + let mut app = app(8); + mask_targeted(&mut app); + assert_eq!(title(&app), "oracle @ 100% (Top, Layer Mask/8)"); + app.run("channel.target", json!({"channel": "composite"})).unwrap(); + assert_eq!(title(&app), "oracle @ 100% (Top, RGB/8)"); +} + +#[test] +fn the_bit_depth_follows_the_document() { + let mut app = app(16); + app.run("channel.new", json!({})).unwrap(); + assert_eq!(title(&app), "oracle @ 100% (Top, Alpha 1/16)"); + app.run("channel.target", json!({"channel": "red"})).unwrap(); + assert_eq!(title(&app), "oracle @ 100% (Top, Red/16)"); +} From 0cfb216b86bf0c4583dfe486f48c51a435d4b499 Mon Sep 17 00:00:00 2001 From: kubuntugamer Date: Sun, 29 Nov 2026 12:32:35 -0600 Subject: [PATCH 2/2] fix(ui): keep the Background's tab title on the mode name (#17711) #17711 leaves the Background active unmeasured, and naming the targeted channel changed its title from "(RGB/8)" to "(Red/8)". Only a pixel layer names its channel; the Background keeps the mode, as before. --- crates/ui-egui/src/canvas/tabs.rs | 3 ++- .../ui-egui/src/tab_title_channel_target_tests.rs | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/canvas/tabs.rs b/crates/ui-egui/src/canvas/tabs.rs index aec296c345..0466086965 100644 --- a/crates/ui-egui/src/canvas/tabs.rs +++ b/crates/ui-egui/src/canvas/tabs.rs @@ -236,9 +236,10 @@ pub(crate) fn tab_title_at(app: &PhotocraftApp, i: usize, zoom: f32) -> String { let mask = app.session.active_index() == Some(i) && app.ui.mask_target && active_layer.is_some_and(|l| l.mask.is_some()); // A single channel target names that channel, as Photoshop does (#17711): the Channels panel's // colour names ("Red", "Cyan", "Lightness") or the alpha channel's own name. Two colour - // channels together are not measured and keep the mode's name. + // channels together, and the Background active, are not measured: they keep the mode's name. let alone = |k: usize| st.channel_view.selected_colors.iter().all(|&c| c == k); let channel = match st.channel_view.target { + _ if active_layer.is_none() => None, ChannelTarget::Alpha(k) => st.doc.channels.get(k).map(|c| c.name.clone()), ChannelTarget::Color(k) if alone(k) => channel_cmds::color_names(st.doc.mode).get(k).map(|name| (*name).to_string()), _ => None, diff --git a/crates/ui-egui/src/tab_title_channel_target_tests.rs b/crates/ui-egui/src/tab_title_channel_target_tests.rs index 7efa6cded5..61257e4721 100644 --- a/crates/ui-egui/src/tab_title_channel_target_tests.rs +++ b/crates/ui-egui/src/tab_title_channel_target_tests.rs @@ -69,6 +69,20 @@ fn a_layer_mask_target_keeps_its_title() { assert_eq!(title(&app), "oracle @ 100% (Top, RGB/8)"); } +/// #17711 leaves the Background active unmeasured, so it keeps today's title: the mode's name +/// with no layer, whatever channel is targeted. +#[test] +fn the_background_keeps_the_mode_label() { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + app.run("file.new", json!({"width": 400, "height": 300, "name": "oracle", "depth": 8})).unwrap(); + assert_eq!(title(&app), "oracle @ 100% (RGB/8)"); + app.run("channel.target", json!({"channel": "red"})).unwrap(); + assert_eq!(title(&app), "oracle @ 100% (RGB/8)", "the Background's tab keeps the mode"); + app.run("channel.target", json!({"channel": "composite"})).unwrap(); + app.run("channel.new", json!({})).unwrap(); + assert_eq!(title(&app), "oracle @ 100% (RGB/8)", "nor does an alpha channel name it"); +} + #[test] fn the_bit_depth_follows_the_document() { let mut app = app(16);