From b1787522444270367b9cc62554c167e99d42ea3e Mon Sep 17 00:00:00 2001 From: bflatastic Date: Tue, 24 Nov 2026 07:16:21 +0700 Subject: [PATCH] ui-patterns: hosted Save for Web takes the host's answers, the Optimize answers and the automation inputs only in a real run, so a palette colour answered in a measured frame still becomes a shift --- .../form_dialogs/save_for_web/hosted.rs | 13 ++++++++----- .../tests/it/form_dialogs/save_for_web.rs | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/crates/ui-patterns/src/patterns/form_dialogs/save_for_web/hosted.rs b/crates/ui-patterns/src/patterns/form_dialogs/save_for_web/hosted.rs index 8708ae4ce..7b220c363 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/save_for_web/hosted.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/save_for_web/hosted.rs @@ -514,10 +514,13 @@ impl StackDialog for HostedSaveForWeb { } fn show(&mut self, ui: &mut Ui, _: &DialogStack) -> Option> { + // A measuring run keeps the host's answers and the inputs: the real run of the pass takes them. + let measuring = crate::runtime::measure::active(ui.ctx()); + let answers = if measuring { Vec::new() } else { self.requests.take_answers() }; let dialog = SaveForWebDialog::new(self.name.clone(), self.size, self.pictures.clone(), Bind::bound(&mut self.options)) .presets(self.presets.clone()) .saving(self.saving) - .answers(self.requests.take_answers()); + .answers(answers); let dialog = SaveForWebDialog { animation: self.animation, remember: self.remember.clone(), @@ -532,11 +535,11 @@ impl StackDialog for HostedSaveForWeb { marks: Some(&self.marks), optimize: self.optimize, browser_preview: self.browser.clone(), - optimize_start: self.optimize_start.take(), - optimize_answer: self.optimize_answer.take(), - optimize_forget: std::mem::take(&mut self.optimize_forget), + optimize_start: if measuring { None } else { self.optimize_start.take() }, + optimize_answer: if measuring { None } else { self.optimize_answer.take() }, + optimize_forget: !measuring && std::mem::take(&mut self.optimize_forget), ok_label: self.ok_label.clone(), - inputs: std::mem::take(&mut self.inputs), + inputs: if measuring { Vec::new() } else { std::mem::take(&mut self.inputs) }, ..dialog }; let mut shown = dialog.show(ui); 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 ad7f1d200..e3171d24b 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 @@ -421,3 +421,21 @@ fn a_palette_answer_survives_a_measuring_run_of_the_body() { 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"); } + +/// A palette colour the host answers in a frame whose first run measures the dialog still shifts the opened entry, once. +/// Guards against a hosted dialog that took its host's answers in the measuring run, whose form drops them. +#[trial] +fn a_palette_answer_in_a_measured_frame_shifts_the_entry_once() { + let host = Rc::new(RefCell::new(DialogHost::new())); + let mut fixture = super::hosted::measured_fixture(&host); + host.borrow_mut().open(HostedSaveForWeb::new("poster.psd", IMAGE, texture()).options(gif(8))); + fixture.idle(10); + 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"); + host.borrow_mut().answer_color(id, PALETTE_COLOR_KEY, Srgba::rgb(1.0, 0.0, 1.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 once"); +}