1use crate::prelude::*;
2
3enum DividerDirection {
4 Horizontal,
5 Vertical,
6}
7
8#[derive(Component)]
9pub struct Divider {
10 direction: DividerDirection,
11 inset: bool,
12}
13
14impl Divider {
15 pub fn horizontal() -> Self {
16 Self {
17 direction: DividerDirection::Horizontal,
18 inset: false,
19 }
20 }
21
22 pub fn vertical() -> Self {
23 Self {
24 direction: DividerDirection::Vertical,
25 inset: false,
26 }
27 }
28
29 pub fn inset(mut self) -> Self {
30 self.inset = true;
31 self
32 }
33
34 fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
35 div()
36 .map(|this| match self.direction {
37 DividerDirection::Horizontal => {
38 this.h_px().w_full().when(self.inset, |this| this.mx_1p5())
39 }
40 DividerDirection::Vertical => {
41 this.w_px().h_full().when(self.inset, |this| this.my_1p5())
42 }
43 })
44 .bg(cx.theme().colors().border_variant)
45 }
46}