tfix4-f6d: FormDialog::opening is the host's Reset baseline in every pass; HostedAdjustDialog::seed moves it, so Reset returns to the last seed

This commit is contained in:
aiongg
2026-11-15 22:04:30 +00:00
parent 245f0dba01
commit 5cabd08694
3 changed files with 45 additions and 6 deletions
+8 -1
View File
@@ -93,6 +93,9 @@ pub struct HostedAdjustDialog<V, E = ()> {
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<V: Value + Default + Serialize + DeserializeOwned, E: Send + 'static> Hoste
key,
title: title.into(),
open: true,
opening: value.clone(),
value,
edited: false,
preview: true,
@@ -272,8 +276,9 @@ impl<V: Value + Default + Serialize + DeserializeOwned, E: Send + 'static> 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<V: Value + Default + Serialize + DeserializeOwned, E: Send + 'static> Stack
title,
open,
value,
opening,
edited,
preview,
comparing,
@@ -341,6 +347,7 @@ impl<V: Value + Default + Serialize + DeserializeOwned, E: Send + 'static> 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| {
+29
View File
@@ -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::<Adjust>() {
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<RefCell<DialogHost>>| host.borrow().get::<Adjust>().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]
@@ -186,7 +186,7 @@ pub struct FormDialog<'a, V: Value + Default> {
answers: Vec<HostAnswer>,
reset_with: Option<ResetWithFn<'a, V>>,
on_reset: Option<OnResetFn<'a>>,
/// 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<V>,
}
@@ -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::<Opened<V>>().0 = Some(opening.clone().unwrap_or_else(|| values.clone()));
match &opening {
Some(opening) if !measuring => cx.memory::<Opened<V>>().0 = Some(opening.clone()),
None if first => cx.memory::<Opened<V>>().0 = Some(values.clone()),
_ => {}
}
if history && !measuring {
let mut steps = steps.unwrap_or_else(|| EditHistory::new(&values));