Skip to main content

liora_components/
divider.rs

1use gpui::{App, Component, IntoElement, RenderOnce, Window, prelude::*, px};
2
3pub struct Divider {
4    vertical: bool,
5    label: Option<String>,
6}
7
8impl Divider {
9    pub fn new() -> Self {
10        Self {
11            vertical: false,
12            label: None,
13        }
14    }
15
16    pub fn vertical(mut self) -> Self {
17        self.vertical = true;
18        self
19    }
20
21    pub fn label(mut self, text: impl Into<String>) -> Self {
22        self.label = Some(text.into());
23        self
24    }
25}
26
27impl RenderOnce for Divider {
28    fn render(self, _window: &mut Window, cx: &mut App) -> impl IntoElement {
29        let theme = &cx.global::<liora_core::Config>().theme;
30
31        if self.vertical {
32            gpui::div().w(px(1.0)).h_full().bg(theme.neutral.border)
33        } else if let Some(text) = self.label {
34            gpui::div()
35                .flex()
36                .flex_row()
37                .items_center()
38                .gap_2()
39                .w_full()
40                .child(gpui::div().flex_1().h(px(1.0)).bg(theme.neutral.border))
41                .child(
42                    gpui::div()
43                        .text_size(px(theme.font_size.sm))
44                        .text_color(theme.neutral.text_3)
45                        .child(text),
46                )
47                .child(gpui::div().flex_1().h(px(1.0)).bg(theme.neutral.border))
48        } else {
49            gpui::div().w_full().h(px(1.0)).bg(theme.neutral.border)
50        }
51    }
52}
53
54impl IntoElement for Divider {
55    type Element = Component<Self>;
56    fn into_element(self) -> Self::Element {
57        Component::new(self)
58    }
59}