From 5cabd08694a04ddff4e7684b49d7d4db0ba2707e Mon Sep 17 00:00:00 2001 From: aiongg Date: Sun, 15 Nov 2026 22:04:30 +0000 Subject: [PATCH] tfix4-f6d: FormDialog::opening is the host's Reset baseline in every pass; HostedAdjustDialog::seed moves it, so Reset returns to the last seed --- crates/imaging/src/ui/adjust/hosted.rs | 9 +++++- crates/imaging/tests/it/hosted_dialogs.rs | 29 +++++++++++++++++++ .../src/patterns/form_dialogs/form.rs | 13 +++++---- 3 files changed, 45 insertions(+), 6 deletions(-) diff --git a/crates/imaging/src/ui/adjust/hosted.rs b/crates/imaging/src/ui/adjust/hosted.rs index ed53c20cd..01cc6f9d7 100644 --- a/crates/imaging/src/ui/adjust/hosted.rs +++ b/crates/imaging/src/ui/adjust/hosted.rs @@ -93,6 +93,9 @@ pub struct HostedAdjustDialog { title: Label, open: bool, value: V, + /// The value Reset returns to and the footer compares with: the opening value, then the last + /// [`seed`](HostedAdjustDialog::seed). + opening: V, /// Whether the value was edited since the dialog opened: by the editor, Reset, a field set or /// [`value_mut`](HostedAdjustDialog::value_mut). A [`seed`](HostedAdjustDialog::seed) is not an edit. edited: bool, @@ -135,6 +138,7 @@ impl Hoste key, title: title.into(), open: true, + opening: value.clone(), value, edited: false, preview: true, @@ -272,8 +276,9 @@ impl Hoste } /// Replaces the value with the one the dialog opens at (the app seeds it after opening, or again once its target - /// resolves or changes), without counting as an edit. + /// resolves or changes), without counting as an edit. Reset returns to the last seed. pub fn seed(&mut self, value: V) { + self.opening = value.clone(); self.value = value; } @@ -312,6 +317,7 @@ impl Stack title, open, value, + opening, edited, preview, comparing, @@ -341,6 +347,7 @@ impl Stack let form = FormDialog::new(title.clone(), Bind::bound(value)) .opened(Bind::bound(open)) .preview(Some(Bind::bound(&mut *preview))) + .opening(opening.clone()) .accept_stays_open(*hold) .ok_enabled(!held.is_waiting()) .shaped(move |dialog| { diff --git a/crates/imaging/tests/it/hosted_dialogs.rs b/crates/imaging/tests/it/hosted_dialogs.rs index 9fdc26513..68a5fbbad 100644 --- a/crates/imaging/tests/it/hosted_dialogs.rs +++ b/crates/imaging/tests/it/hosted_dialogs.rs @@ -130,6 +130,35 @@ fn an_adjustment_dialog_counts_editor_changes_and_sets_as_edits_but_not_seeds_or assert_eq!(edited(&host), Some(true), "a field set of the value is an edit"); } +// A seed after the open moves the Reset baseline: Reset stays disabled after the seed, and after an edit it returns +// the value to the seed, not to the value the dialog opened with. +#[trial] +fn a_seed_moves_the_reset_baseline() { + let host = Rc::new(RefCell::new(DialogHost::new())); + let mut fixture = fixture(&host); + host.borrow_mut().open(brightness_contrast()); + fixture.idle(10); + let seeded = BrightnessContrast { brightness: 5.0, contrast: 5.0, legacy: false }; + if let Some(dialog) = host.borrow_mut().get_mut::() { + dialog.seed(seeded); + } + fixture.idle(4).hold(Modifiers::ALT).idle(2); + let reset = fixture.by_label("Reset").expect("Alt turns Cancel into Reset"); + assert!(fixture.tree().is_disabled_key(reset.node), "a seed is the baseline: nothing to reset"); + fixture.hold(Modifiers::NONE).idle(2); + + let slider = fixture.by_role(craft_ui::contract::Role::SLIDER).first().cloned().expect("the Brightness slider"); + fixture.drag(&slider, Vec2::new(slider.rect.width() / 4.0, 0.0)).settle(); + let value = |host: &Rc>| host.borrow().get::().map(|dialog| dialog.value().clone()); + assert_ne!(value(&host), Some(seeded), "the drag edits the value"); + fixture.hold(Modifiers::ALT).idle(2); + let reset = fixture.by_label("Reset").expect("Alt turns Cancel into Reset"); + assert!(!fixture.tree().is_disabled_key(reset.node), "an edit enables Reset"); + fixture.click(&reset).idle(2); + fixture.hold(Modifiers::NONE).settle(); + assert_eq!(value(&host), Some(seeded), "Reset returns to the seed"); +} + // A dialog given a JSON form lists the form's keys for its value, with the dialog's own fields beside them, and the // form sees the edited signal. #[trial] diff --git a/crates/ui-patterns/src/patterns/form_dialogs/form.rs b/crates/ui-patterns/src/patterns/form_dialogs/form.rs index 0ec97dfcd..3a594be75 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/form.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/form.rs @@ -186,7 +186,7 @@ pub struct FormDialog<'a, V: Value + Default> { answers: Vec, reset_with: Option>, on_reset: Option>, - /// Values the host opened before the first pass: the first pass keeps them as the opening values Reset restores. + /// The host's opening values: each pass given them keeps them as the values Reset restores. opening: Option, } @@ -334,8 +334,9 @@ impl<'a, V: Value + Default> FormDialog<'a, V> { self } - /// Values the host opened before the first pass. The first pass stores them, not its own values, as the opening - /// values Reset restores and the edited check compares with. + /// The opening values the host keeps: Reset restores them and the edited check compares with them. Each pass given + /// them stores them, so a host that moves its baseline (a seed after the open) passes the new one. Without them the + /// first pass's values are the opening values. pub fn opening(mut self, opening: V) -> Self { self.opening = Some(opening); self @@ -483,8 +484,10 @@ impl<'a, V: Value + Default> FormDialog<'a, V> { let ctx = ui.ctx().clone(); crate::runtime::edit::watch_gestures(&ctx, || body(ui, &mut form, &mut values)) }; - if first { - cx.memory::>().0 = Some(opening.clone().unwrap_or_else(|| values.clone())); + match &opening { + Some(opening) if !measuring => cx.memory::>().0 = Some(opening.clone()), + None if first => cx.memory::>().0 = Some(values.clone()), + _ => {} } if history && !measuring { let mut steps = steps.unwrap_or_else(|| EditHistory::new(&values));