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