img_gen_spec/validators/layers/icon.rs
1use super::{ColorKind, PreserveAspect};
2
3#[cfg(feature = "pyo3")]
4use pyo3::prelude::*;
5
6use serde::{Deserialize, Serialize};
7
8/// An attribute to describe a [`Layer`](struct@crate::Layer)'s [`Icon`].
9#[cfg_attr(
10 feature = "pyo3",
11 pyclass(module = "img_gen", get_all, set_all, from_py_object)
12)]
13#[derive(Debug, Clone, Serialize, Deserialize)]
14pub struct Icon {
15 /// A path to an image file.
16 ///
17 /// If the given image path has no file extension, then
18 /// it will be treated as an SVG image.
19 ///
20 /// This also supports built-in SVG icons from the following icon packs:
21 ///
22 /// - Material Design Icons (``material/{icon_slug}``)
23 /// - Simple Icons (``simple/{icon_slug}``)
24 /// - Octicons (``octicons/{icon_slug}``)
25 /// - FontAwesome Free (``fontawesome/<brands|solid|regular>/{icon_slug}``)
26 ///
27 /// Otherwise, the image file's path is resolved via a search through the list of
28 /// ``external_resource_paths`` provided to the ``Generator`` (in `img_gen_renderer` crate),
29 /// which defaults to the current working directory if unspecified or an empty list.
30 pub image: String,
31 /// A color used to replace the [`Icon::image`]'s original coloring.
32 pub color: Option<ColorKind>,
33 /// This controls how the original image is rendered into the layer.
34 ///
35 /// The default is to preserve the original image's width and height
36 /// ([`PreserveAspect::On`]).
37 #[serde(default)]
38 pub preserve_aspect: PreserveAspect,
39}