mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Merge #17107 into the merge queue batch
Layers panel: name an Indexed document's Background row "Index" in italics (#16763)
This commit is contained in:
commit
c56ed19ede
2 files changed
+55
-2
No files matched your search
@@ -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<PhotocraftApp> {
|
||||
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<PhotocraftApp> {
|
||||
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");
|
||||
}
|
||||
@@ -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<LayerThumb<LayerId>> 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;
|
||||
Reference in new issue
Block a user