Skip to content

Commit 8415d77

Browse files
committed
feat(settings/section): support custom header widgets
1 parent 29f38f8 commit 8415d77

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

src/widget/settings/section.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ use std::borrow::Cow;
88
/// A section within a settings view column.
99
#[deprecated(note = "use `settings::section().title()` instead")]
1010
pub fn view_section<'a, Message: 'static>(title: impl Into<Cow<'a, str>>) -> Section<'a, Message> {
11-
Section {
12-
title: title.into(),
13-
children: ListColumn::default(),
14-
}
11+
section().title(title)
1512
}
1613

1714
/// A section within a settings view column.
@@ -22,21 +19,26 @@ pub fn section<'a, Message: 'static>() -> Section<'a, Message> {
2219
/// A section with a pre-defined list column.
2320
pub fn with_column<Message: 'static>(children: ListColumn<'_, Message>) -> Section<'_, Message> {
2421
Section {
25-
title: Cow::Borrowed(""),
22+
header: None,
2623
children,
2724
}
2825
}
2926

3027
#[must_use]
3128
pub struct Section<'a, Message> {
32-
title: Cow<'a, str>,
29+
header: Option<Element<'a, Message>>,
3330
children: ListColumn<'a, Message>,
3431
}
3532

3633
impl<'a, Message: 'static> Section<'a, Message> {
3734
/// Define an optional title for the section.
3835
pub fn title(mut self, title: impl Into<Cow<'a, str>>) -> Self {
39-
self.title = title.into();
36+
self.header(text::heading(title.into()))
37+
}
38+
39+
/// Define an optional custom header for the section.
40+
pub fn header(mut self, header: impl Into<Element<'a, Message>>) -> Self {
41+
self.header = Some(header.into());
4042
self
4143
}
4244

@@ -69,11 +71,7 @@ impl<'a, Message: 'static> From<Section<'a, Message>> for Element<'a, Message> {
6971
fn from(data: Section<'a, Message>) -> Self {
7072
column::with_capacity(2)
7173
.spacing(8)
72-
.push_maybe(if data.title.is_empty() {
73-
None
74-
} else {
75-
Some(text::heading(data.title))
76-
})
74+
.push_maybe(data.header)
7775
.push(data.children)
7876
.into()
7977
}

0 commit comments

Comments
 (0)