mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Merge #18421 into the merge queue batch
Stack Mode: name each mode's History state "Rendering Image Stack <entry>" (#18295)
This commit is contained in:
commit
10303a4557
2 files changed
+76
-2
No files matched your search
@@ -393,8 +393,9 @@ fn color_decontaminate(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
|
||||
fn stack_mode(s: &mut Session, p: &Value, mode: Option<StackMode>) -> Result<Value> {
|
||||
let id = layer_param(s, p)?;
|
||||
let label = mode.map_or("None", StackMode::label);
|
||||
s.edit(&format!("Stack Mode: {label}"), |doc, _| {
|
||||
// The History state of a mode is named after the rendering, with the entry's label; None keeps its own (#18295).
|
||||
let name = mode.map_or_else(|| "Stack Mode: None".to_string(), |mode| format!("Rendering Image Stack {}", mode.label()));
|
||||
s.edit(&name, |doc, _| {
|
||||
let l = doc.layer_mut(id).ok_or(EngineError::NoLayer(id))?;
|
||||
let LayerContent::Smart(sm) = &mut l.content else {
|
||||
return Err(other("the active layer is not a smart object"));
|
||||
@@ -1158,4 +1159,6 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
#[cfg(test)]
|
||||
mod global_light_background_only_tests;
|
||||
#[cfg(test)]
|
||||
mod stack_mode_history_tests;
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
@@ -0,0 +1,71 @@
|
||||
//! #18295: each Layer › Smart Objects › Stack Mode entry adds one History state named "Rendering Image Stack <entry>",
|
||||
//! as the reference application names it, instead of "Stack Mode: <entry>". None keeps "Stack Mode: None".
|
||||
|
||||
use photocraft_geom::Rect;
|
||||
use serde_json::json;
|
||||
|
||||
use crate::Session;
|
||||
|
||||
/// The command's last id segment and the History state the reference application records for it.
|
||||
const NAMES: [(&str, &str); 11] = [
|
||||
("entropy", "Rendering Image Stack Entropy"),
|
||||
("kurtosis", "Rendering Image Stack Kurtosis"),
|
||||
("maximum", "Rendering Image Stack Maximum"),
|
||||
("mean", "Rendering Image Stack Mean"),
|
||||
("median", "Rendering Image Stack Median"),
|
||||
("minimum", "Rendering Image Stack Minimum"),
|
||||
("range", "Rendering Image Stack Range"),
|
||||
("skewness", "Rendering Image Stack Skewness"),
|
||||
("standardDeviation", "Rendering Image Stack Standard Deviation"),
|
||||
("summation", "Rendering Image Stack Summation"),
|
||||
("variance", "Rendering Image Stack Variance"),
|
||||
];
|
||||
|
||||
/// A document whose active layer is a smart object.
|
||||
fn smart_object() -> Session {
|
||||
let mut s = crate::session();
|
||||
s.execute("file.new", json!({"width": 16, "height": 12})).unwrap();
|
||||
s.execute("layer.new.layer", json!({})).unwrap();
|
||||
s.edit("paint", |doc, active| {
|
||||
doc.layer_mut(active.unwrap()).unwrap().surface_mut().unwrap().fill_rect(Rect::new(2, 2, 10, 8), &[1.0, 0.0, 0.0, 1.0]);
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
s.execute("layer.smartObjects.convertToSmartObject", json!({})).unwrap();
|
||||
s
|
||||
}
|
||||
|
||||
/// How many History states there are, and the name of the newest.
|
||||
fn history(s: &Session) -> (usize, Option<String>) {
|
||||
let history = &s.active().unwrap().history;
|
||||
(history.past_len(), history.undo_label().map(String::from))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn each_mode_adds_one_state_named_rendering_image_stack_and_its_entry() {
|
||||
let mut s = smart_object();
|
||||
for (kind, name) in NAMES {
|
||||
let states = history(&s).0;
|
||||
s.execute(&format!("layer.smartObjects.stackMode.{kind}"), json!({})).unwrap();
|
||||
assert_eq!(history(&s), (states + 1, Some(name.to_string())), "{kind}");
|
||||
}
|
||||
}
|
||||
|
||||
/// The name follows the entry as the menu shows it.
|
||||
#[test]
|
||||
fn the_name_ends_with_the_entrys_menu_label() {
|
||||
let _session = crate::session();
|
||||
for (kind, name) in NAMES {
|
||||
let label = crate::commands::find(&format!("layer.smartObjects.stackMode.{kind}")).unwrap().label;
|
||||
assert_eq!(name.strip_prefix("Rendering Image Stack "), Some(label), "{kind}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn none_keeps_its_name() {
|
||||
let mut s = smart_object();
|
||||
s.execute("layer.smartObjects.stackMode.median", json!({})).unwrap();
|
||||
let states = history(&s).0;
|
||||
s.execute("layer.smartObjects.stackMode.none", json!({})).unwrap();
|
||||
assert_eq!(history(&s), (states + 1, Some("Stack Mode: None".to_string())));
|
||||
}
|
||||
Reference in new issue
Block a user