2022-12-06 16:12:59 +01:00
|
|
|
// Copyright 2022 System76 <info@system76.com>
|
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
|
2022-12-07 03:03:41 +01:00
|
|
|
use crate::widget::ListColumn;
|
|
|
|
|
use crate::Element;
|
2022-12-06 16:12:59 +01:00
|
|
|
use iced::widget::{column, text};
|
2022-12-07 03:03:41 +01:00
|
|
|
use std::borrow::Cow;
|
2022-12-06 16:12:59 +01:00
|
|
|
|
|
|
|
|
/// A section within a settings view column.
|
|
|
|
|
#[must_use]
|
2022-12-07 03:03:41 +01:00
|
|
|
pub fn view_section<'a, Message: 'static>(title: impl Into<Cow<'a, str>>) -> Section<'a, Message> {
|
|
|
|
|
Section {
|
|
|
|
|
title: title.into(),
|
|
|
|
|
children: ListColumn::default(),
|
|
|
|
|
}
|
2022-12-06 16:12:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub struct Section<'a, Message> {
|
2022-12-07 03:03:41 +01:00
|
|
|
title: Cow<'a, str>,
|
|
|
|
|
children: ListColumn<'a, Message>,
|
2022-12-06 16:12:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'a, Message: 'static> Section<'a, Message> {
|
|
|
|
|
#[must_use]
|
|
|
|
|
pub fn add(mut self, item: impl Into<Element<'a, Message>>) -> Self {
|
|
|
|
|
self.children = self.children.add(item.into());
|
|
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'a, Message: 'static> From<Section<'a, Message>> for Element<'a, Message> {
|
|
|
|
|
fn from(data: Section<'a, Message>) -> Self {
|
2022-12-07 03:03:41 +01:00
|
|
|
let title = text(data.title).font(crate::font::FONT_SEMIBOLD).into();
|
2022-12-06 16:12:59 +01:00
|
|
|
|
|
|
|
|
column(vec![title, data.children.into_element()])
|
|
|
|
|
.spacing(8)
|
|
|
|
|
.into()
|
|
|
|
|
}
|
2022-12-07 03:03:41 +01:00
|
|
|
}
|