yew_layout/
overflow.rs

1use css_style::{prelude::*, StyleUpdater};
2
3#[derive(Debug, Copy, Clone, PartialEq, Eq)]
4enum OverflowValue {
5    Visible,
6    Hidden,
7    Scroll,
8    AutoScroll,
9}
10
11#[derive(Debug, Copy, Clone, PartialEq, Eq)]
12pub struct Overflow {
13    x: OverflowValue,
14    y: OverflowValue,
15}
16
17impl Overflow {
18    pub fn auto_scroll() -> Self {
19        Self {
20            x: OverflowValue::AutoScroll,
21            y: OverflowValue::AutoScroll,
22        }
23    }
24
25    pub fn hidden() -> Self {
26        Self {
27            x: OverflowValue::Hidden,
28            y: OverflowValue::Hidden,
29        }
30    }
31
32    pub fn visible() -> Self {
33        Self {
34            x: OverflowValue::Visible,
35            y: OverflowValue::Visible,
36        }
37    }
38
39    pub fn scroll() -> Self {
40        Self {
41            x: OverflowValue::Scroll,
42            y: OverflowValue::Scroll,
43        }
44    }
45
46    pub fn x_hidden(mut self) -> Self {
47        self.x = OverflowValue::Hidden;
48        self
49    }
50
51    pub fn x_visible(mut self) -> Self {
52        self.x = OverflowValue::Visible;
53        self
54    }
55
56    pub fn x_scroll(mut self) -> Self {
57        self.x = OverflowValue::Scroll;
58        self
59    }
60
61    pub fn x_auto_scroll(mut self) -> Self {
62        self.x = OverflowValue::AutoScroll;
63        self
64    }
65
66    pub fn y_hidden(mut self) -> Self {
67        self.y = OverflowValue::Hidden;
68        self
69    }
70
71    pub fn y_visible(mut self) -> Self {
72        self.y = OverflowValue::Visible;
73        self
74    }
75
76    pub fn y_scroll(mut self) -> Self {
77        self.y = OverflowValue::Scroll;
78        self
79    }
80
81    pub fn y_auto_scroll(mut self) -> Self {
82        self.y = OverflowValue::AutoScroll;
83        self
84    }
85}
86
87impl StyleUpdater for Overflow {
88    fn update_style(self, style: Style) -> Style {
89        let get_val = |val| match val {
90            OverflowValue::Visible => "visible",
91            OverflowValue::Hidden => "hidden",
92            OverflowValue::Scroll => "scroll",
93            OverflowValue::AutoScroll => "auto",
94        };
95        style
96            .insert("overflow-x", get_val(self.x))
97            .insert("overflow-y", get_val(self.y))
98    }
99}