windjammer_ui/components/generated/
container.rs1#![allow(clippy::all)]
2#![allow(noop_method_call)]
3use super::traits::Renderable;
4
5#[derive(Debug, Clone, PartialEq, Eq, Default)]
6pub struct Container {
7 pub children: Vec<String>,
8 pub max_width: String,
9 pub max_height: String,
10 pub padding: String,
11 pub background_color: String,
12}
13
14impl Container {
15 #[inline]
16 pub fn new() -> Container {
17 Container {
18 children: Vec::new(),
19 max_width: "".to_string(),
20 max_height: "".to_string(),
21 padding: "16px".to_string(),
22 background_color: "".to_string(),
23 }
24 }
25 #[inline]
26 pub fn child(mut self, child: String) -> Container {
27 self.children.push(child);
28 self
29 }
30 #[inline]
31 pub fn children(mut self, children: Vec<String>) -> Container {
32 self.children = children;
33 self
34 }
35 #[inline]
36 pub fn max_width(mut self, width: String) -> Container {
37 self.max_width = width;
38 self
39 }
40 #[inline]
41 pub fn max_height(mut self, height: String) -> Container {
42 self.max_height = height;
43 self
44 }
45 #[inline]
46 pub fn padding(mut self, padding: String) -> Container {
47 self.padding = padding;
48 self
49 }
50 #[inline]
51 pub fn background_color(mut self, color: String) -> Container {
52 self.background_color = color;
53 self
54 }
55}
56
57impl Renderable for Container {
58 #[inline]
59 fn render(self) -> String {
60 let mut style = "margin: 0 auto; ".to_string();
61 if self.max_width != "" {
62 style = format!("{}{}{}{}", style, "max-width: ", self.max_width, "; ");
63 }
64 if self.max_height != "" {
65 style = format!("{}{}{}{}", style, "max-height: ", self.max_height, "; ");
66 }
67 if self.padding != "" {
68 style = format!("{}{}{}{}", style, "padding: ", self.padding, "; ");
69 }
70 if self.background_color != "" {
71 style = format!(
72 "{}{}{}{}",
73 style, "background-color: ", self.background_color, "; "
74 );
75 }
76 let children_html = self.children.join(
77 "
78 ",
79 );
80 format!(
81 "<div class='wj-container' style='{}'>
82 {}
83</div>",
84 style, children_html
85 )
86 }
87}