From aec5cee320cf088a3bda8a7578e22a802d82ea1f Mon Sep 17 00:00:00 2001 From: Dan Date: Tue, 24 Nov 2026 22:56:23 +0000 Subject: [PATCH 1/7] Add Black & White adjustment presets --- crates/ui-egui/src/dialogs/adjust_editors.rs | 13 +-- .../adjust_editors/black_white_presets.rs | 96 +++++++++++++++++++ .../src/dialogs/adjust_editors/session.rs | 16 +++- .../src/dialogs/adjust_editors/ui_tests.rs | 92 ++++++++++++++++++ 4 files changed, 205 insertions(+), 12 deletions(-) create mode 100644 crates/ui-egui/src/dialogs/adjust_editors/black_white_presets.rs diff --git a/crates/ui-egui/src/dialogs/adjust_editors.rs b/crates/ui-egui/src/dialogs/adjust_editors.rs index b1a687f321..3bc8a0fd51 100644 --- a/crates/ui-egui/src/dialogs/adjust_editors.rs +++ b/crates/ui-egui/src/dialogs/adjust_editors.rs @@ -17,9 +17,9 @@ use craft::behavior::{EditEvent, EditEvents, Mixed}; use craft::color_ui::ui::gradient::{ColorStop, GradientStops}; use craft::draw::ui::gradient::{GradientGroup, GradientItem, GradientMap, GradientMapEditor, GradientMapOutput}; use craft::imaging::ui::adjust::{ - AdjustDialogCx, AdjustField, AdjustSliders, AdjustWords, BlackWhite, BlackWhiteEditor, BrightnessContrast, BrightnessContrastEditor, ChannelMixer, - ChannelMixerEditor, ColorBalance, ColorBalanceEditor, ColorBalanceTone, CurvesPanel, HueSaturation, HueSaturationEditor, Levels, LevelsPanel, PhotoFilter, - PhotoFilterEditor, SelectiveColor, SelectiveColorEditor, ThresholdEditor, ToneChannels, ToneCurves, ToneSpace, + AdjustDialogCx, AdjustField, AdjustSliders, AdjustWords, BlackWhite, BrightnessContrast, BrightnessContrastEditor, ChannelMixer, ChannelMixerEditor, + ColorBalance, ColorBalanceEditor, ColorBalanceTone, CurvesPanel, HueSaturation, HueSaturationEditor, Levels, LevelsPanel, PhotoFilter, PhotoFilterEditor, + SelectiveColor, SelectiveColorEditor, ThresholdEditor, ToneChannels, ToneCurves, ToneSpace, }; use craft::imaging::ui::histogram::{ChannelColor, HistogramData}; use craft::theme::Srgba; @@ -35,6 +35,7 @@ use serde_json::{Value, json}; use crate::PhotocraftApp; +mod black_white_presets; mod session; pub mod values; @@ -306,11 +307,7 @@ fn show(kind: &str, setup: &EditorSetup, ui: &mut Ui, value: &mut AdjustValue, c let out = editor.show(ui); lifted(out.edit.events, |value| AdjustValue::ColorBalance { value }) } - ("blackWhite", AdjustValue::BlackWhite { value }) => { - let out = BlackWhiteEditor::new("Black & White", Bind::bound(value)).context(context).show(ui); - let ask = if out.auto { Some(AdjustAsk::Auto) } else { out.pick_color.map(AdjustAsk::PickColor) }; - AdjustOut { ask, edit: out.edit.events.map(|value| AdjustValue::BlackWhite { value }) } - } + ("blackWhite", AdjustValue::BlackWhite { value }) => black_white_presets::show(ui, value, context), ("photoFilter", AdjustValue::PhotoFilter { value }) => { let out = PhotoFilterEditor::new("Photo Filter", Bind::bound(value)).context(context).show(ui); AdjustOut { ask: out.pick_color.map(AdjustAsk::PickColor), edit: out.edit.events.map(|value| AdjustValue::PhotoFilter { value }) } diff --git a/crates/ui-egui/src/dialogs/adjust_editors/black_white_presets.rs b/crates/ui-egui/src/dialogs/adjust_editors/black_white_presets.rs new file mode 100644 index 0000000000..6d338a5b9f --- /dev/null +++ b/crates/ui-egui/src/dialogs/adjust_editors/black_white_presets.rs @@ -0,0 +1,96 @@ +//! Original Black & White recipes for tonal shifts and the effect of color filters. + +use std::sync::Arc; + +use craft::behavior::{EditEvent, EditEvents, Mixed}; +use craft::imaging::ui::adjust::{AdjustContext, AdjustWords, BlackWhite, BlackWhiteEditor}; +use craft::ui::contract::{Bind, Entry, Show as _, ShowContainer as _}; +use craft::ui::form::Field; +use craft::ui::pickers::Select; +use craft::ui::runtime::env::Env; +use egui::Ui; + +use super::{AdjustAsk, AdjustOut, AdjustValue}; + +type Mix = [f64; 6]; + +/// The presets change the grayscale mix and keep the layer's tint settings. +fn entries() -> [Entry>; 14] { + [ + Entry::new(Some(BlackWhite::DEFAULT_WEIGHTS), tl!("Default")), + Entry::new(Some([22.0, 38.0, 25.0, 36.0, 10.0, 50.0]), tl!("Darker")), + Entry::new(Some([60.0, 77.0, 64.0, 78.0, 47.0, 92.0]), tl!("Lighter")), + Entry::new(Some([8.0; 6]), tl!("Deep Shadows")), + Entry::new(Some([92.0; 6]), tl!("Bright Highlights")), + Entry::new(Some([48.0; 6]), tl!("Even Color Weights")), + Entry::new(Some([86.0, 65.0, 33.0, 23.0, 15.0, 72.0]), tl!("Red Filter")), + Entry::new(Some([64.0, 91.0, 64.0, 41.0, 13.0, 53.0]), tl!("Yellow Filter")), + Entry::new(Some([28.0, 67.0, 91.0, 74.0, 17.0, 45.0]), tl!("Green Filter")), + Entry::new(Some([24.0, 35.0, 45.0, 77.0, 92.0, 53.0]), tl!("Blue Filter")), + Entry::new(Some([100.0, 73.0, 24.0, 7.0, 5.0, 64.0]), tl!("Strong Red Filter")), + Entry::new(Some([4.0, 12.0, 27.0, 71.0, 100.0, 44.0]), tl!("Strong Blue Filter")), + Entry::new(Some([58.0, 89.0, 97.0, 38.0, 8.0, 33.0]), tl!("Infrared Foliage")), + Entry::new(None, tl!("Custom")), + ] +} + +/// A manual edit can land on exactly the weights of a named recipe. Remember that edit locally +/// so its value still shows as Custom. The Properties inspector scopes this memory to its target. +#[derive(Clone, Copy, PartialEq)] +struct ManualValue { + weights: Mix, + tint: Option<[u8; 3]>, +} + +impl From for ManualValue { + fn from(value: BlackWhite) -> Self { + let [r, g, b, _] = value.tint_color.to_rgba().0; + Self { weights: value.weights, tint: value.tint.then_some([r, g, b]) } + } +} + +fn manual_id(ui: &Ui) -> egui::Id { + ui.make_persistent_id("black-white-manual-value") +} + +/// The Properties host applies accepted Color Picker colors and Auto outside the editor's pass. +pub(super) fn mark_custom(ui: &Ui, value: &AdjustValue) { + if let AdjustValue::BlackWhite { value } = value { + ui.data_mut(|d| d.insert_temp(manual_id(ui), ManualValue::from(*value))); + } +} + +pub(super) fn show(ui: &mut Ui, value: &mut BlackWhite, context: AdjustContext) -> AdjustOut { + let id = manual_id(ui); + let mut manual = ui.data(|d| d.get_temp::(id)); + let entries = entries(); + let shown = (manual != Some((*value).into()) && entries.iter().any(|entry| entry.value() == Some(&Some(value.weights)))).then_some(value.weights); + let label = tl!("Preset"); + let picked = Field::new(label).show(ui, |ui, _| Select::new(label, Bind::given(shown), &entries).show(ui).events.committed().copied()).inner.flatten(); + let mut edit = EditEvents::new(); + if let Some(picked) = picked { + manual = picked.is_none().then(|| (*value).into()); + if let Some(weights) = picked + && weights != value.weights + { + let before = *value; + value.weights = weights; + edit.push(EditEvent::set(Mixed::Same(before), *value, Arc::from(label), None)); + } + } + + let out = BlackWhiteEditor::new("Black & White", Bind::bound(&mut *value)).context(context).show(ui); + if let Some(after) = out.edit.events.committed() { + let words = Env::of(ui).words::(); + let reset = matches!(out.edit.events.ended(), Some(EditEvent::Set { label, .. }) if label.as_ref() == words.default_button.as_str()); + manual = (!reset).then(|| (*after).into()); + } + ui.data_mut(|d| match manual { + Some(value) => d.insert_temp(id, value), + None => d.remove::(id), + }); + + let ask = if out.auto { Some(AdjustAsk::Auto) } else { out.pick_color.map(AdjustAsk::PickColor) }; + edit.extend(out.edit.events); + AdjustOut { ask, edit: edit.map(|value| AdjustValue::BlackWhite { value }) } +} diff --git a/crates/ui-egui/src/dialogs/adjust_editors/session.rs b/crates/ui-egui/src/dialogs/adjust_editors/session.rs index 2c0b85ca45..5ec90aa8ca 100644 --- a/crates/ui-egui/src/dialogs/adjust_editors/session.rs +++ b/crates/ui-egui/src/dialogs/adjust_editors/session.rs @@ -13,7 +13,7 @@ use photocraft_engine::adjust_params; use serde_json::{Value, json}; use super::values::{self, ValueCx}; -use super::{AdjustAsk, AdjustValue, EditorSetup, answer_color, black_white_auto, editor, gradient_presets, is_gray, swatches}; +use super::{AdjustAsk, AdjustValue, EditorSetup, answer_color, black_white_auto, black_white_presets, editor, gradient_presets, is_gray, swatches}; use crate::PhotocraftApp; use crate::color_picker_ui::PickWindow; use crate::theme::Tokens; @@ -189,7 +189,7 @@ pub fn layer_editor(app: &mut PhotocraftApp, ui: &mut egui::Ui, id: LayerId, adj record.session.track(session_target(doc, id), app.properties_hidden, &committed); app.properties_tracked = true; } - follow_color_pick(app, id, &mut record, &committed, &vcx); + follow_color_pick(app, ui, id, &mut record, &committed, &vcx); let mut value = match &app.live_adjust { Some((layer, params)) if *layer == id => values::from_params(kind, params, &vcx).unwrap_or_else(|_| committed.clone()), _ => committed.clone(), @@ -240,7 +240,12 @@ pub fn layer_editor(app: &mut PhotocraftApp, ui: &mut egui::Ui, id: LayerId, adj target.extend(weights); } match values::from_params(kind, ¶ms, &vcx) { - Ok(auto) => commit(app, id, &mut record, &committed, &auto, &vcx, None), + Ok(auto) => { + if auto != committed { + black_white_presets::mark_custom(ui, &auto); + } + commit(app, id, &mut record, &committed, &auto, &vcx, None); + } Err(err) => app.ui.status = err, } } @@ -288,7 +293,7 @@ fn commit( /// A colour well's Color Picker while it is open: its colour previews on the layer. Once it /// closed, OK's colour is one edit and Cancel (or OK without a colour) leaves the layer as it was. -fn follow_color_pick(app: &mut PhotocraftApp, id: LayerId, record: &mut PropertiesAdjust, committed: &AdjustValue, vcx: &ValueCx) { +fn follow_color_pick(app: &mut PhotocraftApp, ui: &egui::Ui, id: LayerId, record: &mut PropertiesAdjust, committed: &AdjustValue, vcx: &ValueCx) { let Some(pick) = record.pick.take() else { return }; match app.framework.dialogs.get_by_id::(pick.dialog).map(ColorPickerDialog::current) { Some(current) => { @@ -304,6 +309,9 @@ fn follow_color_pick(app: &mut PhotocraftApp, id: LayerId, record: &mut Properti Some((key, color)) if key == pick.key && Some(color) != pick.opened => { let mut answered = pick.before; if answer_color(&mut answered, &key, color) { + if answered != *committed { + black_white_presets::mark_custom(ui, &answered); + } commit(app, id, record, committed, &answered, vcx, None); } else { app.live_adjust = None; diff --git a/crates/ui-egui/src/dialogs/adjust_editors/ui_tests.rs b/crates/ui-egui/src/dialogs/adjust_editors/ui_tests.rs index fa23887d65..1a2b8307ca 100644 --- a/crates/ui-egui/src/dialogs/adjust_editors/ui_tests.rs +++ b/crates/ui-egui/src/dialogs/adjust_editors/ui_tests.rs @@ -492,3 +492,95 @@ fn black_white_auto_button_sets_the_weights() { assert_ne!(after, before, "the red and blue are told apart"); assert_eq!(history_len(&h), steps + 1); } + +fn assert_black_white_preset(h: &Harness<'_, Box>, name: &str) { + assert_eq!(h.get_by_role_and_label(Role::ComboBox, "Preset").accesskit_node().value().as_deref(), Some(name)); +} + +#[test] +fn black_white_presets_apply_through_properties_and_undo() { + let mut h = app_harness("blackWhite", "rgb", 8); + let (id, _) = layer(&h); + h.state_mut().run("layer.setAdjustment", json!({"layer": id.0, "tint": true, "tintColor": "#336699"})).unwrap(); + h.run_steps(4); + let (_, before) = layer(&h); + let Adjustment::BlackWhite { weights: original, tint: original_tint } = &before else { panic!("{before:?}") }; + let history = history_len(&h); + let pixel = h.state_mut().run("document.pixel", json!({"x": 10, "y": 10})).unwrap(); + assert_black_white_preset(&h, "Default"); + + h.get_by_role_and_label(Role::ComboBox, "Preset").click(); + h.run_steps(3); + h.get_by_role_and_label(Role::ListBoxOption, "Darker").click(); + h.run_steps(4); + assert_black_white_preset(&h, "Darker"); + let (_, after) = layer(&h); + let Adjustment::BlackWhite { weights, tint } = &after else { panic!("{after:?}") }; + assert!(weights.iter().zip(original).all(|(weight, original)| weight < original)); + assert_eq!(tint, original_tint); + assert_ne!(h.state_mut().run("document.pixel", json!({"x": 10, "y": 10})).unwrap(), pixel); + assert_eq!(history_len(&h), history + 1); + assert!(h.state().live_adjust.is_none()); + + let ctx = h.ctx.clone(); + let picker = open_picker(&mut h, "Tint Color"); + show_in_picker(&mut h, picker, "#ad632a"); + h.state_mut().framework.dialogs.cancel_by_id(&ctx, picker); + h.run_steps(4); + assert_black_white_preset(&h, "Darker"); + assert_eq!(layer(&h).1, after); + assert_eq!(history_len(&h), history + 1); + + let picker = open_picker(&mut h, "Tint Color"); + show_in_picker(&mut h, picker, "#ad632a"); + crate::dialogs::confirm(h.state_mut(), &ctx, picker).expect("OK is enabled"); + h.run_steps(4); + assert_black_white_preset(&h, "Custom"); + assert_eq!(history_len(&h), history + 2); + + h.state_mut().run("edit.undo", json!({})).unwrap(); + h.run_steps(4); + assert_eq!(layer(&h).1, after); + assert_black_white_preset(&h, "Darker"); + h.state_mut().run("edit.undo", json!({})).unwrap(); + h.run_steps(4); + assert_eq!(layer(&h).1, before); + assert_black_white_preset(&h, "Default"); +} + +#[test] +fn black_white_presets_distinguish_manual_edits_from_named_choices() { + let mut h = app_harness("blackWhite", "rgb", 8); + let (id, defaults) = layer(&h); + let Adjustment::BlackWhite { weights, .. } = &defaults else { panic!("{defaults:?}") }; + let red = weights[0]; + h.state_mut().run("layer.setAdjustment", json!({"layer": id.0, "reds": red + 7.0})).unwrap(); + h.run_steps(4); + assert_black_white_preset(&h, "Custom"); + + h.get_by_role_and_label(Role::SpinButton, "Reds").click(); + h.run_steps(1); + h.key_press_modifiers(egui::Modifiers::COMMAND, egui::Key::A); + h.event(egui::Event::Text(red.to_string())); + h.run_steps(1); + h.key_press(egui::Key::Tab); + h.run_steps(4); + assert_eq!(layer(&h).1, defaults); + assert_black_white_preset(&h, "Custom"); + + h.state_mut().run("layer.newAdjustmentLayer.blackWhite", json!({})).unwrap(); + h.run_steps(4); + assert_black_white_preset(&h, "Default"); + h.state_mut().run("layer.select", json!({"layer": id.0})).unwrap(); + h.run_steps(4); + assert_black_white_preset(&h, "Custom"); + + let history = history_len(&h); + h.get_by_role_and_label(Role::ComboBox, "Preset").click(); + h.run_steps(3); + h.get_by_role_and_label(Role::ListBoxOption, "Default").click(); + h.run_steps(4); + assert_black_white_preset(&h, "Default"); + assert_eq!(layer(&h).1, defaults); + assert_eq!(history_len(&h), history); +} From 0146460e38ddb3938f01773bb974bbd101ce956b Mon Sep 17 00:00:00 2001 From: Dan Date: Tue, 24 Nov 2026 23:00:44 +0000 Subject: [PATCH 2/7] Reset the Black & White preset label at default weights --- crates/ui-egui/src/dialogs/adjust_editors.rs | 2 +- .../adjust_editors/black_white_presets.rs | 5 +++ .../src/dialogs/adjust_editors/ui_tests.rs | 35 ++++++++++++------- crates/ui-egui/src/panels/properties.rs | 3 ++ 4 files changed, 32 insertions(+), 13 deletions(-) diff --git a/crates/ui-egui/src/dialogs/adjust_editors.rs b/crates/ui-egui/src/dialogs/adjust_editors.rs index 3bc8a0fd51..d3cb061721 100644 --- a/crates/ui-egui/src/dialogs/adjust_editors.rs +++ b/crates/ui-egui/src/dialogs/adjust_editors.rs @@ -35,7 +35,7 @@ use serde_json::{Value, json}; use crate::PhotocraftApp; -mod black_white_presets; +pub(crate) mod black_white_presets; mod session; pub mod values; diff --git a/crates/ui-egui/src/dialogs/adjust_editors/black_white_presets.rs b/crates/ui-egui/src/dialogs/adjust_editors/black_white_presets.rs index 6d338a5b9f..ca5f03100d 100644 --- a/crates/ui-egui/src/dialogs/adjust_editors/black_white_presets.rs +++ b/crates/ui-egui/src/dialogs/adjust_editors/black_white_presets.rs @@ -53,6 +53,11 @@ fn manual_id(ui: &Ui) -> egui::Id { ui.make_persistent_id("black-white-manual-value") } +pub(crate) fn clear_custom(ui: &Ui) { + ui.data_mut(|d| d.remove::(manual_id(ui))); + ui.ctx().request_repaint(); +} + /// The Properties host applies accepted Color Picker colors and Auto outside the editor's pass. pub(super) fn mark_custom(ui: &Ui, value: &AdjustValue) { if let AdjustValue::BlackWhite { value } = value { diff --git a/crates/ui-egui/src/dialogs/adjust_editors/ui_tests.rs b/crates/ui-egui/src/dialogs/adjust_editors/ui_tests.rs index 1a2b8307ca..a4c88a1036 100644 --- a/crates/ui-egui/src/dialogs/adjust_editors/ui_tests.rs +++ b/crates/ui-egui/src/dialogs/adjust_editors/ui_tests.rs @@ -554,19 +554,22 @@ fn black_white_presets_distinguish_manual_edits_from_named_choices() { let (id, defaults) = layer(&h); let Adjustment::BlackWhite { weights, .. } = &defaults else { panic!("{defaults:?}") }; let red = weights[0]; - h.state_mut().run("layer.setAdjustment", json!({"layer": id.0, "reds": red + 7.0})).unwrap(); - h.run_steps(4); - assert_black_white_preset(&h, "Custom"); + let type_default = |h: &mut Harness<'_, Box>| { + h.state_mut().run("layer.setAdjustment", json!({"layer": id.0, "reds": red + 7.0})).unwrap(); + h.run_steps(4); + assert_black_white_preset(h, "Custom"); + h.get_by_role_and_label(Role::SpinButton, "Reds").click(); + h.run_steps(1); + h.key_press_modifiers(egui::Modifiers::COMMAND, egui::Key::A); + h.event(egui::Event::Text(red.to_string())); + h.run_steps(1); + h.key_press(egui::Key::Tab); + h.run_steps(4); + assert_eq!(layer(h).1, defaults); + assert_black_white_preset(h, "Custom"); + }; - h.get_by_role_and_label(Role::SpinButton, "Reds").click(); - h.run_steps(1); - h.key_press_modifiers(egui::Modifiers::COMMAND, egui::Key::A); - h.event(egui::Event::Text(red.to_string())); - h.run_steps(1); - h.key_press(egui::Key::Tab); - h.run_steps(4); - assert_eq!(layer(&h).1, defaults); - assert_black_white_preset(&h, "Custom"); + type_default(&mut h); h.state_mut().run("layer.newAdjustmentLayer.blackWhite", json!({})).unwrap(); h.run_steps(4); @@ -583,4 +586,12 @@ fn black_white_presets_distinguish_manual_edits_from_named_choices() { assert_black_white_preset(&h, "Default"); assert_eq!(layer(&h).1, defaults); assert_eq!(history_len(&h), history); + + type_default(&mut h); + h.get_by_role_and_label(Role::Button, "Reset to defaults").scroll_to_me(); + h.run_steps(2); + h.get_by_role_and_label(Role::Button, "Reset to defaults").click(); + h.run_steps(4); + assert_black_white_preset(&h, "Default"); + assert_eq!(layer(&h).1, defaults); } diff --git a/crates/ui-egui/src/panels/properties.rs b/crates/ui-egui/src/panels/properties.rs index 08dd6ac85c..e2f6daa62d 100644 --- a/crates/ui-egui/src/panels/properties.rs +++ b/crates/ui-egui/src/panels/properties.rs @@ -156,6 +156,9 @@ fn adjustment_controls(app: &mut PhotocraftApp, ui: &mut egui::Ui, id: LayerId, let params = crate::adjust_editors::layer_reset(app, id, adj); let _ = app.run("layer.setAdjustment", params); app.live_adjust = None; + if matches!(adj, photocraft_doc::Adjustment::BlackWhite { .. }) { + crate::adjust_editors::black_white_presets::clear_custom(ui); + } } } From d87cdb8792e3ce56b10f1417271de2432c147fe2 Mon Sep 17 00:00:00 2001 From: Dan Date: Tue, 24 Nov 2026 23:08:49 +0000 Subject: [PATCH 3/7] Discard the temporary key when storing preset editor state --- .../ui-egui/src/dialogs/adjust_editors/black_white_presets.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/dialogs/adjust_editors/black_white_presets.rs b/crates/ui-egui/src/dialogs/adjust_editors/black_white_presets.rs index ca5f03100d..720dee307e 100644 --- a/crates/ui-egui/src/dialogs/adjust_editors/black_white_presets.rs +++ b/crates/ui-egui/src/dialogs/adjust_editors/black_white_presets.rs @@ -91,7 +91,9 @@ pub(super) fn show(ui: &mut Ui, value: &mut BlackWhite, context: AdjustContext) manual = (!reset).then(|| (*after).into()); } ui.data_mut(|d| match manual { - Some(value) => d.insert_temp(id, value), + Some(value) => { + d.insert_temp(id, value); + } None => d.remove::(id), }); From 98681840296d8b9954f184ca5e272d3a53409551 Mon Sep 17 00:00:00 2001 From: Dan Date: Tue, 24 Nov 2026 23:31:15 +0000 Subject: [PATCH 4/7] Retarget the adjustment after switching layers in the preset test --- crates/ui-egui/src/dialogs/adjust_editors/ui_tests.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/ui-egui/src/dialogs/adjust_editors/ui_tests.rs b/crates/ui-egui/src/dialogs/adjust_editors/ui_tests.rs index a4c88a1036..65fa053623 100644 --- a/crates/ui-egui/src/dialogs/adjust_editors/ui_tests.rs +++ b/crates/ui-egui/src/dialogs/adjust_editors/ui_tests.rs @@ -575,6 +575,8 @@ fn black_white_presets_distinguish_manual_edits_from_named_choices() { h.run_steps(4); assert_black_white_preset(&h, "Default"); h.state_mut().run("layer.select", json!({"layer": id.0})).unwrap(); + // Layer selection can keep the mask targeted. Return to the adjustment's controls. + h.state_mut().run("channel.target.composite", json!({})).unwrap(); h.run_steps(4); assert_black_white_preset(&h, "Custom"); From 2b1afe637cabe3eba622c8edd3e92b279aa8dfe4 Mon Sep 17 00:00:00 2001 From: Dan Date: Tue, 24 Nov 2026 23:55:37 +0000 Subject: [PATCH 5/7] Group Black & White presets and exercise every mix --- .../adjust_editors/black_white_presets.rs | 4 +- .../src/dialogs/adjust_editors/ui_tests.rs | 45 +++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/dialogs/adjust_editors/black_white_presets.rs b/crates/ui-egui/src/dialogs/adjust_editors/black_white_presets.rs index 720dee307e..0c999dd787 100644 --- a/crates/ui-egui/src/dialogs/adjust_editors/black_white_presets.rs +++ b/crates/ui-egui/src/dialogs/adjust_editors/black_white_presets.rs @@ -15,9 +15,10 @@ use super::{AdjustAsk, AdjustOut, AdjustValue}; type Mix = [f64; 6]; /// The presets change the grayscale mix and keep the layer's tint settings. -fn entries() -> [Entry>; 14] { +fn entries() -> [Entry>; 16] { [ Entry::new(Some(BlackWhite::DEFAULT_WEIGHTS), tl!("Default")), + Entry::separator(), Entry::new(Some([22.0, 38.0, 25.0, 36.0, 10.0, 50.0]), tl!("Darker")), Entry::new(Some([60.0, 77.0, 64.0, 78.0, 47.0, 92.0]), tl!("Lighter")), Entry::new(Some([8.0; 6]), tl!("Deep Shadows")), @@ -30,6 +31,7 @@ fn entries() -> [Entry>; 14] { Entry::new(Some([100.0, 73.0, 24.0, 7.0, 5.0, 64.0]), tl!("Strong Red Filter")), Entry::new(Some([4.0, 12.0, 27.0, 71.0, 100.0, 44.0]), tl!("Strong Blue Filter")), Entry::new(Some([58.0, 89.0, 97.0, 38.0, 8.0, 33.0]), tl!("Infrared Foliage")), + Entry::separator(), Entry::new(None, tl!("Custom")), ] } diff --git a/crates/ui-egui/src/dialogs/adjust_editors/ui_tests.rs b/crates/ui-egui/src/dialogs/adjust_editors/ui_tests.rs index 65fa053623..e2ebefaa69 100644 --- a/crates/ui-egui/src/dialogs/adjust_editors/ui_tests.rs +++ b/crates/ui-egui/src/dialogs/adjust_editors/ui_tests.rs @@ -497,6 +497,51 @@ fn assert_black_white_preset(h: &Harness<'_, Box>, name: &str) { assert_eq!(h.get_by_role_and_label(Role::ComboBox, "Preset").accesskit_node().value().as_deref(), Some(name)); } +#[test] +fn black_white_presets_each_set_a_distinct_mix_and_keep_tint() { + let mut h = app_harness("blackWhite", "rgb", 8); + // Leave enough vertical space for the complete dropdown to be visible at once. + h.set_size(vec2(1440.0, 1350.0)); + let (id, _) = layer(&h); + h.state_mut().run("layer.setAdjustment", json!({"layer": id.0, "tint": true, "tintColor": "#336699"})).unwrap(); + h.run_steps(4); + let (_, original) = layer(&h); + let Adjustment::BlackWhite { tint: original_tint, .. } = &original else { panic!("{original:?}") }; + + let mut seen = Vec::new(); + for name in [ + "Darker", + "Lighter", + "Deep Shadows", + "Bright Highlights", + "Even Color Weights", + "Red Filter", + "Yellow Filter", + "Green Filter", + "Blue Filter", + "Strong Red Filter", + "Strong Blue Filter", + "Infrared Foliage", + "Default", + ] { + let history = history_len(&h); + h.get_by_role_and_label(Role::ComboBox, "Preset").click(); + h.run_steps(3); + h.get_by_role_and_label(Role::ListBoxOption, name).click(); + h.run_steps(4); + + let (_, applied) = layer(&h); + let Adjustment::BlackWhite { weights, tint } = applied else { panic!("{applied:?}") }; + assert!(!seen.contains(&weights), "{name} must set a distinct mix"); + seen.push(weights); + assert_black_white_preset(&h, name); + assert_eq!(&tint, original_tint, "{name} preserves Tint"); + assert_eq!(history_len(&h), history + 1, "{name} is one history step"); + assert!(h.state().live_adjust.is_none(), "{name} finishes the preview"); + } + assert_eq!(layer(&h).1, original, "Default restores the original mix"); +} + #[test] fn black_white_presets_apply_through_properties_and_undo() { let mut h = app_harness("blackWhite", "rgb", 8); From 4ab8225b5d17d241877bec6ea5188557ebe4ac56 Mon Sep 17 00:00:00 2001 From: Dan Date: Wed, 25 Nov 2026 20:27:28 +0000 Subject: [PATCH 6/7] Keep Default visible in the Black & White preset test --- crates/ui-egui/src/dialogs/adjust_editors/ui_tests.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/crates/ui-egui/src/dialogs/adjust_editors/ui_tests.rs b/crates/ui-egui/src/dialogs/adjust_editors/ui_tests.rs index 027ba82e5e..06fb26c284 100644 --- a/crates/ui-egui/src/dialogs/adjust_editors/ui_tests.rs +++ b/crates/ui-egui/src/dialogs/adjust_editors/ui_tests.rs @@ -493,6 +493,7 @@ fn black_white_auto_button_sets_the_weights() { assert_eq!(history_len(&h), steps + 1); } +#[track_caller] fn assert_black_white_preset(h: &Harness<'_, Box>, name: &str) { assert_eq!(h.get_by_role_and_label(Role::ComboBox, "Preset").accesskit_node().value().as_deref(), Some(name)); } @@ -594,6 +595,8 @@ fn black_white_presets_apply_through_properties_and_undo() { #[test] fn black_white_presets_distinguish_manual_edits_from_named_choices() { let mut h = app_harness("blackWhite", "rgb", 8); + // Opening the dropdown on Custom reveals the last row, so leave room for Default too. + h.set_size(vec2(1440.0, 1350.0)); let (id, defaults) = layer(&h); let Adjustment::BlackWhite { weights, .. } = &defaults else { panic!("{defaults:?}") }; let red = weights[0]; From 788c0f2d1d273b96a02b2c58e18cba67adfc038e Mon Sep 17 00:00:00 2001 From: Dan Date: Tue, 1 Dec 2026 17:02:08 +0000 Subject: [PATCH 7/7] Restore the original PhotoCraft Black & White presets --- ATTRIBUTION.md | 1 + .../adjust_editors/black_white_presets.rs | 26 ++++++++--------- .../src/dialogs/adjust_editors/ui_tests.rs | 28 +++++++++---------- 3 files changed, 28 insertions(+), 27 deletions(-) diff --git a/ATTRIBUTION.md b/ATTRIBUTION.md index 40f765acb9..a1c20d52f6 100644 --- a/ATTRIBUTION.md +++ b/ATTRIBUTION.md @@ -25,6 +25,7 @@ next to them. | `assets/app-icon/photocraft-nightly.png`, `photocraft-nightly-1024.png`, `photocraft-nightly.ico`, `photocraft-nightly.icns` | PhotoCraft nightly deep-background derivatives | @skylartaylor | Original project-owned256 and padded1024 masters at the revision and hashes in [`nightly-provenance.json`](assets/app-icon/nightly-provenance.json); code-generated background-contribution change only, preserving foreground/alpha; no badge or crescent | MIT OR Apache-2.0, [`assets/app-icon/LICENSE.txt`](assets/app-icon/LICENSE.txt) | | `packaging/nightly-archive-tests.py` (runtime-generated temporary files) | Synthetic flat-archive inventory and exclusive-output fixtures; regular-file payloads, not real image/executable validity | @skylartaylor | Original test-generated strings/files and symlinks from the committed script; no external media or user documents | MIT OR Apache-2.0 | | `packaging/macos/dmg/` (all files) | PhotoCraft DMG window background and layout | @XusBadia, from the PhotoCraft app icon | Original work, see [`packaging/macos/dmg/README.md`](packaging/macos/dmg/README.md) | MIT OR Apache-2.0, like the code | +| `crates/ui-egui/src/dialogs/adjust_editors/black_white_presets.rs` | Built-in Black & White tonal and filter mixes | PhotoCraft contributors (@Bobderto) | Original weights chosen to produce the named tonal and color-filter effects, from [PhotoCraft `2b1afe637`](https://github.com/storytold/photocraft/commit/2b1afe637cabe3eba622c8edd3e92b279aa8dfe4) | MIT OR Apache-2.0 | | `crates/ui-egui/src/theme.rs` (Solarized Dark palette) | Solarized colour scheme used by the Solarized Dark theme | Ethan Schoonover | | MIT, [`LICENSE-solarized.txt`](crates/ui-egui/src/LICENSE-solarized.txt) | | `crates/ui-egui/src/theme.rs` (Breeze Light and Breeze Dark themes) | The Breeze Light and Breeze Dark themes are original colour values on PhotoCraft's Studio layout, chosen to look close to KDE Plasma's Breeze (cool blue-greys, blue accent, 5 px frame radius) so the app blends into a Plasma desktop. None of Breeze's colour values, files or code are copied; the values are a few levels away from its schemes and tuned for text contrast | PhotoCraft contributors | Inspired by the look of KDE Breeze, (its colour schemes are LGPL-2.0-or-later) | Original work | | `crates/ui-egui/src/theme.rs` (Soft Dark and Soft Light themes) | Original colour values and radii for two low-contrast themes on PhotoCraft's Studio layout; no third-party palette, file or code is used | PhotoCraft contributors | Original | Original work | diff --git a/crates/ui-egui/src/dialogs/adjust_editors/black_white_presets.rs b/crates/ui-egui/src/dialogs/adjust_editors/black_white_presets.rs index f1673f2d69..0c999dd787 100644 --- a/crates/ui-egui/src/dialogs/adjust_editors/black_white_presets.rs +++ b/crates/ui-egui/src/dialogs/adjust_editors/black_white_presets.rs @@ -1,4 +1,4 @@ -//! Preset grayscale mixes for the Black & White adjustment. +//! Original Black & White recipes for tonal shifts and the effect of color filters. use std::sync::Arc; @@ -19,18 +19,18 @@ fn entries() -> [Entry>; 16] { [ Entry::new(Some(BlackWhite::DEFAULT_WEIGHTS), tl!("Default")), Entry::separator(), - Entry::new(Some([0.0, 0.0, 0.0, 110.0, 110.0, 110.0]), tl!("Blue Filter")), - Entry::new(Some([30.0, 50.0, 30.0, 50.0, 10.0, 70.0]), tl!("Darker")), - Entry::new(Some([50.0, 120.0, 90.0, 50.0, 0.0, 0.0]), tl!("Green Filter")), - Entry::new(Some([-50.0, -50.0, -50.0, 150.0, 150.0, 150.0]), tl!("High Contrast Blue Filter")), - Entry::new(Some([120.0, 120.0, -10.0, -50.0, -50.0, 120.0]), tl!("High Contrast Red Filter")), - Entry::new(Some([-40.0, 235.0, 144.0, -68.0, -3.0, -107.0]), tl!("Infrared")), - Entry::new(Some([50.0, 70.0, 50.0, 70.0, 30.0, 90.0]), tl!("Lighter")), - Entry::new(Some([0.0; 6]), tl!("Maximum Black")), - Entry::new(Some([100.0; 6]), tl!("Maximum White")), - Entry::new(Some([128.0, 128.0, 100.0, 100.0, 128.0, 100.0]), tl!("Neutral Density")), - Entry::new(Some([120.0, 110.0, -10.0, -50.0, 0.0, 120.0]), tl!("Red Filter")), - Entry::new(Some([120.0, 110.0, 40.0, -30.0, 0.0, 70.0]), tl!("Yellow Filter")), + Entry::new(Some([22.0, 38.0, 25.0, 36.0, 10.0, 50.0]), tl!("Darker")), + Entry::new(Some([60.0, 77.0, 64.0, 78.0, 47.0, 92.0]), tl!("Lighter")), + Entry::new(Some([8.0; 6]), tl!("Deep Shadows")), + Entry::new(Some([92.0; 6]), tl!("Bright Highlights")), + Entry::new(Some([48.0; 6]), tl!("Even Color Weights")), + Entry::new(Some([86.0, 65.0, 33.0, 23.0, 15.0, 72.0]), tl!("Red Filter")), + Entry::new(Some([64.0, 91.0, 64.0, 41.0, 13.0, 53.0]), tl!("Yellow Filter")), + Entry::new(Some([28.0, 67.0, 91.0, 74.0, 17.0, 45.0]), tl!("Green Filter")), + Entry::new(Some([24.0, 35.0, 45.0, 77.0, 92.0, 53.0]), tl!("Blue Filter")), + Entry::new(Some([100.0, 73.0, 24.0, 7.0, 5.0, 64.0]), tl!("Strong Red Filter")), + Entry::new(Some([4.0, 12.0, 27.0, 71.0, 100.0, 44.0]), tl!("Strong Blue Filter")), + Entry::new(Some([58.0, 89.0, 97.0, 38.0, 8.0, 33.0]), tl!("Infrared Foliage")), Entry::separator(), Entry::new(None, tl!("Custom")), ] diff --git a/crates/ui-egui/src/dialogs/adjust_editors/ui_tests.rs b/crates/ui-egui/src/dialogs/adjust_editors/ui_tests.rs index 06fb26c284..87493748f5 100644 --- a/crates/ui-egui/src/dialogs/adjust_editors/ui_tests.rs +++ b/crates/ui-egui/src/dialogs/adjust_editors/ui_tests.rs @@ -499,7 +499,7 @@ fn assert_black_white_preset(h: &Harness<'_, Box>, name: &str) { } #[test] -fn black_white_presets_apply_the_requested_weights_and_keep_tint() { +fn black_white_presets_apply_the_authored_weights_and_keep_tint() { let mut h = app_harness("blackWhite", "rgb", 8); // Leave enough vertical space for the complete dropdown to be visible at once. h.set_size(vec2(1440.0, 1350.0)); @@ -510,18 +510,18 @@ fn black_white_presets_apply_the_requested_weights_and_keep_tint() { let Adjustment::BlackWhite { tint: original_tint, .. } = &original else { panic!("{original:?}") }; for (name, expected) in [ - ("Blue Filter", [0.0, 0.0, 0.0, 110.0, 110.0, 110.0]), - ("Darker", [30.0, 50.0, 30.0, 50.0, 10.0, 70.0]), - ("Green Filter", [50.0, 120.0, 90.0, 50.0, 0.0, 0.0]), - ("High Contrast Blue Filter", [-50.0, -50.0, -50.0, 150.0, 150.0, 150.0]), - ("High Contrast Red Filter", [120.0, 120.0, -10.0, -50.0, -50.0, 120.0]), - ("Infrared", [-40.0, 235.0, 144.0, -68.0, -3.0, -107.0]), - ("Lighter", [50.0, 70.0, 50.0, 70.0, 30.0, 90.0]), - ("Maximum Black", [0.0; 6]), - ("Maximum White", [100.0; 6]), - ("Neutral Density", [128.0, 128.0, 100.0, 100.0, 128.0, 100.0]), - ("Red Filter", [120.0, 110.0, -10.0, -50.0, 0.0, 120.0]), - ("Yellow Filter", [120.0, 110.0, 40.0, -30.0, 0.0, 70.0]), + ("Darker", [22.0, 38.0, 25.0, 36.0, 10.0, 50.0]), + ("Lighter", [60.0, 77.0, 64.0, 78.0, 47.0, 92.0]), + ("Deep Shadows", [8.0; 6]), + ("Bright Highlights", [92.0; 6]), + ("Even Color Weights", [48.0; 6]), + ("Red Filter", [86.0, 65.0, 33.0, 23.0, 15.0, 72.0]), + ("Yellow Filter", [64.0, 91.0, 64.0, 41.0, 13.0, 53.0]), + ("Green Filter", [28.0, 67.0, 91.0, 74.0, 17.0, 45.0]), + ("Blue Filter", [24.0, 35.0, 45.0, 77.0, 92.0, 53.0]), + ("Strong Red Filter", [100.0, 73.0, 24.0, 7.0, 5.0, 64.0]), + ("Strong Blue Filter", [4.0, 12.0, 27.0, 71.0, 100.0, 44.0]), + ("Infrared Foliage", [58.0, 89.0, 97.0, 38.0, 8.0, 33.0]), ("Default", [40.0, 60.0, 40.0, 60.0, 20.0, 80.0]), ] { let history = history_len(&h); @@ -532,7 +532,7 @@ fn black_white_presets_apply_the_requested_weights_and_keep_tint() { let (_, applied) = layer(&h); let Adjustment::BlackWhite { weights, tint } = applied else { panic!("{applied:?}") }; - assert_eq!(weights, expected, "{name} applies the requested mix"); + assert_eq!(weights, expected, "{name} applies the authored mix"); assert_black_white_preset(&h, name); assert_eq!(&tint, original_tint, "{name} preserves Tint"); assert_eq!(history_len(&h), history + 1, "{name} is one history step");