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

This commit is contained in:
bflatastic
2026-11-24 07:16:21 +07:00
parent 8f60b79b39
commit b178752244
2 changed files with 26 additions and 5 deletions
@@ -514,10 +514,13 @@ impl StackDialog for HostedSaveForWeb {
}
fn show(&mut self, ui: &mut Ui, _: &DialogStack) -> Option<DialogResult<SaveForWebResult>> {
// 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);
@@ -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");
}