From 35535b77203239df7bff207cff0b3f6cf78334cc Mon Sep 17 00:00:00 2001 From: bflatastic Date: Sun, 22 Nov 2026 20:11:08 +0700 Subject: [PATCH] ui-patterns: ParamDialog keeps its footer rows' states and pending flip in one session slot (runtime::memory::with_session), not egui temp data; the chord story narrows its room in testing::memory::scoped --- .../src/patterns/form_dialogs/dialog.rs | 22 +++++++++++++------ crates/ui-widgets/src/buttons/stories.rs | 3 +-- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/crates/ui-patterns/src/patterns/form_dialogs/dialog.rs b/crates/ui-patterns/src/patterns/form_dialogs/dialog.rs index 9b3acb2c97..b00411317f 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/dialog.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/dialog.rs @@ -27,7 +27,7 @@ use crate::layout_components::{Row, Stack}; use crate::runtime::env::{Env, Label}; use crate::text::RangeAlert; -use crate::runtime::memory::{Lifetime, MemoryStage}; +use crate::runtime::memory::{Lifetime, MemoryStage, with_session}; use crate::runtime::overlay::CloseReason; use crate::runtime::words::CommonWords; @@ -314,6 +314,14 @@ impl<'a> ParamPresets<'a> { } } +/// The footer rows of a [`ParamDialog`] between passes: whether each was on when the last pass ended, which its +/// button label shows, and the key of the row whose button was pressed, which the next pass flips. +#[derive(Clone, Debug, Default)] +struct FooterRows { + on: Vec, + flip: Option, +} + /// What `ParamDialog::below` draws under the rows. pub struct BelowRows<'a>(BelowRowsFn<'a>); @@ -516,9 +524,9 @@ impl<'a> ParamDialog<'a> { // The footer rows' buttons follow the extra buttons. A button's label cannot change inside the pass that // draws it, so it shows the state the previous pass left. let footer_rows: Vec<&Param> = params.iter().filter(|param| param.footer_on().is_some()).collect(); - let footer_id = egui::Id::unique(("paramDialog.footer", key.as_str())); - let flip_id = footer_id.with("flip"); - let footer_states: Vec = if footer_rows.is_empty() { Vec::new() } else { ui.data(|data| data.get_temp(footer_id)).unwrap_or_default() }; + let footer_id = crate::runtime::memory::unique(("paramDialog.footer", key.as_str())); + let footer_states: Vec = + if footer_rows.is_empty() { Vec::new() } else { with_session(ui.ctx(), footer_id, |footer: &mut FooterRows| footer.on.clone()) }; let footer_buttons = footer_rows.iter().enumerate().map(|(at, param)| { let on = footer_states.get(at).copied().unwrap_or(false); let label = param.footer_on().filter(|_| on).unwrap_or_else(|| param.label.clone()); @@ -551,7 +559,7 @@ impl<'a> ParamDialog<'a> { apply_answers(¶ms, values, cx.take_answers()); // A footer row pressed in the previous pass flips once; a measuring run leaves it for the real one. if !footer_rows.is_empty() && !crate::runtime::measure::active(ui.ctx()) { - if let Some(flip) = ui.data_mut(|data| data.remove_temp::(flip_id)) { + if let Some(flip) = with_session(ui.ctx(), footer_id, |footer: &mut FooterRows| footer.flip.take()) { let on = values.bool(&flip).unwrap_or(false); values.set(flip, FieldValue::Bool(!on)); } @@ -604,7 +612,7 @@ impl<'a> ParamDialog<'a> { *cx.memory::() = live.clone(); if !footer_rows.is_empty() { let states: Vec = footer_rows.iter().map(|param| values.bool(¶m.key).unwrap_or(false)).collect(); - ui.data_mut(|data| data.insert_temp(footer_id, states)); + with_session(ui.ctx(), footer_id, |footer: &mut FooterRows| footer.on = states); } // OK and Enter wait while a row's text does not parse. rows.as_ref().is_none_or(|rows| !rows.unparsed) @@ -619,7 +627,7 @@ impl<'a> ParamDialog<'a> { if let Some(ResetPick::Extra(at)) = pick && let Some(param) = at.checked_sub(extra_buttons.len()).and_then(|at| footer_rows.get(at)) { - ui.data_mut(|data| data.insert_temp(flip_id, param.key.clone())); + with_session(ui.ctx(), footer_id, |footer: &mut FooterRows| footer.flip = Some(param.key.clone())); crate::runtime::frame::request_repaint(ui.ctx()); } let result = shown.accepted.map(|fields| Self::result(key, ¶ms, remember, remember_for, fields)); diff --git a/crates/ui-widgets/src/buttons/stories.rs b/crates/ui-widgets/src/buttons/stories.rs index 953649b169..817b00e774 100644 --- a/crates/ui-widgets/src/buttons/stories.rs +++ b/crates/ui-widgets/src/buttons/stories.rs @@ -418,11 +418,10 @@ fn button_chord_narrow_room(ui: &mut Ui, _: &mut StoryData) -> StoryOutput { let width = |chord| Button::command(EditCommands::Copy).chord(chord).measure_in(ui, Proposal::Ideal).x; // Halfway between the button without its chord and with it: room for the whole label, not for the chord too. let room = (width(ButtonChord::Hidden) + width(ButtonChord::Trailing)) / 2.0; - ui.scope(|ui| { + crate::testing::memory::scoped(ui, |ui| { ui.set_max_width(room.min(ui.available_width())); Button::command(EditCommands::Copy).chord(ButtonChord::Trailing).show(ui) }) - .inner .into() }