From 0dfaa4d158d85fc9218d5be84cd7a63634940607 Mon Sep 17 00:00:00 2001 From: wiiznokes <78230769+wiiznokes@users.noreply.github.com> Date: Sat, 19 Oct 2024 01:06:10 +0200 Subject: [PATCH] Update section.rs --- src/widget/settings/section.rs | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/widget/settings/section.rs b/src/widget/settings/section.rs index 3e6c66aa..d42c2318 100644 --- a/src/widget/settings/section.rs +++ b/src/widget/settings/section.rs @@ -37,6 +37,12 @@ pub struct Section<'a, Message> { } impl<'a, Message: 'static> Section<'a, Message> { + /// Define an optional title for the section. + pub fn title(mut self, title: impl Into>) -> Self { + self.title = title.into(); + self + } + /// Add a child element to the section's list column. #[allow(clippy::should_implement_trait)] pub fn add(mut self, item: impl Into>) -> Self { @@ -44,10 +50,21 @@ impl<'a, Message: 'static> Section<'a, Message> { self } - /// Define an optional title for the section. - pub fn title(mut self, title: impl Into>) -> Self { - self.title = title.into(); - self + /// Add a child element to the section's list column, if `Some`. + pub fn add_maybe(self, item: Option>>) -> Self { + if let Some(item) = item { + self.add(item) + } else { + self + } + } + + /// Extends the [`Section`] with the given children. + pub fn extend( + self, + children: impl IntoIterator>>, + ) -> Self { + children.into_iter().fold(self, Self::add) } }