list_sub_header.rs

 1use crate::prelude::*;
 2use crate::{h_flex, Icon, IconName, IconSize, Label};
 3
 4#[derive(IntoElement)]
 5pub struct ListSubHeader {
 6    label: SharedString,
 7    start_slot: Option<IconName>,
 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<IconName>) -> 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_flex().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(
44                            self.start_slot
45                                .map(|i| Icon::new(i).color(Color::Muted).size(IconSize::Small)),
46                        )
47                        .child(Label::new(self.label.clone()).color(Color::Muted)),
48                ),
49        )
50    }
51}