diff --git a/src/widget/settings/mod.rs b/src/widget/settings/mod.rs index dedbc886..05452b35 100644 --- a/src/widget/settings/mod.rs +++ b/src/widget/settings/mod.rs @@ -2,7 +2,7 @@ // SPDX-License-Identifier: MPL-2.0 pub mod item; -mod section; +pub mod section; pub use self::item::{flex_item, flex_item_row, item, item_row}; pub use self::section::{view_section, Section}; diff --git a/src/widget/settings/section.rs b/src/widget/settings/section.rs index 9fde8131..29f18ca4 100644 --- a/src/widget/settings/section.rs +++ b/src/widget/settings/section.rs @@ -7,7 +7,6 @@ use crate::Element; use std::borrow::Cow; /// A section within a settings view column. -#[must_use] pub fn view_section<'a, Message: 'static>(title: impl Into>) -> Section<'a, Message> { Section { title: title.into(), @@ -15,18 +14,35 @@ pub fn view_section<'a, Message: 'static>(title: impl Into>) -> Sec } } +/// A section with a pre-defined list column. +pub fn with_column<'a, Message: 'static>( + children: ListColumn<'a, Message>, +) -> Section<'a, Message> { + Section { + title: Cow::Borrowed(""), + children, + } +} + +#[must_use] pub struct Section<'a, Message> { title: Cow<'a, str>, children: ListColumn<'a, Message>, } impl<'a, Message: 'static> Section<'a, Message> { - #[must_use] + /// Add a child element to the section's list column. #[allow(clippy::should_implement_trait)] pub fn add(mut self, item: impl Into>) -> Self { self.children = self.children.add(item.into()); self } + + /// Define an optional title for the section. + pub fn title(mut self, title: impl Into>) -> Self { + self.title = title.into(); + self + } } impl<'a, Message: 'static> From> for Element<'a, Message> {