ui-patterns: NewDocumentDialog print_resolution and screen_resolution are quantity props again, set over the setup through DocumentSettings::set_resolutions

This commit is contained in:
bflatastic
2026-11-22 21:01:13 +07:00
parent bcce1c9f89
commit b1af55834d
2 changed files with 28 additions and 16 deletions
@@ -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<f64>,
/// The resolution screen presets open at, in pixels per inch, over the setup's.
#[prop(quantity = "resolution in pixels per inch")]
screen_resolution: Option<f64>,
}
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<ColorProfiles>) -> 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<S> = match recent_bound.as_mut() {
Some(bind) => read_bind(bind).unwrap_or_default(),
@@ -782,7 +779,12 @@ impl<S: DocumentSettings> HostedNewDocument<S> {
/// 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::<NewDocumentWords>().untitled.as_str());
HostedNewDocument {
id: dialog_id("new-document"),
@@ -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<f64>, screen: Option<f64>) {
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<f64>, screen: Option<f64>) {
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;