zen_rs/components/
container.rs1use crate::aspects::{
4 Align, BackgroundColor, BorderPart, BorderStyle, Color, Gap, Height, Order, Padding, Size,
5 Width,
6};
7
8use super::Components;
9
10#[inline]
11pub fn container() -> Container {
13 Container::default()
14}
15
16#[derive(Debug, Default, Clone, PartialEq, PartialOrd)]
17pub struct Container {
19 components: Vec<Components>,
21 background_color: BackgroundColor,
23 width: Width,
25 is_width_full: bool,
27 height: Height,
29 is_height_full: bool,
31 border: BorderStyle,
33 direction: Order,
35 gap: Gap,
37 padding: Padding,
39 is_flex: bool,
41 align_content: Align,
43 align_items: Align,
45}
46
47impl Container {
48 #[inline]
50 pub fn push(&mut self, component: impl Into<Components>) {
51 self.components.push(component.into());
52 }
53
54 #[inline]
56 pub fn component(mut self, component: impl Into<Components>) -> Self {
57 self.components.push(component.into());
58 self
59 }
60
61 #[inline]
64 pub fn components(
65 mut self,
66 components: impl IntoIterator<Item = impl Into<Components>>,
67 ) -> Self {
68 self.components
69 .append(&mut components.into_iter().map(|x| x.into()).collect());
70 self
71 }
72
73 #[inline]
75 pub fn get_components(&self) -> &[Components] {
76 &self.components
77 }
78
79 #[inline]
81 pub fn gap(mut self, gap: Gap) -> Self {
82 self.gap = gap;
83 self
84 }
85
86 #[inline]
88 pub fn padding(mut self, padding: Padding) -> Self {
89 self.padding = padding;
90 self
91 }
92
93 #[inline]
95 pub fn get_gap(&self) -> &Gap {
96 &self.gap
97 }
98
99 #[inline]
101 pub fn get_padding(&self) -> &Padding {
102 &self.padding
103 }
104
105 #[inline]
107 pub fn background_color(mut self, background_color: BackgroundColor) -> Self {
108 self.background_color = background_color;
109 self
110 }
111
112 #[inline]
114 pub fn width(mut self, width: Width) -> Self {
115 self.width = width;
116 self
117 }
118
119 #[inline]
121 pub fn height(mut self, height: Height) -> Self {
122 self.height = height;
123 self
124 }
125
126 #[inline]
128 pub fn width_full(mut self) -> Self {
129 self.is_width_full = !self.is_width_full;
130 self
131 }
132
133 #[inline]
135 pub fn height_full(mut self) -> Self {
136 self.is_height_full = !self.is_height_full;
137 self
138 }
139
140 #[inline]
142 pub fn border(mut self, border: BorderStyle) -> Self {
143 self.border = border;
144 self
145 }
146
147 #[inline]
149 pub fn border_color(mut self, border_color: Color) -> Self {
150 self.border.1 = border_color;
151 self
152 }
153
154 #[inline]
156 pub fn border_radius(mut self, border_size: Size) -> Self {
157 self.border.2 = border_size;
158 self
159 }
160
161 #[inline]
163 pub fn border_size(mut self, border_size: BorderPart) -> Self {
164 self.border.0 = border_size;
165 self
166 }
167
168 #[inline]
170 pub fn border_size_full(mut self, border_size_full: Size) -> Self {
171 self.border.0 = (
172 border_size_full,
173 border_size_full,
174 border_size_full,
175 border_size_full,
176 );
177 self
178 }
179
180 #[inline]
182 pub fn border_size_l(mut self, border_size_l: Size) -> Self {
183 let (_, t, b, r) = self.border.0;
184 self.border.0 = (border_size_l, t, b, r);
185 self
186 }
187
188 #[inline]
190 pub fn border_size_t(mut self, border_size_t: Size) -> Self {
191 let (l, _, b, r) = self.border.0;
192 self.border.0 = (l, border_size_t, b, r);
193 self
194 }
195
196 #[inline]
198 pub fn border_size_b(mut self, border_size_b: Size) -> Self {
199 let (l, t, _, r) = self.border.0;
200 self.border.0 = (l, t, border_size_b, r);
201 self
202 }
203
204 #[inline]
206 pub fn border_size_r(mut self, border_size_r: Size) -> Self {
207 let (l, t, b, _) = self.border.0;
208 self.border.0 = (l, t, b, border_size_r);
209 self
210 }
211
212 #[inline]
214 pub fn direction(mut self, direction: Order) -> Self {
215 self.direction = direction;
216 self
217 }
218
219 #[inline]
221 pub fn flex(mut self) -> Self {
222 self.is_flex = !self.is_flex;
223 self
224 }
225
226 #[inline]
228 pub fn align_content(mut self, align_content: Align) -> Self {
229 self.align_content = align_content;
230 self
231 }
232
233 #[inline]
235 pub fn align_items(mut self, align_items: Align) -> Self {
236 self.align_items = align_items;
237 self
238 }
239
240 #[inline]
242 pub fn get_flex(&self) -> &bool {
243 &self.is_flex
244 }
245
246 #[inline]
248 pub fn get_width_full(&self) -> &bool {
249 &self.is_width_full
250 }
251
252 #[inline]
254 pub fn get_height_full(&self) -> &bool {
255 &self.is_height_full
256 }
257
258 #[inline]
260 pub fn get_align_content(&self) -> &Align {
261 &self.align_content
262 }
263
264 #[inline]
266 pub fn get_align_items(&self) -> &Align {
267 &self.align_items
268 }
269
270 #[inline]
272 pub fn get_background_color(&self) -> &(u8, u8, u8, u8) {
273 &self.background_color
274 }
275
276 #[inline]
278 pub fn get_width(&self) -> &u64 {
279 &self.width
280 }
281
282 #[inline]
284 pub fn get_height(&self) -> &u64 {
285 &self.height
286 }
287
288 #[inline]
290 pub fn get_border(&self) -> &BorderStyle {
291 &self.border
292 }
293
294 #[inline]
296 pub fn get_direction(&self) -> &Order {
297 &self.direction
298 }
299}