list_sub_header.rs

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