feat(settings/section): support custom header widgets
This commit is contained in:
parent
29f38f83a3
commit
8415d77b0a
1 changed files with 10 additions and 12 deletions
|
|
@ -8,10 +8,7 @@ use std::borrow::Cow;
|
||||||
/// A section within a settings view column.
|
/// A section within a settings view column.
|
||||||
#[deprecated(note = "use `settings::section().title()` instead")]
|
#[deprecated(note = "use `settings::section().title()` instead")]
|
||||||
pub fn view_section<'a, Message: 'static>(title: impl Into<Cow<'a, str>>) -> Section<'a, Message> {
|
pub fn view_section<'a, Message: 'static>(title: impl Into<Cow<'a, str>>) -> Section<'a, Message> {
|
||||||
Section {
|
section().title(title)
|
||||||
title: title.into(),
|
|
||||||
children: ListColumn::default(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A section within a settings view column.
|
/// A section within a settings view column.
|
||||||
|
|
@ -22,21 +19,26 @@ pub fn section<'a, Message: 'static>() -> Section<'a, Message> {
|
||||||
/// A section with a pre-defined list column.
|
/// A section with a pre-defined list column.
|
||||||
pub fn with_column<Message: 'static>(children: ListColumn<'_, Message>) -> Section<'_, Message> {
|
pub fn with_column<Message: 'static>(children: ListColumn<'_, Message>) -> Section<'_, Message> {
|
||||||
Section {
|
Section {
|
||||||
title: Cow::Borrowed(""),
|
header: None,
|
||||||
children,
|
children,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub struct Section<'a, Message> {
|
pub struct Section<'a, Message> {
|
||||||
title: Cow<'a, str>,
|
header: Option<Element<'a, Message>>,
|
||||||
children: ListColumn<'a, Message>,
|
children: ListColumn<'a, Message>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Message: 'static> Section<'a, Message> {
|
impl<'a, Message: 'static> Section<'a, Message> {
|
||||||
/// Define an optional title for the section.
|
/// Define an optional title for the section.
|
||||||
pub fn title(mut self, title: impl Into<Cow<'a, str>>) -> Self {
|
pub fn title(mut self, title: impl Into<Cow<'a, str>>) -> Self {
|
||||||
self.title = title.into();
|
self.header(text::heading(title.into()))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Define an optional custom header for the section.
|
||||||
|
pub fn header(mut self, header: impl Into<Element<'a, Message>>) -> Self {
|
||||||
|
self.header = Some(header.into());
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -69,11 +71,7 @@ impl<'a, Message: 'static> From<Section<'a, Message>> for Element<'a, Message> {
|
||||||
fn from(data: Section<'a, Message>) -> Self {
|
fn from(data: Section<'a, Message>) -> Self {
|
||||||
column::with_capacity(2)
|
column::with_capacity(2)
|
||||||
.spacing(8)
|
.spacing(8)
|
||||||
.push_maybe(if data.title.is_empty() {
|
.push_maybe(data.header)
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(text::heading(data.title))
|
|
||||||
})
|
|
||||||
.push(data.children)
|
.push(data.children)
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue