From 1e5782dfd4432bbdf8e536d2f451951b8467c169 Mon Sep 17 00:00:00 2001 From: aiongg Date: Fri, 13 Nov 2026 02:17:08 +0000 Subject: [PATCH] Dialogs: StackDialog::story_facts; hosted forms keep their last pass's facts and hosted stories report them --- crates/imaging/src/ui/adjust/hosted.rs | 13 +++++++++++ crates/imaging/src/ui/layer_style/hosted.rs | 15 ++++++++++++ crates/ui-panels/src/dialog/alert.rs | 18 ++++++++++++++- crates/ui-panels/src/dialog/host.rs | 8 +++++++ crates/ui-panels/src/dialog/stories.rs | 6 +++-- crates/ui-panels/tests/it/dialogs.rs | 1 + .../src/patterns/form_dialogs/about.rs | 22 +++++++++++++++++- .../patterns/form_dialogs/export/as_dialog.rs | 13 +++++++++++ .../patterns/form_dialogs/export/options.rs | 20 +++++++++++++++- .../patterns/form_dialogs/sizing/canvas.rs | 23 +++++++++++++++++-- .../src/patterns/form_dialogs/sizing/image.rs | 23 +++++++++++++++++-- 11 files changed, 153 insertions(+), 9 deletions(-) diff --git a/crates/imaging/src/ui/adjust/hosted.rs b/crates/imaging/src/ui/adjust/hosted.rs index 998d23683..4686c397f 100644 --- a/crates/imaging/src/ui/adjust/hosted.rs +++ b/crates/imaging/src/ui/adjust/hosted.rs @@ -39,6 +39,8 @@ pub struct HostedAdjustDialog { remember: Option, editor: Box>, asks: Vec, + #[cfg(feature = "screen-testing")] + facts: craft_ui::testing::StoryOutput, } impl HostedAdjustDialog { @@ -65,6 +67,8 @@ impl HostedAdjustDialog { remember: None, editor: Box::new(editor), asks: Vec::new(), + #[cfg(feature = "screen-testing")] + facts: craft_ui::testing::StoryOutput::default(), } } @@ -147,6 +151,10 @@ impl StackDialog for HostedAdjustDialog StackDialog for HostedAdjustDialog Option<&str> { Some(&self.key) } + + #[cfg(feature = "screen-testing")] + fn story_facts(&self) -> craft_ui::testing::StoryOutput { + self.facts.clone() + } } diff --git a/crates/imaging/src/ui/layer_style/hosted.rs b/crates/imaging/src/ui/layer_style/hosted.rs index bdd9b37cc..1c4326868 100644 --- a/crates/imaging/src/ui/layer_style/hosted.rs +++ b/crates/imaging/src/ui/layer_style/hosted.rs @@ -85,6 +85,8 @@ pub struct HostedLayerStyle { styles: Option<(Vec>, Box)>, asks: Vec, comparing: bool, + #[cfg(feature = "screen-testing")] + facts: craft_ui::testing::StoryOutput, } /// The key of the hosted Layer Style dialog. @@ -109,6 +111,8 @@ impl HostedLayerStyle { styles: None, asks: Vec::new(), comparing: false, + #[cfg(feature = "screen-testing")] + facts: craft_ui::testing::StoryOutput::default(), } } @@ -223,6 +227,8 @@ impl StackDialog for HostedLayerStyle { styles, asks, comparing, + #[cfg(feature = "screen-testing")] + facts, .. } = self; // The draft holds Preview: the box edits a copy, written back only when the box changed it, so a Reset that @@ -247,6 +253,10 @@ impl StackDialog for HostedLayerStyle { body = body.style_presets(StylePresets::new(rows, |cx, rect, info| thumb(cx, rect, info))); } let out = body.show(ui); + #[cfg(feature = "screen-testing")] + { + *facts = craft_ui::contract::Outcome::story_facts(&out); + } out.apply_view(draft); if let Some(style) = out.edit.value() { draft.style = style.clone(); @@ -266,4 +276,9 @@ impl StackDialog for HostedLayerStyle { fn key(&self) -> Option<&str> { Some(KEY) } + + #[cfg(feature = "screen-testing")] + fn story_facts(&self) -> craft_ui::testing::StoryOutput { + self.facts.clone() + } } diff --git a/crates/ui-panels/src/dialog/alert.rs b/crates/ui-panels/src/dialog/alert.rs index 0f45bc23f..e0406aa70 100644 --- a/crates/ui-panels/src/dialog/alert.rs +++ b/crates/ui-panels/src/dialog/alert.rs @@ -121,12 +121,19 @@ impl AlertContent { pub struct HostedAlert { content: AlertContent, open: bool, + #[cfg(feature = "testing")] + facts: crate::testing::StoryOutput, } impl HostedAlert { /// `alert` on the host; its own `opened` binding is not used. pub fn new(alert: Alert<'_>) -> Self { - HostedAlert { content: alert.split().0, open: true } + HostedAlert { + content: alert.split().0, + open: true, + #[cfg(feature = "testing")] + facts: crate::testing::StoryOutput::default(), + } } } @@ -142,10 +149,19 @@ impl StackDialog for HostedAlert { fn show(&mut self, ui: &mut Ui, _: &DialogStack) -> Option> { let shown = self.content.prompt(&Env::of(ui)).opened(Bind::bound(&mut self.open)).show(ui); + #[cfg(feature = "testing")] + { + self.facts = crate::contract::Outcome::story_facts(&shown); + } shown.closed.map(|_| DialogResult::Ok(())) } fn key(&self) -> Option<&str> { Some(ALERT_KEY) } + + #[cfg(feature = "testing")] + fn story_facts(&self) -> crate::testing::StoryOutput { + self.facts.clone() + } } diff --git a/crates/ui-panels/src/dialog/host.rs b/crates/ui-panels/src/dialog/host.rs index 64000a19c..de67396d8 100644 --- a/crates/ui-panels/src/dialog/host.rs +++ b/crates/ui-panels/src/dialog/host.rs @@ -88,6 +88,14 @@ pub trait StackDialog: Any + Send { Err(format!("unknown field `{field}`: this dialog has no fields")) } + /// The facts a story reports about the dialog's last pass, as [`Outcome::story_facts`](crate::contract::Outcome) + /// reports a component's: hosted forms keep their component's. Empty by default. + #[cfg(feature = "testing")] + #[doc(hidden)] + fn story_facts(&self) -> crate::testing::StoryOutput { + crate::testing::StoryOutput::default() + } + /// Called when the host closes the dialog from outside with [`DialogResult::Cancel`] /// ([`DialogHost::cancel`], a dialog of the same type opened over it, or its parent closing), /// so it can release what it holds: a pick ticket (`Files::forget`), an armed dropper. The diff --git a/crates/ui-panels/src/dialog/stories.rs b/crates/ui-panels/src/dialog/stories.rs index d85a2a593..45aae2a16 100644 --- a/crates/ui-panels/src/dialog/stories.rs +++ b/crates/ui-panels/src/dialog/stories.rs @@ -21,7 +21,8 @@ pub fn body(ui: &mut Ui, checks: &mut [bool; 2]) { /// A story of a hosted dialog: `open()` on the story's [`DialogHost`] (a story note), which runs every pass. The story's `open` value /// is the dialog's open state, so the card holds the dialog behind its button as it holds any story dialog: the /// dialog opens while the value is on, and the value goes off when the dialog closes. `knobs` holds the story values -/// `open` reads; when they change, `open()` replaces the open dialog, so a knob reaches the dialog on screen. +/// `open` reads; when they change, `open()` replaces the open dialog, so a knob reaches the dialog on screen. The +/// story reports the open dialog's [`story_facts`](StackDialog::story_facts). #[doc(hidden)] pub fn hosted(ui: &mut Ui, data: &mut StoryData, knobs: K, open: impl FnOnce() -> D) -> StoryOutput { hosted_with(ui, data, knobs, open, |_| {}) @@ -53,11 +54,12 @@ pub fn hosted_with( pass(host); host.run(ui); let is_open = host.is_open::(); + let facts = host.get::().map(StackDialog::story_facts).unwrap_or_default(); if opened { *data.note::>("knobs", None) = Some(knobs); } *data.value("open", true) = is_open; - StoryOutput::default() + facts } /// The opener of the Grid options dialogs. diff --git a/crates/ui-panels/tests/it/dialogs.rs b/crates/ui-panels/tests/it/dialogs.rs index 723e990ab..91cfcbdef 100644 --- a/crates/ui-panels/tests/it/dialogs.rs +++ b/crates/ui-panels/tests/it/dialogs.rs @@ -67,6 +67,7 @@ fn a_story_knob_reaches_its_open_hosted_dialog() { let mut fixture = Fixture::story(&Story::new("titled_alert", titled_alert)); fixture.idle(6); assert!(fixture.by_label("Could not open").is_some(), "the story opens its dialog"); + assert!(fixture.take_outputs().last().is_some_and(|output| output.id.is_some()), "the story reports the open dialog's facts"); *fixture.data().value("title", "Could not open") = "Could not save"; fixture.idle(6); assert!(fixture.by_label("Could not save").is_some(), "the changed knob shows in the open dialog"); diff --git a/crates/ui-patterns/src/patterns/form_dialogs/about.rs b/crates/ui-patterns/src/patterns/form_dialogs/about.rs index 40b3a55b4..3b3f680c7 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/about.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/about.rs @@ -469,12 +469,23 @@ pub struct HostedAbout { tab: Option, link: Option, open: bool, + #[cfg(feature = "testing")] + facts: crate::testing::StoryOutput, } impl HostedAbout { /// The dialog over `info` and `credits`, opening on the About tab. pub fn new(info: AboutInfo, credits: Credits) -> Self { - HostedAbout { id: dialog_id(ABOUT_KEY), info, credits, tab: None, link: None, open: true } + HostedAbout { + id: dialog_id(ABOUT_KEY), + info, + credits, + tab: None, + link: None, + open: true, + #[cfg(feature = "testing")] + facts: crate::testing::StoryOutput::default(), + } } /// The tab the dialog opens on. @@ -502,6 +513,10 @@ impl StackDialog for HostedAbout { fn show(&mut self, ui: &mut Ui, _: &DialogStack) -> Option> { let shown = AboutDialog { info: &self.info, credits: &self.credits, open: Some(Bind::bound(&mut self.open)), tab: self.tab }.show(ui); + #[cfg(feature = "testing")] + { + self.facts = crate::contract::Outcome::story_facts(&shown); + } if let Some(link) = shown.link { self.link = Some(link); } @@ -511,4 +526,9 @@ impl StackDialog for HostedAbout { fn key(&self) -> Option<&str> { Some(ABOUT_KEY) } + + #[cfg(feature = "testing")] + fn story_facts(&self) -> crate::testing::StoryOutput { + self.facts.clone() + } } diff --git a/crates/ui-patterns/src/patterns/form_dialogs/export/as_dialog.rs b/crates/ui-patterns/src/patterns/form_dialogs/export/as_dialog.rs index 8213e26b7..698c3d6c6 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/export/as_dialog.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/export/as_dialog.rs @@ -251,6 +251,8 @@ pub struct HostedExportAs { requests: HostRequests, saving: bool, open: bool, + #[cfg(feature = "testing")] + facts: crate::testing::StoryOutput, } impl HostedExportAs { @@ -268,6 +270,8 @@ impl HostedExportAs { requests: HostRequests::new(), saving: false, open: true, + #[cfg(feature = "testing")] + facts: crate::testing::StoryOutput::default(), } } @@ -340,6 +344,10 @@ impl StackDialog for HostedExportAs { ..ExportAsDialog::new(self.file_name.clone(), self.source, Bind::bound(&mut self.options)) }; let mut shown = dialog.show(ui); + #[cfg(feature = "testing")] + { + self.facts = crate::contract::Outcome::story_facts(&shown); + } if let Some(wanted) = shown.wanted_preview { self.wanted = Some(wanted); } @@ -361,6 +369,11 @@ impl StackDialog for HostedExportAs { Some(EXPORT_KEY) } + #[cfg(feature = "testing")] + fn story_facts(&self) -> crate::testing::StoryOutput { + self.facts.clone() + } + fn cancelled(&mut self, _: &egui::Context) { self.cancel_requests(); } diff --git a/crates/ui-patterns/src/patterns/form_dialogs/export/options.rs b/crates/ui-patterns/src/patterns/form_dialogs/export/options.rs index 96b1f3b9d..06187a8ad 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/export/options.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/export/options.rs @@ -373,12 +373,21 @@ pub struct HostedFormatOptions { kind: ExportOptionsKind, initial: Option, open: bool, + #[cfg(feature = "testing")] + facts: crate::testing::StoryOutput, } impl HostedFormatOptions { /// The options dialog of `kind`. pub fn new(kind: ExportOptionsKind) -> Self { - HostedFormatOptions { id: dialog_id(options_key(kind)), kind, initial: None, open: true } + HostedFormatOptions { + id: dialog_id(options_key(kind)), + kind, + initial: None, + open: true, + #[cfg(feature = "testing")] + facts: crate::testing::StoryOutput::default(), + } } /// The options the dialog opens with, when they are the options of its format. @@ -403,6 +412,10 @@ impl StackDialog for HostedFormatOptions { fn show(&mut self, ui: &mut Ui, _: &DialogStack) -> Option> { let shown = FormatOptionsDialog { kind: self.kind, open: Some(Bind::bound(&mut self.open)), initial: self.initial }.show(ui); + #[cfg(feature = "testing")] + { + self.facts = crate::contract::Outcome::story_facts(&shown); + } match (shown.result, shown.closed) { (Some(options), _) => Some(DialogResult::Ok(options)), (None, Some(_)) => Some(DialogResult::Cancel), @@ -413,6 +426,11 @@ impl StackDialog for HostedFormatOptions { fn key(&self) -> Option<&str> { Some(options_key(self.kind)) } + + #[cfg(feature = "testing")] + fn story_facts(&self) -> crate::testing::StoryOutput { + self.facts.clone() + } } /// The parameter list of `start`'s format. diff --git a/crates/ui-patterns/src/patterns/form_dialogs/sizing/canvas.rs b/crates/ui-patterns/src/patterns/form_dialogs/sizing/canvas.rs index fa2e3d116..46d31616c 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/sizing/canvas.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/sizing/canvas.rs @@ -216,12 +216,21 @@ pub struct HostedCanvasSize { open: bool, values: CanvasSizeValues, build: Box, + #[cfg(feature = "testing")] + facts: crate::testing::StoryOutput, } impl HostedCanvasSize { /// A dialog opening with `values`; `build` makes it over the values (`CanvasSize::new` with its settings). pub fn new(values: CanvasSizeValues, build: impl for<'b> Fn(Bind<'b, CanvasSizeValues>) -> CanvasSize<'b> + Send + 'static) -> Self { - HostedCanvasSize { id: dialog_id(KEY), open: true, values, build: Box::new(build) } + HostedCanvasSize { + id: dialog_id(KEY), + open: true, + values, + build: Box::new(build), + #[cfg(feature = "testing")] + facts: crate::testing::StoryOutput::default(), + } } /// The values the dialog shows. @@ -241,10 +250,20 @@ impl StackDialog for HostedCanvasSize { } fn show(&mut self, ui: &mut Ui, _: &DialogStack) -> Option> { - (self.build)(Bind::bound(&mut self.values)).opened(Bind::bound(&mut self.open)).show(ui).hosted() + let shown = (self.build)(Bind::bound(&mut self.values)).opened(Bind::bound(&mut self.open)).show(ui); + #[cfg(feature = "testing")] + { + self.facts = crate::contract::Outcome::story_facts(&shown); + } + shown.hosted() } fn key(&self) -> Option<&str> { Some(KEY) } + + #[cfg(feature = "testing")] + fn story_facts(&self) -> crate::testing::StoryOutput { + self.facts.clone() + } } diff --git a/crates/ui-patterns/src/patterns/form_dialogs/sizing/image.rs b/crates/ui-patterns/src/patterns/form_dialogs/sizing/image.rs index 08f8dc413..cdba52033 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/sizing/image.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/sizing/image.rs @@ -220,12 +220,21 @@ pub struct HostedImageSize { open: bool, values: ImageSizeValues, build: Box, + #[cfg(feature = "testing")] + facts: crate::testing::StoryOutput, } impl HostedImageSize { /// A dialog opening with `values`; `build` makes it over the values (`ImageSize::new` with its settings). pub fn new(values: ImageSizeValues, build: impl for<'b> Fn(Bind<'b, ImageSizeValues>) -> ImageSize<'b> + Send + 'static) -> Self { - HostedImageSize { id: dialog_id(KEY), open: true, values, build: Box::new(build) } + HostedImageSize { + id: dialog_id(KEY), + open: true, + values, + build: Box::new(build), + #[cfg(feature = "testing")] + facts: crate::testing::StoryOutput::default(), + } } /// The values the dialog shows. @@ -245,10 +254,20 @@ impl StackDialog for HostedImageSize { } fn show(&mut self, ui: &mut Ui, _: &DialogStack) -> Option> { - (self.build)(Bind::bound(&mut self.values)).opened(Bind::bound(&mut self.open)).show(ui).hosted() + let shown = (self.build)(Bind::bound(&mut self.values)).opened(Bind::bound(&mut self.open)).show(ui); + #[cfg(feature = "testing")] + { + self.facts = crate::contract::Outcome::story_facts(&shown); + } + shown.hosted() } fn key(&self) -> Option<&str> { Some(KEY) } + + #[cfg(feature = "testing")] + fn story_facts(&self) -> crate::testing::StoryOutput { + self.facts.clone() + } }