feat(settings/section): add method to create section with a list column

This commit is contained in:
Antoine C 2024-09-04 17:22:45 +01:00 committed by Michael Murphy
parent 9a57e36d1c
commit c4e8f4d1e6
2 changed files with 19 additions and 3 deletions

View file

@ -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};

View file

@ -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<Cow<'a, str>>) -> Section<'a, Message> {
Section {
title: title.into(),
@ -15,18 +14,35 @@ pub fn view_section<'a, Message: 'static>(title: impl Into<Cow<'a, str>>) -> 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<Element<'a, Message>>) -> Self {
self.children = self.children.add(item.into());
self
}
/// Define an optional title for the section.
pub fn title(mut self, title: impl Into<Cow<'a, str>>) -> Self {
self.title = title.into();
self
}
}
impl<'a, Message: 'static> From<Section<'a, Message>> for Element<'a, Message> {