zen_rs/components/
icon.rs1pub mod github;
4
5use crate::aspects::{Height, Path, Size, StrokeLinecap, StrokeLinejoin, SvgColor, Width};
6
7pub static XMLNS: &str = r"http://www.w3.org/2000/svg";
9
10#[inline]
12pub fn icon() -> Icon {
13 Icon::default()
14}
15
16#[derive(Debug, Default, Clone, PartialEq, PartialOrd)]
17pub struct Icon {
19 content: Vec<Path>,
21 foreground_color: SvgColor,
23 background_color: SvgColor,
25 width: Width,
27 height: Height,
29 stroke_linecap: Option<StrokeLinecap>,
31 stroke_linejoin: Option<StrokeLinejoin>,
33 stroke_width: Option<f64>,
35 view_box: (u8, u8, u8, u8),
37}
38
39impl Icon {
40 #[inline]
42 pub fn get_content(&self) -> &[String] {
43 &(self).content
44 }
45
46 #[inline]
48 pub fn get_foreground_color(&self) -> &SvgColor {
49 &self.foreground_color
50 }
51
52 #[inline]
54 pub fn get_background_color(&self) -> &SvgColor {
55 &self.background_color
56 }
57
58 #[inline]
60 pub fn get_width(&self) -> Width {
61 self.width
62 }
63
64 #[inline]
66 pub fn get_height(&self) -> Height {
67 self.height
68 }
69
70 #[inline]
72 pub fn content(mut self, content: impl ToString) -> Self {
73 self.content.push(content.to_string());
74 self
75 }
76
77 #[inline]
79 pub fn contents(mut self, content: Vec<impl ToString>) -> Self {
80 self.content
81 .append(&mut content.iter().map(|x| x.to_string()).collect());
82 self
83 }
84
85 #[inline]
87 pub fn foreground_color(mut self, foreground_color: impl ToString) -> Self {
88 self.foreground_color = SvgColor::Color(foreground_color.to_string());
89 self
90 }
91
92 #[inline]
94 pub fn foreground_color_none(mut self) -> Self {
95 self.foreground_color = SvgColor::None;
96 self
97 }
98
99 #[inline]
101 pub fn foreground_color_current_color(mut self) -> Self {
102 self.foreground_color = SvgColor::CurrentColor;
103 self
104 }
105
106 #[inline]
108 pub fn background_color(mut self, background_color: impl ToString) -> Self {
109 self.background_color = SvgColor::Color(background_color.to_string());
110 self
111 }
112
113 #[inline]
115 pub fn background_color_none(mut self) -> Self {
116 self.background_color = SvgColor::None;
117 self
118 }
119
120 #[inline]
122 pub fn background_color_current_color(mut self) -> Self {
123 self.background_color = SvgColor::CurrentColor;
124 self
125 }
126
127 #[inline]
129 pub fn width(mut self, width: Width) -> Self {
130 self.width = width;
131 self
132 }
133
134 #[inline]
136 pub fn height(mut self, height: Height) -> Self {
137 self.height = height;
138 self
139 }
140
141 #[inline]
143 pub fn size(mut self, size: Size) -> Self {
144 self.width = size;
145 self.height = size;
146 self
147 }
148
149 #[inline]
151 pub fn get_stroke_linejoin(&self) -> Option<StrokeLinejoin> {
152 self.stroke_linejoin
153 }
154
155 #[inline]
157 pub fn get_stroke_width(&self) -> Option<f64> {
158 self.stroke_width
159 }
160
161 #[inline]
163 pub fn get_view_box(&self) -> (u8, u8, u8, u8) {
164 self.view_box
165 }
166
167 #[inline]
169 pub fn get_stroke_linecap(&self) -> Option<StrokeLinecap> {
170 self.stroke_linecap
171 }
172
173 #[inline]
175 pub fn stroke_linejoin(mut self, stroke_linejoin: StrokeLinejoin) -> Self {
176 self.stroke_linejoin = Some(stroke_linejoin);
177 self
178 }
179
180 #[inline]
182 pub fn stroke_width(mut self, stroke_width: f64) -> Self {
183 self.stroke_width = Some(stroke_width);
184 self
185 }
186
187 #[inline]
189 pub fn view_box(mut self, view_box: (u8, u8, u8, u8)) -> Self {
190 self.view_box = view_box;
191 self
192 }
193
194 #[inline]
196 pub fn stroke_linecap(mut self, stroke_linecap: StrokeLinecap) -> Self {
197 self.stroke_linecap = Some(stroke_linecap);
198 self
199 }
200}