Skip to main content

glassy_ui/
separator.rs

1//! Paper hex+alpha is grouped as `RRGGBB_AA`.
2#![allow(clippy::unusual_byte_groupings)]
3
4use crate::motion::StyledSlot;
5use crate::theme::{paint, ActiveTheme};
6use gpui::{div, prelude::*, px, App, IntoElement, RenderOnce, StyleRefinement, Styled, Window};
7
8/// Horizontal 280×1 or vertical 1×36. Zinc at 12%, not a black rule.
9#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
10pub enum SeparatorOrientation {
11    #[default]
12    Horizontal,
13    Vertical,
14}
15
16/// 1px rule matching Paper `Glassy UI` → Separators.
17#[derive(IntoElement)]
18pub struct Separator {
19    orientation: SeparatorOrientation,
20    style: StyleRefinement,
21}
22
23impl Separator {
24    pub fn new() -> Self {
25        Self::horizontal()
26    }
27
28    pub fn horizontal() -> Self {
29        Self {
30            orientation: SeparatorOrientation::Horizontal,
31            style: StyleRefinement::default(),
32        }
33    }
34
35    pub fn vertical() -> Self {
36        Self {
37            orientation: SeparatorOrientation::Vertical,
38            style: StyleRefinement::default(),
39        }
40    }
41}
42
43impl Default for Separator {
44    fn default() -> Self {
45        Self::new()
46    }
47}
48
49impl Styled for Separator {
50    fn style(&mut self) -> &mut StyleRefinement {
51        &mut self.style
52    }
53}
54
55impl RenderOnce for Separator {
56    fn render(self, _window: &mut Window, cx: &mut App) -> impl IntoElement {
57        let color = if cx.theme().is_dark() {
58            paint(0xFAFAFA_1F)
59        } else {
60            paint(0x18181B_1F)
61        };
62
63        div()
64            .flex_shrink_0()
65            .bg(color)
66            .when(self.orientation == SeparatorOrientation::Horizontal, |el| {
67                el.w(px(280.)).h(px(1.))
68            })
69            .when(self.orientation == SeparatorOrientation::Vertical, |el| {
70                el.w(px(1.)).h(px(36.))
71            })
72            .refine_style(&self.style)
73    }
74}