windjammer_ui/components/generated/
scrollarea.rs

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