Skip to content

Commit c4e8f4d

Browse files
acolombiermmstick
authored andcommitted
feat(settings/section): add method to create section with a list column
1 parent 9a57e36 commit c4e8f4d

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/widget/settings/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// SPDX-License-Identifier: MPL-2.0
33

44
pub mod item;
5-
mod section;
5+
pub mod section;
66

77
pub use self::item::{flex_item, flex_item_row, item, item_row};
88
pub use self::section::{view_section, Section};

src/widget/settings/section.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,42 @@ use crate::Element;
77
use std::borrow::Cow;
88

99
/// A section within a settings view column.
10-
#[must_use]
1110
pub fn view_section<'a, Message: 'static>(title: impl Into<Cow<'a, str>>) -> Section<'a, Message> {
1211
Section {
1312
title: title.into(),
1413
children: ListColumn::default(),
1514
}
1615
}
1716

17+
/// A section with a pre-defined list column.
18+
pub fn with_column<'a, Message: 'static>(
19+
children: ListColumn<'a, Message>,
20+
) -> Section<'a, Message> {
21+
Section {
22+
title: Cow::Borrowed(""),
23+
children,
24+
}
25+
}
26+
27+
#[must_use]
1828
pub struct Section<'a, Message> {
1929
title: Cow<'a, str>,
2030
children: ListColumn<'a, Message>,
2131
}
2232

2333
impl<'a, Message: 'static> Section<'a, Message> {
24-
#[must_use]
34+
/// Add a child element to the section's list column.
2535
#[allow(clippy::should_implement_trait)]
2636
pub fn add(mut self, item: impl Into<Element<'a, Message>>) -> Self {
2737
self.children = self.children.add(item.into());
2838
self
2939
}
40+
41+
/// Define an optional title for the section.
42+
pub fn title(mut self, title: impl Into<Cow<'a, str>>) -> Self {
43+
self.title = title.into();
44+
self
45+
}
3046
}
3147

3248
impl<'a, Message: 'static> From<Section<'a, Message>> for Element<'a, Message> {

0 commit comments

Comments
 (0)