windjammer_ui/components/generated/
flex.rs1#![allow(clippy::all)]
2#![allow(noop_method_call)]
3use super::traits::Renderable;
4
5#[derive(Clone, Debug, PartialEq, Copy)]
6pub enum FlexDirection {
7 Row,
8 Column,
9}
10
11#[derive(Debug, Clone, PartialEq)]
12pub struct Flex {
13 pub children: Vec<String>,
14 pub direction: FlexDirection,
15 pub gap: String,
16 pub padding: String,
17 pub background_color: String,
18}
19
20impl Flex {
21 #[inline]
22 pub fn new() -> Flex {
23 Flex {
24 children: Vec::new(),
25 direction: FlexDirection::Row,
26 gap: "8px".to_string(),
27 padding: "".to_string(),
28 background_color: "".to_string(),
29 }
30 }
31 #[inline]
32 pub fn direction(mut self, direction: FlexDirection) -> Flex {
33 self.direction = direction;
34 self
35 }
36 #[inline]
37 pub fn child(mut self, child: String) -> Flex {
38 self.children.push(child);
39 self
40 }
41 #[inline]
42 pub fn children(mut self, children: Vec<String>) -> Flex {
43 self.children = children;
44 self
45 }
46 #[inline]
47 pub fn gap(mut self, gap: String) -> Flex {
48 self.gap = gap;
49 self
50 }
51 #[inline]
52 pub fn gap_px(mut self, gap: i32) -> Flex {
53 self.gap = format!("{}px", gap);
54 self
55 }
56 #[inline]
57 pub fn padding(mut self, padding: String) -> Flex {
58 self.padding = padding;
59 self
60 }
61 #[inline]
62 pub fn background_color(mut self, color: String) -> Flex {
63 self.background_color = color;
64 self
65 }
66}
67
68impl Renderable for Flex {
69 #[inline]
70 fn render(self) -> String {
71 let direction_str = match self.direction {
72 FlexDirection::Row => "row".to_string(),
73 FlexDirection::Column => "column".to_string(),
74 };
75 let mut style = format!(
76 "{}{}{}{}{}",
77 "display: flex; flex-direction: ".to_string(),
78 direction_str,
79 "; gap: ",
80 self.gap,
81 ";"
82 );
83 if self.padding != "" {
84 style = format!("{}{}{}{}", style, " padding: ", self.padding, ";");
85 }
86 if self.background_color != "" {
87 style = format!(
88 "{}{}{}{}",
89 style, " background-color: ", self.background_color, ";"
90 );
91 }
92 let children_html = self.children.join(
93 "
94 ",
95 );
96 format!(
97 "<div class='wj-flex' style='{}'>
98 {}
99</div>",
100 style, children_html
101 )
102 }
103}