windjammer_ui/components/generated/
stack.rs

1#![allow(clippy::all)]
2#![allow(noop_method_call)]
3use super::traits::Renderable;
4
5pub enum StackDirection {
6    Vertical,
7    Horizontal,
8}
9
10pub enum StackAlign {
11    Start,
12    Center,
13    End,
14    Stretch,
15}
16
17pub enum StackJustify {
18    Start,
19    Center,
20    End,
21    SpaceBetween,
22    SpaceAround,
23    SpaceEvenly,
24}
25
26pub struct Stack {
27    direction: StackDirection,
28    gap: String,
29    align: StackAlign,
30    justify: StackJustify,
31    children: Vec<String>,
32    padding: String,
33    width: String,
34    height: String,
35}
36
37impl Stack {
38    #[inline]
39    pub fn new() -> Stack {
40        Stack {
41            direction: StackDirection::Vertical,
42            gap: "8px".to_string(),
43            align: StackAlign::Stretch,
44            justify: StackJustify::Start,
45            children: Vec::new(),
46            padding: "0".to_string(),
47            width: "auto".to_string(),
48            height: "auto".to_string(),
49        }
50    }
51    #[inline]
52    pub fn vertical() -> Stack {
53        Stack::new()
54    }
55    #[inline]
56    pub fn horizontal() -> Stack {
57        let mut stack = Stack::new();
58        stack.direction = StackDirection::Horizontal;
59        stack
60    }
61    #[inline]
62    pub fn direction(mut self, dir: StackDirection) -> Stack {
63        self.direction = dir;
64        self
65    }
66    #[inline]
67    pub fn gap(mut self, gap: String) -> Stack {
68        self.gap = gap;
69        self
70    }
71    #[inline]
72    pub fn align(mut self, align: StackAlign) -> Stack {
73        self.align = align;
74        self
75    }
76    #[inline]
77    pub fn justify(mut self, justify: StackJustify) -> Stack {
78        self.justify = justify;
79        self
80    }
81    #[inline]
82    pub fn padding(mut self, padding: String) -> Stack {
83        self.padding = padding;
84        self
85    }
86    #[inline]
87    pub fn width(mut self, width: String) -> Stack {
88        self.width = width;
89        self
90    }
91    #[inline]
92    pub fn height(mut self, height: String) -> Stack {
93        self.height = height;
94        self
95    }
96    #[inline]
97    pub fn child(mut self, child: String) -> Stack {
98        self.children.push(child);
99        self
100    }
101}
102
103impl Renderable for Stack {
104    fn render(self) -> String {
105        let flex_direction = match self.direction {
106            StackDirection::Vertical => "column",
107            StackDirection::Horizontal => "row",
108        };
109        let align_items = match self.align {
110            StackAlign::Start => "flex-start",
111            StackAlign::Center => "center",
112            StackAlign::End => "flex-end",
113            StackAlign::Stretch => "stretch",
114        };
115        let justify_content = match self.justify {
116            StackJustify::Start => "flex-start",
117            StackJustify::Center => "center",
118            StackJustify::End => "flex-end",
119            StackJustify::SpaceBetween => "space-between",
120            StackJustify::SpaceAround => "space-around",
121            StackJustify::SpaceEvenly => "space-evenly",
122        };
123        let mut html = String::new();
124        html.push_str("<div style='display: flex; flex-direction: ");
125        html.push_str(flex_direction);
126        html.push_str("; gap: ");
127        html.push_str(&self.gap);
128        html.push_str("; align-items: ");
129        html.push_str(align_items);
130        html.push_str("; justify-content: ");
131        html.push_str(justify_content);
132        html.push_str("; padding: ");
133        html.push_str(&self.padding);
134        html.push_str("; width: ");
135        html.push_str(&self.width);
136        html.push_str("; height: ");
137        html.push_str(&self.height);
138        html.push_str(";'>");
139        for child in &self.children {
140            html.push_str(child);
141        }
142        html.push_str("</div>");
143        html
144    }
145}