img_gen_spec/validators/layers/rectangle.rs
1use super::{Border, ColorKind};
2
3#[cfg(feature = "pyo3")]
4use pyo3::prelude::*;
5
6use serde::{Deserialize, Serialize};
7
8/// An enum to represent the possible options in specifying which [`Rectangle::corners`] to render rounded.
9#[cfg_attr(
10 feature = "pyo3",
11 pyclass(eq, eq_int, module = "img_gen", from_py_object)
12)]
13#[derive(Debug, PartialEq, Clone, Copy, Serialize, Deserialize)]
14pub enum Corners {
15 /// The ``"top left"`` corner of the `Rectangle`.
16 #[serde(alias = "top left")]
17 TopLeft,
18
19 /// The ``"top right"`` corner of the `Rectangle`.
20 #[serde(alias = "top right")]
21 TopRight,
22
23 /// The ``"bottom left"`` corner of the `Rectangle`.
24 #[serde(alias = "bottom left")]
25 BottomLeft,
26
27 /// The ``"bottom right"`` corner of the `Rectangle`.
28 #[serde(alias = "bottom right")]
29 BottomRight,
30}
31
32impl Corners {
33 /// All rectangle corners in display order.
34 pub const ALL: [Self; 4] = [
35 Corners::TopLeft,
36 Corners::TopRight,
37 Corners::BottomLeft,
38 Corners::BottomRight,
39 ];
40}
41
42/// An attribute to represent a rectangle rendered in the layer.
43///
44/// The size of the rectangle is specified by the layer's size.
45#[cfg_attr(
46 feature = "pyo3",
47 pyclass(module = "img_gen", get_all, set_all, from_py_object)
48)]
49#[derive(Debug, Clone, Default, Serialize, Deserialize)]
50pub struct Rectangle {
51 /// The [`Border`] (if specified) to render around the rectangle.
52 pub border: Option<Border>,
53
54 /// The color used to fill the rectangle.
55 #[serde(default = "ColorKind::transparent_default")]
56 pub color: ColorKind,
57
58 /// The radius of the rendered [`Rectangle::corners`].
59 ///
60 /// The renderer shall limit this value if it is
61 /// greater than half the minimum of the rectangle's width or height
62 /// (see [`Layer::size`](value@crate::Layer::size)).
63 #[serde(default)]
64 pub radius: f32,
65
66 /// A list of the [`Corners`] in which the `radius` is applied.
67 ///
68 /// Any [`Corners`] not in this list will not be rounded.
69 #[serde(default)]
70 pub corners: Vec<Corners>,
71}