mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Merge #17630 into the merge queue batch
fix(ui): name an Indexed or Bitmap document's mode without a bit depth (#17607)
This commit is contained in:
commit
033ad501d1
2 files changed
+77
-1
No files matched your search
@@ -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<PhotocraftApp> {
|
||||
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)");
|
||||
}
|
||||
@@ -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;
|
||||
Reference in new issue
Block a user