json2pdf_client/protocol/
border.rs

1use serde::Serialize;
2
3/// Settings for the border of an element.
4/// If a side is left unset, no border will be created for that side
5#[derive(Debug, Clone, Default, Serialize)]
6pub struct BorderSettings {
7    #[serde(skip_serializing_if = "Option::is_none")]
8    bottom: Option<BorderSpecification>,
9    #[serde(skip_serializing_if = "Option::is_none")]
10    top: Option<BorderSpecification>,
11    #[serde(skip_serializing_if = "Option::is_none")]
12    left: Option<BorderSpecification>,
13    #[serde(skip_serializing_if = "Option::is_none")]
14    right: Option<BorderSpecification>,
15}
16
17/// Settings for a specific border
18#[derive(Debug, Clone, Serialize)]
19pub struct BorderSpecification {
20    width: f32,
21    #[serde(skip_serializing_if = "Option::is_none")]
22    color: Option<String>,
23}
24
25impl BorderSpecification {
26    /// Create a new border
27    pub fn new(width: f32) -> Self {
28        Self {
29            width,
30            color: None,
31        }
32    }
33
34    /// Set the border's color.
35    /// The color should be a six digit hex color without the `#` prefix.
36    pub fn color(mut self, color: String) -> Self {
37        self.color = Some(color);
38        self
39    }
40}
41
42impl BorderSettings {
43    /// Create an empty object
44    pub fn new() -> Self {
45        Self::default()
46    }
47
48    /// Set the bottom border
49    pub fn bottom(mut self, spec: BorderSpecification) -> Self {
50        self.bottom = Some(spec);
51        self
52    }
53
54    /// Set the top border
55    pub fn top(mut self, spec: BorderSpecification) -> Self {
56        self.top = Some(spec);
57        self
58    }
59
60    /// Set the left border
61    pub fn left(mut self, spec: BorderSpecification) -> Self {
62        self.left = Some(spec);
63        self
64    }
65
66    /// Set the right border
67    pub fn right(mut self, spec: BorderSpecification) -> Self {
68        self.right = Some(spec);
69        self
70    }
71}