windjammer_ui/components/generated/
scrollarea.rs

1#![allow(clippy::all)]
2#![allow(noop_method_call)]
3use super::traits::Renderable;
4
5#[derive(Clone, Debug, PartialEq, Copy)]
6pub enum ScrollDirection {
7    Vertical,
8    Horizontal,
9    Both,
10}
11
12#[derive(Debug, Clone, PartialEq)]
13pub struct ScrollArea {
14    pub children: Vec<String>,
15    pub direction: ScrollDirection,
16    pub height: String,
17    pub width: String,
18}
19
20impl ScrollArea {
21    #[inline]
22    pub fn new() -> ScrollArea {
23        ScrollArea {
24            children: Vec::new(),
25            direction: ScrollDirection::Vertical,
26            height: "300px".to_string(),
27            width: "100%".to_string(),
28        }
29    }
30    #[inline]
31    pub fn child(mut self, child: String) -> ScrollArea {
32        self.children.push(child);
33        self
34    }
35    #[inline]
36    pub fn direction(mut self, direction: ScrollDirection) -> ScrollArea {
37        self.direction = direction;
38        self
39    }
40    #[inline]
41    pub fn height(mut self, height: String) -> ScrollArea {
42        self.height = height;
43        self
44    }
45    #[inline]
46    pub fn width(mut self, width: String) -> ScrollArea {
47        self.width = width;
48        self
49    }
50}
51
52impl Renderable for ScrollArea {
53    #[inline]
54    fn render(self) -> String {
55        let overflow_style = match self.direction {
56            ScrollDirection::Vertical => "overflow-y: auto; overflow-x: hidden;".to_string(),
57            ScrollDirection::Horizontal => "overflow-x: auto; overflow-y: hidden;".to_string(),
58            ScrollDirection::Both => "overflow: auto;".to_string(),
59        };
60        let children_html = self.children.join(
61            "
62",
63        );
64        format!(
65            "<div class='wj-scroll-area' style='height: {}; width: {}; {}'>
66  {}
67</div>",
68            self.height, self.width, overflow_style, children_html
69        )
70    }
71}