windjammer_ui/components/generated/
divider.rs

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