windjammer_ui/components/generated/
flex.rs

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