polyhorn_cli/ios/xcassets/
mod.rs

1//! Types that represent the data structures of the `xcassets` format.
2
3use serde::Serialize;
4
5/// Represents the JSON-serialized data structure that is contained within a
6/// `xcassets` asset catalog.
7#[derive(Serialize)]
8pub struct XcAssets<'a> {
9    /// Contains metadata about this asset catalog.
10    pub info: Info<'a>,
11}
12
13/// Represents the JSON-serialized data structure that is contained within an
14/// image set in an asset catalog.
15#[derive(Serialize)]
16pub struct ImageSet<'a> {
17    /// A set of alternative images for this image set. For example, multiple
18    /// images can be provided to support different screen DPIs.
19    pub images: Vec<Image<'a>>,
20
21    /// Contains metadata about this image set.
22    pub info: Info<'a>,
23}
24
25/// Metadata structure that is used in several places in an asset catalog.
26#[derive(Serialize)]
27pub struct Info<'a> {
28    /// Contains the author of the corresponding data structure. This is usually
29    /// Xcode.
30    pub author: &'a str,
31
32    /// Contains the version of the corresponding data structure. This is
33    /// usually 1.
34    pub version: usize,
35}
36
37/// Represents the JSON-serialized data structure that is contained within a
38/// folder in an asset catalog.
39#[derive(Serialize)]
40pub struct Folder<'a> {
41    /// Properties of this folder.
42    pub properties: Properties,
43
44    /// Contains metadata about this folder.
45    pub info: Info<'a>,
46}
47
48/// Additional properties of a folder.
49#[derive(Serialize)]
50pub struct Properties {
51    /// Boolean that indicates whether this folder provides a namespace. If it
52    /// provides a namespace, images are accessed through
53    /// `UIImage(named: "folder-name/image-name")`.
54    #[serde(rename = "provides-namespace")]
55    pub provides_namespace: bool,
56}
57
58/// A single image within an image set.
59#[derive(Serialize)]
60pub struct Image<'a> {
61    /// Original file name of the image.
62    #[serde(skip_serializing_if = "Option::is_none")]
63    pub filename: Option<&'a str>,
64
65    /// Contains the device idiom for which this image should be used. For
66    /// example, this can be used to distinguish between iPhone and iPad.
67    pub idiom: &'a str,
68
69    /// Relative screen DPI for which this image should be used. For example,
70    /// this can be used to provide both @1x and @2x (or even @3x)
71    /// rasterizations of the same source image.
72    pub scale: &'a str,
73
74    /// Size of this image.
75    #[serde(skip_serializing_if = "Option::is_none")]
76    pub size: Option<&'a str>,
77}