From b1af55834dab0de2b3a4d0b9a4cac2e3a7fec236 Mon Sep 17 00:00:00 2001 From: bflatastic Date: Sun, 22 Nov 2026 21:01:13 +0700 Subject: [PATCH] ui-patterns: NewDocumentDialog print_resolution and screen_resolution are quantity props again, set over the setup through DocumentSettings::set_resolutions --- .../src/patterns/form_dialogs/new_document.rs | 34 ++++++++++--------- .../form_dialogs/new_document/settings.rs | 10 ++++++ 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/crates/ui-patterns/src/patterns/form_dialogs/new_document.rs b/crates/ui-patterns/src/patterns/form_dialogs/new_document.rs index 063b1b761..30674af04 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/new_document.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/new_document.rs @@ -509,6 +509,12 @@ pub struct NewDocumentDialog<'a, S: DocumentSettings = DocumentOptions> { /// What the dialog is set up with besides the cards. #[prop] setup: S::Setup, + /// The resolution print presets open at, in pixels per inch, over the setup's. + #[prop(quantity = "resolution in pixels per inch")] + print_resolution: Option, + /// The resolution screen presets open at, in pixels per inch, over the setup's. + #[prop(quantity = "resolution in pixels per inch")] + screen_resolution: Option, } impl<'a, S: DocumentSettings> NewDocumentDialog<'a, S> { @@ -526,6 +532,8 @@ impl<'a, S: DocumentSettings> NewDocumentDialog<'a, S> { answers: Vec::new(), opening: None, setup: S::Setup::default(), + print_resolution: None, + screen_resolution: None, } } } @@ -561,20 +569,6 @@ impl<'a> NewDocumentDialog<'a, DocumentOptions> { self } - /// The resolution print presets open at, in pixels per inch. - #[must_use] - pub fn print_resolution(mut self, pixels_per_inch: f64) -> Self { - self.setup.print_ppi = pixels_per_inch; - self - } - - /// The resolution screen presets open at, in pixels per inch. - #[must_use] - pub fn screen_resolution(mut self, pixels_per_inch: f64) -> Self { - self.setup.screen_ppi = pixels_per_inch; - self - } - /// The colour profiles each mode offers. #[must_use] pub fn profiles(mut self, profiles: Vec) -> Self { @@ -612,8 +606,11 @@ impl<'a, S: DocumentSettings> NewDocumentDialog<'a, S> { remember, answers, opening, - setup, + mut setup, + print_resolution, + screen_resolution, } = self; + S::set_resolutions(&mut setup, print_resolution, screen_resolution); let recent_is_bound = recent_bound.is_some(); let recent: Vec = match recent_bound.as_mut() { Some(bind) => read_bind(bind).unwrap_or_default(), @@ -782,7 +779,12 @@ impl HostedNewDocument { /// app's name). The settings open at once (the clipboard's size, the default name from the root's words), so /// automation lists and sets them before the first pass. pub fn new(ctx: &egui::Context, mut options: S, build: impl for<'b> Fn(&'b mut S) -> NewDocumentDialog<'b, S> + Send + 'static) -> Self { - let setup = build(&mut options).setup; + let setup = { + let built = build(&mut options); + let mut setup = built.setup; + S::set_resolutions(&mut setup, built.print_resolution, built.screen_resolution); + setup + }; options.open(&setup, Env::of_root(ctx).words::().untitled.as_str()); HostedNewDocument { id: dialog_id("new-document"), diff --git a/crates/ui-patterns/src/patterns/form_dialogs/new_document/settings.rs b/crates/ui-patterns/src/patterns/form_dialogs/new_document/settings.rs index c9b95aec9..ec1be5b18 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/new_document/settings.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/new_document/settings.rs @@ -42,6 +42,11 @@ pub trait DocumentSettings: Clone + PartialEq + Debug + Default + Serialize + De fn note_set(&mut self, field: &str, memory: &mut Self::Memory) { let _ = (field, memory); } + /// Sets the resolutions print and screen presets open at in `setup`, in pixels per inch, each the host gave + /// ([`NewDocumentDialog::print_resolution`](super::NewDocumentDialog::print_resolution)); nothing by default. + fn set_resolutions(setup: &mut Self::Setup, print: Option, screen: Option) { + let _ = (setup, print, screen); + } /// Fills what the dialog adds to the settings it opens on: the clipboard's size and the default name `untitled`. fn open(&mut self, setup: &Self::Setup, untitled: &str); /// The card of a built-in `preset`. @@ -301,6 +306,11 @@ impl DocumentSettings for DocumentOptions { DocumentOptions::fitted(self) } + fn set_resolutions(setup: &mut Self::Setup, print: Option, screen: Option) { + setup.print_ppi = print.unwrap_or(setup.print_ppi); + setup.screen_ppi = screen.unwrap_or(setup.screen_ppi); + } + fn open(&mut self, setup: &Self::Setup, untitled: &str) { if let Some(size) = setup.clipboard { self.size = size;