section_items.rs

 1use gpui::{IntoElement, ParentElement, Styled};
 2use ui::{Divider, DividerColor, prelude::*};
 3
 4#[derive(IntoElement)]
 5pub struct SettingsSectionHeader {
 6    icon: Option<IconName>,
 7    label: SharedString,
 8    no_padding: bool,
 9}
10
11impl SettingsSectionHeader {
12    pub fn new(label: impl Into<SharedString>) -> Self {
13        Self {
14            label: label.into(),
15            icon: None,
16            no_padding: false,
17        }
18    }
19
20    pub fn icon(mut self, icon: IconName) -> Self {
21        self.icon = Some(icon);
22        self
23    }
24
25    pub fn no_padding(mut self, no_padding: bool) -> Self {
26        self.no_padding = no_padding;
27        self
28    }
29}
30
31impl RenderOnce for SettingsSectionHeader {
32    fn render(self, _: &mut Window, cx: &mut App) -> impl IntoElement {
33        let label = Label::new(self.label)
34            .size(LabelSize::Small)
35            .color(Color::Muted)
36            .buffer_font(cx);
37
38        v_flex()
39            .w_full()
40            .when(!self.no_padding, |this| this.px_8())
41            .gap_1p5()
42            .map(|this| {
43                if self.icon.is_some() {
44                    this.child(
45                        h_flex()
46                            .gap_1p5()
47                            .child(Icon::new(self.icon.unwrap()).color(Color::Muted))
48                            .child(label),
49                    )
50                } else {
51                    this.child(label)
52                }
53            })
54            .child(Divider::horizontal().color(DividerColor::BorderFaded))
55    }
56}