elvis_core/value/
border.rs

1use crate::value::{Color, Unit};
2use elvis_core_support::EnumStyle;
3
4/// Border Style
5#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Debug, EnumStyle)]
6pub enum BorderStyle {
7    /// No Style
8    None,
9    /// Hidden Border
10    Hidden,
11    /// Dotted Border
12    Dotted,
13    /// Dashed Border
14    Dashed,
15    /// Solid Border
16    Solid,
17    /// Double Border
18    Double,
19    /// Groove Style
20    Groove,
21    /// Ridge Style
22    Ridge,
23    /// Inset
24    Inset,
25    /// Outset
26    Outset,
27}
28
29impl Default for BorderStyle {
30    fn default() -> BorderStyle {
31        BorderStyle::None
32    }
33}
34
35/// Border Style
36#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Debug)]
37pub struct BoxBorder {
38    /// border width
39    pub width: Unit,
40    /// border style
41    pub style: BorderStyle,
42    /// border color
43    pub color: Color,
44}
45
46impl Default for BoxBorder {
47    fn default() -> BoxBorder {
48        BoxBorder {
49            width: Unit::None(0.0),
50            style: BorderStyle::None,
51            color: Color::Black,
52        }
53    }
54}
55
56impl ToString for BoxBorder {
57    fn to_string(&self) -> String {
58        format!(
59            "{} {} {}",
60            self.width.to_string(),
61            self.style.to_string(),
62            self.color.to_string()
63        )
64    }
65}
66
67/// Border Radius
68#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Debug)]
69pub struct BorderRadius {
70    /// top left radius
71    pub top_left: Unit,
72    /// top right radius
73    pub top_right: Unit,
74    /// bottom left radius
75    pub bottom_left: Unit,
76    /// bottom right radius
77    pub bottom_right: Unit,
78    /// second top left radius
79    pub second_top_left: Unit,
80    /// second top right radius
81    pub second_top_right: Unit,
82    /// second bottom left radius
83    pub second_bottom_left: Unit,
84    /// second bottom right radius
85    pub second_bottom_right: Unit,
86}
87
88impl Default for BorderRadius {
89    fn default() -> BorderRadius {
90        BorderRadius {
91            top_left: Unit::None(0.0),
92            top_right: Unit::None(0.0),
93            bottom_left: Unit::None(0.0),
94            bottom_right: Unit::None(0.0),
95            second_top_left: Unit::None(0.0),
96            second_top_right: Unit::None(0.0),
97            second_bottom_left: Unit::None(0.0),
98            second_bottom_right: Unit::None(0.0),
99        }
100    }
101}
102
103impl ToString for BorderRadius {
104    fn to_string(&self) -> String {
105        let radius = format!(
106            "{} {} {} {}",
107            self.top_left.to_string(),
108            self.top_right.to_string(),
109            self.bottom_left.to_string(),
110            self.bottom_right.to_string(),
111        );
112
113        if self.second_top_left == self.second_top_right
114            && self.second_bottom_right == self.second_bottom_left
115            && self.second_top_left == self.second_bottom_right
116            && self.second_bottom_right == Unit::None(0.0)
117        {
118            radius
119        } else {
120            format!(
121                "{} / {} {} {} {}",
122                radius,
123                self.second_top_left.to_string(),
124                self.second_top_right.to_string(),
125                self.second_bottom_left.to_string(),
126                self.second_bottom_right.to_string(),
127            )
128        }
129    }
130}