diff --git a/crates/ui-patterns/src/patterns/form_dialogs/form.rs b/crates/ui-patterns/src/patterns/form_dialogs/form.rs index 412d6f674..50e86ada0 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/form.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/form.rs @@ -557,8 +557,9 @@ impl<'a, V: Value + Default> FormDialog<'a, V> { let accepts = Cell::new(ok_enabled); let body_pick = Cell::new(false); let shown = dialog.show(ui, |ui, cx| { - // A measuring run sees no answers and no opening pass: the real run that follows still has both. - let measuring = measuring_run; + // A measuring run sees no answers and no opening pass: the real run that follows still has both. The dialog + // measures its body in a run of its own too (a re-layout under a child dialog), inside a real run of the form. + let measuring = measuring_run || crate::runtime::measure::active(ui.ctx()); let first = cx.appeared() && !measuring; let mut held = bind.borrow_mut(); let before = match held.reborrow().read(cx) { diff --git a/crates/ui-patterns/tests/it/form_dialogs/save_for_web.rs b/crates/ui-patterns/tests/it/form_dialogs/save_for_web.rs index 1559f5cb8..ad7f1d200 100644 --- a/crates/ui-patterns/tests/it/form_dialogs/save_for_web.rs +++ b/crates/ui-patterns/tests/it/form_dialogs/save_for_web.rs @@ -400,3 +400,24 @@ fn four_up_webp_halves_the_quality_until_lossless() { let [half, quarter] = four_up_options(&host); assert_eq!((half.format, quarter.format), (WebFormat::Png8, WebFormat::Gif)); } + +/// A palette answer that arrives as the child dialog that picked it closes and the room changes, so the dialog measures +/// its body again before it runs it, still shifts the opened entry. Guards against a body that took the host's answers +/// in whichever run of the pass came first: the measuring run used the answer up and the real run reported nothing. +#[trial] +fn a_palette_answer_survives_a_measuring_run_of_the_body() { + use craft_ui::dialog::{Alert, HostedAlert}; + let (host, mut fixture) = open(HostedSaveForWeb::new("poster.psd", IMAGE, texture()).options(gif(8))); + show_palette(&host, &mut fixture); + let cell = fixture.by_label("1 #00ff00").expect("the Color Table lists the palette"); + fixture.click(&cell).key(Key::Enter, Modifiers::NONE).idle(4); + let (id, _) = host.borrow_mut().take_color_request().expect("opening a cell asks for its colour"); + let picker = host.borrow_mut().open_child(HostedAlert::new(Alert::new("Color Picker", "Pick a colour.")), id); + fixture.idle(4); + host.borrow_mut().close_by_id(picker); + host.borrow_mut().answer_color(id, PALETTE_COLOR_KEY, Srgba::rgb(1.0, 0.0, 1.0)); + fixture.room(Vec2::new(1000.0, 700.0)); + fixture.idle(4); + let shift = (ColorTableEdit::Shift([255, 0, 255]), vec![[0, 255, 0]]); + assert_eq!(table_events(&host), vec![shift], "the answer shifts the opened entry's colour"); +}