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