elvis_core/value/
border.rs1use crate::value::{Color, Unit};
2use elvis_core_support::EnumStyle;
3
4#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Debug, EnumStyle)]
6pub enum BorderStyle {
7 None,
9 Hidden,
11 Dotted,
13 Dashed,
15 Solid,
17 Double,
19 Groove,
21 Ridge,
23 Inset,
25 Outset,
27}
28
29impl Default for BorderStyle {
30 fn default() -> BorderStyle {
31 BorderStyle::None
32 }
33}
34
35#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Debug)]
37pub struct BoxBorder {
38 pub width: Unit,
40 pub style: BorderStyle,
42 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#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Debug)]
69pub struct BorderRadius {
70 pub top_left: Unit,
72 pub top_right: Unit,
74 pub bottom_left: Unit,
76 pub bottom_right: Unit,
78 pub second_top_left: Unit,
80 pub second_top_right: Unit,
82 pub second_bottom_left: Unit,
84 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}