Skip to main content

fc_ui/capabilities/foundation/
styled_ext.rs

1use gpui::*;
2
3pub trait StyledExt: Styled + Sized {
4    fn center(self) -> Self {
5        self.flex().items_center().justify_center()
6    }
7
8    fn stack(self) -> Self {
9        self.flex().flex_col()
10    }
11
12    fn row(self) -> Self {
13        self.flex().flex_row()
14    }
15
16    fn glass(self, opacity: f32) -> Self {
17        let bg_color = hsla(0.0, 0.0, 1.0, 0.08 * opacity);
18        let border_color = hsla(0.0, 0.0, 1.0, 0.12 * opacity);
19        self.bg(bg_color).border_1().border_color(border_color)
20    }
21
22    fn elevated(self, level: u8) -> Self {
23        let shadow = match level {
24            0 => return self,
25            1 => BoxShadow {
26                offset: point(px(0.0), px(1.0)),
27                blur_radius: px(2.0),
28                spread_radius: px(0.0),
29                inset: false,
30                color: hsla(0.0, 0.0, 0.0, 0.05),
31            },
32            2 => BoxShadow {
33                offset: point(px(0.0), px(1.0)),
34                blur_radius: px(3.0),
35                spread_radius: px(0.0),
36                inset: false,
37                color: hsla(0.0, 0.0, 0.0, 0.1),
38            },
39            3 => BoxShadow {
40                offset: point(px(0.0), px(4.0)),
41                blur_radius: px(6.0),
42                spread_radius: px(-1.0),
43                inset: false,
44                color: hsla(0.0, 0.0, 0.0, 0.1),
45            },
46            4 => BoxShadow {
47                offset: point(px(0.0), px(10.0)),
48                blur_radius: px(15.0),
49                spread_radius: px(-3.0),
50                inset: false,
51                color: hsla(0.0, 0.0, 0.0, 0.1),
52            },
53            _ => BoxShadow {
54                offset: point(px(0.0), px(20.0)),
55                blur_radius: px(25.0),
56                spread_radius: px(-5.0),
57                inset: false,
58                color: hsla(0.0, 0.0, 0.0, 0.1),
59            },
60        };
61        self.shadow(smallvec::smallvec![shadow])
62    }
63
64    fn ring(self, color: Hsla, width: Pixels) -> Self {
65        let shadow = BoxShadow {
66            offset: point(px(0.0), px(0.0)),
67            blur_radius: px(0.0),
68            spread_radius: width,
69            inset: false,
70            color,
71        };
72        self.shadow(smallvec::smallvec![shadow])
73    }
74}
75
76impl<T: Styled + Sized> StyledExt for T {}