list_sub_header.rs

 1use gpui::Div;
 2
 3use crate::prelude::*;
 4use crate::{h_stack, Icon, IconElement, IconSize, Label};
 5
 6#[derive(IntoElement)]
 7pub struct ListSubHeader {
 8    label: SharedString,
 9    left_icon: Option<Icon>,
10    inset: bool,
11}
12
13impl ListSubHeader {
14    pub fn new(label: impl Into<SharedString>) -> Self {
15        Self {
16            label: label.into(),
17            left_icon: None,
18            inset: false,
19        }
20    }
21
22    pub fn left_icon(mut self, left_icon: Option<Icon>) -> Self {
23        self.left_icon = left_icon;
24        self
25    }
26}
27
28impl RenderOnce for ListSubHeader {
29    type Rendered = Div;
30
31    fn render(self, _cx: &mut WindowContext) -> Self::Rendered {
32        h_stack().flex_1().w_full().relative().py_1().child(
33            div()
34                .h_6()
35                .when(self.inset, |this| this.px_2())
36                .flex()
37                .flex_1()
38                .w_full()
39                .gap_1()
40                .items_center()
41                .justify_between()
42                .child(
43                    div()
44                        .flex()
45                        .gap_1()
46                        .items_center()
47                        .children(self.left_icon.map(|i| {
48                            IconElement::new(i)
49                                .color(Color::Muted)
50                                .size(IconSize::Small)
51                        }))
52                        .child(Label::new(self.label.clone()).color(Color::Muted)),
53                ),
54        )
55    }
56}