windjammer_ui/components/generated/
container.rs

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