From 0146460e38ddb3938f01773bb974bbd101ce956b Mon Sep 17 00:00:00 2001 From: Dan Date: Tue, 24 Nov 2026 23:00:44 +0000 Subject: [PATCH] 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); + } } }