mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-29 17:55:45 +01:00
Merge pull request #2254 from RickiNano/newdoc-preset-lists
New Document: Photo, Print and Art & Illustration list the blank document presets (photocraft#14040)
This commit is contained in:
3 files changed
+168
-31
No files matched your search
@@ -292,7 +292,7 @@ fn preset_title(preset: &DocumentPreset, setup: &RasterSetup, words: &NewDocumen
|
||||
pub(super) fn raster_preset_card(preset: &DocumentPreset, cx: &CardCx<'_, DocumentOptions>) -> DocumentCard<DocumentOptions> {
|
||||
let preset = cx.orientation.map_or_else(|| preset.clone(), |orientation| preset.turned(orientation));
|
||||
let mut settings = preset.options(cx.setup.print_ppi, cx.setup.screen_ppi);
|
||||
if preset.is_print() && !matches!(cx.values.unit, UnitKind::Pixels | UnitKind::Percent) {
|
||||
if preset.in_inches() && !matches!(cx.values.unit, UnitKind::Pixels | UnitKind::Percent) {
|
||||
settings.unit = cx.values.unit;
|
||||
}
|
||||
DocumentCard::new(
|
||||
|
||||
@@ -266,12 +266,14 @@ pub struct DocumentPreset {
|
||||
pub pixels_per_inch: f64,
|
||||
/// Picking the card turns Artboards on (Photoshop's Web and Mobile presets).
|
||||
pub artboard: bool,
|
||||
/// A print preset sized in pixels (a pixel grid): it shows and applies its pixels, at the app's print resolution.
|
||||
pub pixel_sized: bool,
|
||||
}
|
||||
|
||||
impl DocumentPreset {
|
||||
/// The card `id`, named `name` in English, for a page of `width` x `height` pixels at `pixels_per_inch`.
|
||||
pub const fn new(id: &'static str, name: &'static str, width: u32, height: u32, pixels_per_inch: f64) -> Self {
|
||||
Self { id, name, width, height, pixels_per_inch, artboard: false }
|
||||
Self { id, name, width, height, pixels_per_inch, artboard: false, pixel_sized: false }
|
||||
}
|
||||
|
||||
/// The card turns Artboards on when picked.
|
||||
@@ -281,12 +283,25 @@ impl DocumentPreset {
|
||||
self
|
||||
}
|
||||
|
||||
/// Whether the preset is for print (300 ppi and up): its card and fields show inches at the app's print resolution;
|
||||
/// screen presets stay in pixels.
|
||||
/// The card keeps its pixels: it shows and applies them at the app's print resolution instead of keeping a page
|
||||
/// size in inches.
|
||||
#[must_use]
|
||||
pub const fn pixel_sized(mut self) -> Self {
|
||||
self.pixel_sized = true;
|
||||
self
|
||||
}
|
||||
|
||||
/// Whether the preset is for print (300 ppi and up): it takes the app's print resolution; screen presets take the
|
||||
/// screen resolution.
|
||||
pub fn is_print(&self) -> bool {
|
||||
self.pixels_per_inch >= 300.0
|
||||
}
|
||||
|
||||
/// Whether the card and fields show the preset in inches: a print preset that is not [`pixel_sized`](Self::pixel_sized).
|
||||
pub fn in_inches(&self) -> bool {
|
||||
self.is_print() && !self.pixel_sized
|
||||
}
|
||||
|
||||
/// The preset turned to `orientation`; a square preset stays as it is.
|
||||
#[must_use]
|
||||
pub fn turned(&self, orientation: Orientation) -> DocumentPreset {
|
||||
@@ -297,14 +312,15 @@ impl DocumentPreset {
|
||||
DocumentPreset { width: self.height, height: self.width, ..self.clone() }
|
||||
}
|
||||
|
||||
/// The preset as settings: the unit (inches for print, pixels for screen) and the resolution moved to the app's
|
||||
/// print or screen resolution, keeping a print preset's physical size.
|
||||
/// The preset as settings: the unit (inches for print, pixels for screen and pixel-sized presets) and the
|
||||
/// resolution moved to the app's print or screen resolution, keeping a print preset's physical size and any other
|
||||
/// preset's pixels.
|
||||
pub fn options(&self, print_ppi: f64, screen_ppi: f64) -> DocumentOptions {
|
||||
let print = self.is_print();
|
||||
let wanted = if print { print_ppi } else { screen_ppi };
|
||||
let inches = self.in_inches();
|
||||
let wanted = if self.is_print() { print_ppi } else { screen_ppi };
|
||||
let (width, height, pixels_per_inch) = if !(wanted.is_finite() && wanted > 0.0) {
|
||||
(self.width, self.height, self.pixels_per_inch)
|
||||
} else if print {
|
||||
} else if inches {
|
||||
let scale = wanted / self.pixels_per_inch;
|
||||
let pixels = |side: u32| (f64::from(side) * scale).round().clamp(1.0, MAX_DOCUMENT_SIDE) as u32;
|
||||
(pixels(self.width), pixels(self.height), wanted)
|
||||
@@ -314,7 +330,7 @@ impl DocumentPreset {
|
||||
DocumentOptions {
|
||||
size: PixelSize::new(width, height),
|
||||
pixels_per_inch,
|
||||
unit: if print { UnitKind::Inches } else { UnitKind::Pixels },
|
||||
unit: if inches { UnitKind::Inches } else { UnitKind::Pixels },
|
||||
..DocumentOptions::default()
|
||||
}
|
||||
}
|
||||
@@ -348,12 +364,15 @@ impl PresetCategory<DocumentPreset> {
|
||||
"photo",
|
||||
"Photo",
|
||||
vec![
|
||||
DocumentPreset::new(DEFAULT_ID, "Default Size", 2100, 1500, 300.0),
|
||||
DocumentPreset::new("landscape-3x2", "Landscape, 3 x 2", 900, 600, 300.0),
|
||||
DocumentPreset::new("landscape-6x4", "Landscape, 6 x 4", 1800, 1200, 300.0),
|
||||
DocumentPreset::new("landscape-7x5", "Landscape, 7 x 5", 2100, 1500, 300.0),
|
||||
DocumentPreset::new("landscape-10x8", "Landscape, 10 x 8", 3000, 2400, 300.0),
|
||||
DocumentPreset::new("portrait-2x3", "Portrait, 2 x 3", 600, 900, 300.0),
|
||||
DocumentPreset::new("portrait-4x6", "Portrait, 4 x 6", 1200, 1800, 300.0),
|
||||
DocumentPreset::new("portrait-5x7", "Portrait, 5 x 7", 1500, 2100, 300.0),
|
||||
DocumentPreset::new("square-5x5", "Square, 5 x 5", 1500, 1500, 300.0),
|
||||
DocumentPreset::new("portrait-8x10", "Portrait, 8 x 10", 2400, 3000, 300.0),
|
||||
],
|
||||
),
|
||||
PresetCategory::new(
|
||||
@@ -364,20 +383,28 @@ impl PresetCategory<DocumentPreset> {
|
||||
DocumentPreset::new("legal", "Legal", 2550, 4200, 300.0),
|
||||
DocumentPreset::new("tabloid", "Tabloid", 3300, 5100, 300.0),
|
||||
DocumentPreset::new("a4", "A4", 2480, 3508, 300.0),
|
||||
DocumentPreset::new("a3", "A3", 3508, 4961, 300.0),
|
||||
DocumentPreset::new("a6", "A6", 1240, 1748, 300.0),
|
||||
DocumentPreset::new("a5", "A5", 1748, 2480, 300.0),
|
||||
DocumentPreset::new("b3", "B3", 4169, 5906, 300.0),
|
||||
DocumentPreset::new("a3", "A3", 3508, 4961, 300.0),
|
||||
DocumentPreset::new("b5", "B5", 2079, 2953, 300.0),
|
||||
DocumentPreset::new("b4", "B4", 2953, 4169, 300.0),
|
||||
DocumentPreset::new("b3", "B3", 4169, 5906, 300.0),
|
||||
DocumentPreset::new("c4", "C4", 2705, 3827, 300.0),
|
||||
DocumentPreset::new("c5", "C5", 1913, 2705, 300.0),
|
||||
DocumentPreset::new("c6", "C6", 1346, 1913, 300.0),
|
||||
DocumentPreset::new("dl", "DL", 1299, 2598, 300.0),
|
||||
],
|
||||
),
|
||||
PresetCategory::new(
|
||||
"art",
|
||||
"Art & Illustration",
|
||||
vec![
|
||||
DocumentPreset::new("grid-1000", "1000 pixel grid", 1000, 1000, 300.0).pixel_sized(),
|
||||
DocumentPreset::new("grid-2000", "2000 pixel grid", 2000, 2000, 300.0).pixel_sized(),
|
||||
DocumentPreset::new("poster", "Poster", 5400, 7200, 300.0),
|
||||
DocumentPreset::new("postcard", "Postcard", 1800, 1200, 300.0),
|
||||
DocumentPreset::new("comic-book", "Comic Book", 1988, 3075, 300.0),
|
||||
DocumentPreset::new("square-12x12", "Square, 12 x 12", 3600, 3600, 300.0),
|
||||
DocumentPreset::new("postcard", "Postcard", 1200, 1800, 300.0),
|
||||
DocumentPreset::new("video-1080p", "1080p", 1920, 1080, 72.0),
|
||||
DocumentPreset::new("video-720p", "720p", 1280, 720, 72.0),
|
||||
],
|
||||
),
|
||||
PresetCategory::new(
|
||||
@@ -464,24 +491,34 @@ craft_ui::words! {
|
||||
/// The names of the built-in presets, in the order of `PRESET_IDS`.
|
||||
pub struct NewDocumentPresetWords {
|
||||
names: array [
|
||||
"newDocumentPreset.landscape3x2" = "Landscape, 3 x 2",
|
||||
"newDocumentPreset.landscape6x4" = "Landscape, 6 x 4",
|
||||
"newDocumentPreset.landscape7x5" = "Landscape, 7 x 5",
|
||||
"newDocumentPreset.landscape10x8" = "Landscape, 10 x 8",
|
||||
"newDocumentPreset.portrait2x3" = "Portrait, 2 x 3",
|
||||
"newDocumentPreset.portrait4x6" = "Portrait, 4 x 6",
|
||||
"newDocumentPreset.portrait5x7" = "Portrait, 5 x 7",
|
||||
"newDocumentPreset.square5x5" = "Square, 5 x 5",
|
||||
"newDocumentPreset.portrait8x10" = "Portrait, 8 x 10",
|
||||
"newDocumentPreset.letter" = "Letter",
|
||||
"newDocumentPreset.legal" = "Legal",
|
||||
"newDocumentPreset.tabloid" = "Tabloid",
|
||||
"newDocumentPreset.a4" = "A4",
|
||||
"newDocumentPreset.a3" = "A3",
|
||||
"newDocumentPreset.a6" = "A6",
|
||||
"newDocumentPreset.a5" = "A5",
|
||||
"newDocumentPreset.b3" = "B3",
|
||||
"newDocumentPreset.a3" = "A3",
|
||||
"newDocumentPreset.b5" = "B5",
|
||||
"newDocumentPreset.b4" = "B4",
|
||||
"newDocumentPreset.b3" = "B3",
|
||||
"newDocumentPreset.c4" = "C4",
|
||||
"newDocumentPreset.c5" = "C5",
|
||||
"newDocumentPreset.c6" = "C6",
|
||||
"newDocumentPreset.dl" = "DL",
|
||||
"newDocumentPreset.grid1000" = "1000 pixel grid",
|
||||
"newDocumentPreset.grid2000" = "2000 pixel grid",
|
||||
"newDocumentPreset.poster" = "Poster",
|
||||
"newDocumentPreset.postcard" = "Postcard",
|
||||
"newDocumentPreset.comicBook" = "Comic Book",
|
||||
"newDocumentPreset.square12x12" = "Square, 12 x 12",
|
||||
"newDocumentPreset.video1080p" = "1080p",
|
||||
"newDocumentPreset.video720p" = "720p",
|
||||
"newDocumentPreset.webMostCommon" = "Web Most Common",
|
||||
"newDocumentPreset.webMinimum" = "Web Minimum",
|
||||
"newDocumentPreset.webLarge" = "Web Large",
|
||||
@@ -502,25 +539,35 @@ craft_ui::words! {
|
||||
}
|
||||
|
||||
/// The ids of the built-in presets, in the order of `PresetWords::names`.
|
||||
const PRESET_IDS: [&str; 33] = [
|
||||
const PRESET_IDS: [&str; 43] = [
|
||||
"landscape-3x2",
|
||||
"landscape-6x4",
|
||||
"landscape-7x5",
|
||||
"landscape-10x8",
|
||||
"portrait-2x3",
|
||||
"portrait-4x6",
|
||||
"portrait-5x7",
|
||||
"square-5x5",
|
||||
"portrait-8x10",
|
||||
"letter",
|
||||
"legal",
|
||||
"tabloid",
|
||||
"a4",
|
||||
"a3",
|
||||
"a6",
|
||||
"a5",
|
||||
"b3",
|
||||
"a3",
|
||||
"b5",
|
||||
"b4",
|
||||
"b3",
|
||||
"c4",
|
||||
"c5",
|
||||
"c6",
|
||||
"dl",
|
||||
"grid-1000",
|
||||
"grid-2000",
|
||||
"poster",
|
||||
"postcard",
|
||||
"comic-book",
|
||||
"square-12x12",
|
||||
"video-1080p",
|
||||
"video-720p",
|
||||
"web-most-common",
|
||||
"web-minimum",
|
||||
"web-large",
|
||||
|
||||
@@ -191,10 +191,10 @@ fn the_orientation_turns_the_built_in_cards() {
|
||||
};
|
||||
|
||||
turn(&mut fixture, "Portrait");
|
||||
pick(&mut fixture, "Art & Illustration", "Postcard");
|
||||
pick(&mut fixture, "Art & Illustration", "1080p");
|
||||
let (width, height) = page(&shared);
|
||||
assert!(height > width, "Portrait turns the landscape Postcard: {width} x {height}");
|
||||
pick(&mut fixture, "Art & Illustration", "Comic Book");
|
||||
assert!(height > width, "Portrait turns the landscape 1080p: {width} x {height}");
|
||||
pick(&mut fixture, "Art & Illustration", "720p");
|
||||
let (width, height) = page(&shared);
|
||||
assert!(height > width, "the orientation stays for the next card: {width} x {height}");
|
||||
|
||||
@@ -202,7 +202,7 @@ fn the_orientation_turns_the_built_in_cards() {
|
||||
pick(&mut fixture, "Art & Illustration", "Poster");
|
||||
let (width, height) = page(&shared);
|
||||
assert!(width > height, "Landscape turns the portrait Poster: {width} x {height}");
|
||||
pick(&mut fixture, "Art & Illustration", "Postcard");
|
||||
pick(&mut fixture, "Art & Illustration", "1080p");
|
||||
let (width, height) = page(&shared);
|
||||
assert!(width > height, "a landscape card stays wider than tall: {width} x {height}");
|
||||
}
|
||||
@@ -523,6 +523,96 @@ fn section_captions_paint_in_capitals_and_keep_their_text() {
|
||||
assert!(fixture.by_label("Preset Details").is_some(), "the accessible name keeps the text as written");
|
||||
}
|
||||
|
||||
/// The names of the standard category `id`, in card order.
|
||||
fn standard_names(id: &str) -> Vec<&'static str> {
|
||||
let categories = craft_ui::patterns::form_dialogs::PresetCategory::standard();
|
||||
categories.iter().find(|category| category.id == id).expect("a standard category").presets.iter().map(|preset| preset.name).collect()
|
||||
}
|
||||
|
||||
/// The standard preset `name` of category `id`.
|
||||
fn standard_preset(id: &str, name: &str) -> craft_ui::patterns::form_dialogs::DocumentPreset {
|
||||
let categories = craft_ui::patterns::form_dialogs::PresetCategory::standard();
|
||||
let category = categories.into_iter().find(|category| category.id == id).expect("a standard category");
|
||||
category.presets.into_iter().find(|preset| preset.name == name).expect("a standard preset")
|
||||
}
|
||||
|
||||
#[trial]
|
||||
fn photo_print_and_art_list_the_blank_document_presets() {
|
||||
assert_eq!(
|
||||
standard_names("photo"),
|
||||
[
|
||||
"Default Size",
|
||||
"Landscape, 3 x 2",
|
||||
"Landscape, 6 x 4",
|
||||
"Landscape, 7 x 5",
|
||||
"Landscape, 10 x 8",
|
||||
"Portrait, 2 x 3",
|
||||
"Portrait, 4 x 6",
|
||||
"Portrait, 5 x 7",
|
||||
"Portrait, 8 x 10"
|
||||
]
|
||||
);
|
||||
assert_eq!(standard_names("print"), ["Letter", "Legal", "Tabloid", "A4", "A6", "A5", "A3", "B5", "B4", "B3", "C4", "C5", "C6", "DL"]);
|
||||
assert_eq!(standard_names("art"), ["1000 pixel grid", "2000 pixel grid", "Poster", "Postcard", "1080p", "720p"]);
|
||||
// ISO 216 / ISO 269 sizes in millimetres, at 300 ppi.
|
||||
let mm = |side: f64| (side / 25.4 * 300.0).round() as u32;
|
||||
for (name, width, height) in [
|
||||
("A3", 297.0, 420.0),
|
||||
("A4", 210.0, 297.0),
|
||||
("A5", 148.0, 210.0),
|
||||
("A6", 105.0, 148.0),
|
||||
("B3", 353.0, 500.0),
|
||||
("B4", 250.0, 353.0),
|
||||
("B5", 176.0, 250.0),
|
||||
("C4", 229.0, 324.0),
|
||||
("C5", 162.0, 229.0),
|
||||
("C6", 114.0, 162.0),
|
||||
("DL", 110.0, 220.0),
|
||||
] {
|
||||
let preset = standard_preset("print", name);
|
||||
assert_eq!((preset.width, preset.height, preset.pixels_per_inch), (mm(width), mm(height), 300.0), "{name}");
|
||||
}
|
||||
let photo = standard_preset("photo", "Portrait, 8 x 10");
|
||||
assert_eq!((photo.width, photo.height), (2400, 3000));
|
||||
let postcard = standard_preset("art", "Postcard");
|
||||
assert_eq!((postcard.width, postcard.height, postcard.pixels_per_inch), (1200, 1800, 300.0), "4 x 6 in, portrait");
|
||||
let video = standard_preset("art", "720p");
|
||||
assert_eq!((video.width, video.height, video.pixels_per_inch), (1280, 720, 72.0));
|
||||
}
|
||||
|
||||
#[trial]
|
||||
fn the_pixel_grids_keep_their_pixels_at_the_print_resolution() {
|
||||
use craft_ui::runtime::env::UnitKind;
|
||||
let grid = standard_preset("art", "1000 pixel grid");
|
||||
assert!(grid.is_print() && !grid.in_inches());
|
||||
for (print, screen) in [(300.0, 72.0), (200.0, 96.0)] {
|
||||
let options = grid.options(print, screen);
|
||||
assert_eq!(
|
||||
(options.size.width, options.size.height, options.pixels_per_inch, options.unit),
|
||||
(1000, 1000, print, UnitKind::Pixels),
|
||||
"{print} ppi"
|
||||
);
|
||||
}
|
||||
// A print preset keeps its inches at the print resolution; a screen preset its pixels at the screen resolution.
|
||||
let postcard = standard_preset("art", "Postcard").options(200.0, 96.0);
|
||||
assert_eq!((postcard.size.width, postcard.size.height, postcard.pixels_per_inch, postcard.unit), (800, 1200, 200.0, UnitKind::Inches));
|
||||
let video = standard_preset("art", "720p").options(200.0, 96.0);
|
||||
assert_eq!((video.size.width, video.size.height, video.pixels_per_inch, video.unit), (1280, 720, 96.0, UnitKind::Pixels));
|
||||
}
|
||||
|
||||
#[trial]
|
||||
fn the_art_tab_shows_the_grids_in_pixels_and_the_postcard_in_inches() {
|
||||
let mut options = DocumentOptions::default();
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
let _ = NewDocumentDialog::new(Bind::bound(&mut options)).show(ui);
|
||||
});
|
||||
fixture.room(Vec2::new(1400.0, 1000.0)).idle(30);
|
||||
let art = fixture.by_label("Art & Illustration").expect("the Art & Illustration tab");
|
||||
fixture.click(&art).idle(10);
|
||||
assert!(shows(&fixture, "1000 × 1000 px @ 300 ppi"), "the grid's card is in pixels");
|
||||
assert!(shows(&fixture, "4 × 6 in @ 300 ppi"), "the postcard's card is in inches");
|
||||
}
|
||||
|
||||
/// The preset cards fill the left column's width, and each card's title and size line are painted whole and centred
|
||||
/// under the page outline.
|
||||
#[trial]
|
||||
|
||||
Reference in new issue
Block a user