Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/widget/settings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// 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};
pub use self::section::{section, view_section, Section};

use crate::widget::{column, Column};
use crate::Element;
Expand Down
26 changes: 24 additions & 2 deletions src/widget/settings/section.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,48 @@ use crate::Element;
use std::borrow::Cow;

/// A section within a settings view column.
#[must_use]
#[deprecated(note = "use `settings::section().title()` instead")]
pub fn view_section<'a, Message: 'static>(title: impl Into<Cow<'a, str>>) -> Section<'a, Message> {
Section {
title: title.into(),
children: ListColumn::default(),
}
}

/// A section within a settings view column.
pub fn section<'a, Message: 'static>() -> Section<'a, Message> {
with_column(ListColumn::default())
}

/// 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> {
Expand Down
Loading