settings_group.rs

 1#![allow(missing_docs)]
 2
 3use gpui::AnyElement;
 4use smallvec::SmallVec;
 5
 6use crate::{prelude::*, ListHeader};
 7
 8/// A group of settings.
 9#[derive(IntoElement)]
10pub struct SettingsGroup {
11    header: SharedString,
12    children: SmallVec<[AnyElement; 2]>,
13}
14
15impl SettingsGroup {
16    pub fn new(header: impl Into<SharedString>) -> Self {
17        Self {
18            header: header.into(),
19            children: SmallVec::new(),
20        }
21    }
22}
23
24impl ParentElement for SettingsGroup {
25    fn extend(&mut self, elements: impl IntoIterator<Item = AnyElement>) {
26        self.children.extend(elements)
27    }
28}
29
30impl RenderOnce for SettingsGroup {
31    fn render(self, _window: &mut Window, _cx: &mut App) -> impl IntoElement {
32        v_flex()
33            .p_1()
34            .gap_2()
35            .child(ListHeader::new(self.header))
36            .children(self.children)
37    }
38}