From f510684bf26f281ab9d663c20fdd75015f330899 Mon Sep 17 00:00:00 2001 From: kubuntugamer Date: Sun, 29 Nov 2026 01:00:33 -0600 Subject: [PATCH] fix(ui): name an Indexed or Bitmap document's mode without a bit depth (#17607) The tab always appended `/`, so an Indexed document read "(Indexed/8)" and a Bitmap one "(Bitmap/8)". The reference names the mode alone, "(Index)" and "(Bitmap)"; a mask target and the other colour modes keep "RGB/8". Co-Authored-By: Codebuff --- .../canvas/tab_indexed_bitmap_label_tests.rs | 65 +++++++++++++++++++ crates/ui-egui/src/canvas/tabs.rs | 13 +++- 2 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 crates/ui-egui/src/canvas/tab_indexed_bitmap_label_tests.rs diff --git a/crates/ui-egui/src/canvas/tab_indexed_bitmap_label_tests.rs b/crates/ui-egui/src/canvas/tab_indexed_bitmap_label_tests.rs new file mode 100644 index 0000000000..aabea6a05b --- /dev/null +++ b/crates/ui-egui/src/canvas/tab_indexed_bitmap_label_tests.rs @@ -0,0 +1,65 @@ +//! #17607: an Indexed document's tab reads "(Index)" and a Bitmap document's "(Bitmap)", with no +//! bit depth; the other colour modes keep "(RGB/8)" and so on. + +use serde_json::json; + +use crate::PhotocraftApp; + +use super::tab_title_at; + +fn app() -> Box { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + app.run("file.new", json!({"width": 40, "height": 30, "name": "oracle"})).unwrap(); + app +} + +/// The document 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) +} + +fn indexed(app: &mut PhotocraftApp) { + app.run("image.mode.indexedColor", json!({"palette": "exact", "forced": "none", "dither": "none", "transparency": false})).unwrap(); +} + +#[test] +fn an_indexed_document_names_its_mode_without_a_bit_depth() { + let mut app = app(); + assert_eq!(title(&app), "oracle @ 100% (RGB/8)"); + + indexed(&mut app); + assert_eq!(title(&app), "oracle @ 100% (Index)"); +} + +#[test] +fn a_bitmap_document_names_its_mode_without_a_bit_depth() { + let mut app = app(); + app.run("image.mode.grayscale", json!({})).unwrap(); + app.run("image.mode.bitmap", json!({"method": "threshold"})).unwrap(); + + assert_eq!(title(&app), "oracle @ 100% (Bitmap)"); +} + +/// The measured label is the mode alone; a tab that also shows the active layer keeps it in front +/// (the conversion itself flattens the document back to its Background layer). +#[test] +fn the_layer_name_stays_in_front_of_the_indexed_label() { + let mut app = app(); + indexed(&mut app); + app.run("layer.new.layer", json!({})).unwrap(); + + assert_eq!(title(&app), "oracle @ 100% (Layer 1, Index)"); +} + +#[test] +fn the_other_colour_modes_keep_their_bit_depth() { + let mut app = app(); + app.run("image.mode.grayscale", json!({})).unwrap(); + assert_eq!(title(&app), "oracle @ 100% (Gray/8)"); + + app.run("image.mode.cmyk", json!({})).unwrap(); + assert_eq!(title(&app), "oracle @ 100% (CMYK/8)"); + + app.run("image.mode.lab", json!({})).unwrap(); + assert_eq!(title(&app), "oracle @ 100% (Lab/8)"); +} diff --git a/crates/ui-egui/src/canvas/tabs.rs b/crates/ui-egui/src/canvas/tabs.rs index 5ebe93e531..43429927a7 100644 --- a/crates/ui-egui/src/canvas/tabs.rs +++ b/crates/ui-egui/src/canvas/tabs.rs @@ -241,9 +241,16 @@ pub(crate) fn tab_title_at(app: &PhotocraftApp, i: usize, zoom: f32) -> String { mode_label(&st.doc).to_string() }; let layer = active_layer.map(|l| format!("{}, ", l.name)).unwrap_or_default(); + // An Indexed or Bitmap document names only its mode, with no bit depth: "(Index)", + // "(Bitmap)" (#17607). A mask target and every other mode keep "RGB/8" and so on. + let mode = match (mask || quick_mask, st.doc.mode) { + (false, photocraft_doc::ColorMode::Indexed) => "Index".to_string(), + (false, photocraft_doc::ColorMode::Bitmap) => "Bitmap".to_string(), + _ => format!("{model}/{}", st.doc.depth.bits()), + }; // A save in progress: "name @ 100% (Layer 1, RGB/16) - Saving 45%", as Photoshop does (#3389). let saving = crate::jobs_ui::save_progress(app, st.doc.id).map(|s| format!(" - {s}")).unwrap_or_default(); - format!("{} @ {}% ({layer}{model}/{}){saving}", titled_name(app, st), fmt_zoom(zoom), st.doc.depth.bits()) + format!("{} @ {}% ({layer}{mode}){saving}", titled_name(app, st), fmt_zoom(zoom)) } /// The document's name as its tab and window title show it: "© name" when File Info marks it @@ -282,3 +289,7 @@ pub(super) fn move_target_after_filter(visible: &[usize], from: usize, to: usize #[cfg(test)] #[path = "../file_info_copyright_title_tests.rs"] mod file_info_copyright_title_tests; + +#[cfg(test)] +#[path = "tab_indexed_bitmap_label_tests.rs"] +mod tab_indexed_bitmap_label_tests;