2022-12-06 16:12:59 +01:00
|
|
|
// Copyright 2022 System76 <info@system76.com>
|
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
|
2023-01-24 21:13:50 +01:00
|
|
|
use crate::{theme, widget::divider, Element};
|
2023-01-03 21:35:35 +01:00
|
|
|
use apply::Apply;
|
2022-12-06 16:12:59 +01:00
|
|
|
use iced::{Background, Color};
|
|
|
|
|
|
|
|
|
|
#[must_use]
|
|
|
|
|
pub fn list_column<'a, Message: 'static>() -> ListColumn<'a, Message> {
|
|
|
|
|
ListColumn::default()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub struct ListColumn<'a, Message> {
|
|
|
|
|
children: Vec<Element<'a, Message>>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'a, Message: 'static> Default for ListColumn<'a, Message> {
|
|
|
|
|
fn default() -> Self {
|
2023-01-03 21:35:35 +01:00
|
|
|
Self {
|
|
|
|
|
children: Vec::with_capacity(4),
|
|
|
|
|
}
|
2022-12-06 16:12:59 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'a, Message: 'static> ListColumn<'a, Message> {
|
2022-12-23 15:10:13 +01:00
|
|
|
#[must_use]
|
2022-12-06 16:12:59 +01:00
|
|
|
pub fn new() -> Self {
|
|
|
|
|
Self::default()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[must_use]
|
2022-12-23 15:10:13 +01:00
|
|
|
#[allow(clippy::should_implement_trait)]
|
2022-12-06 16:12:59 +01:00
|
|
|
pub fn add(mut self, item: impl Into<Element<'a, Message>>) -> Self {
|
|
|
|
|
if !self.children.is_empty() {
|
2023-01-24 21:13:50 +01:00
|
|
|
self.children.push(divider::horizontal::light().into());
|
2022-12-06 16:12:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
self.children.push(item.into());
|
|
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[must_use]
|
|
|
|
|
pub fn into_element(self) -> Element<'a, Message> {
|
2023-09-01 07:29:19 +02:00
|
|
|
crate::widget::column::with_children(self.children)
|
2022-12-06 16:12:59 +01:00
|
|
|
.spacing(12)
|
2023-09-01 07:29:19 +02:00
|
|
|
.apply(crate::widget::container)
|
2022-12-21 12:18:54 -07:00
|
|
|
.padding([16, 6])
|
2023-04-28 16:04:57 -07:00
|
|
|
.style(theme::Container::custom(style))
|
2022-12-06 16:12:59 +01:00
|
|
|
.into()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'a, Message: 'static> From<ListColumn<'a, Message>> for Element<'a, Message> {
|
|
|
|
|
fn from(column: ListColumn<'a, Message>) -> Self {
|
|
|
|
|
column.into_element()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-23 15:10:13 +01:00
|
|
|
#[must_use]
|
|
|
|
|
#[allow(clippy::trivially_copy_pass_by_ref)]
|
2023-09-01 07:29:19 +02:00
|
|
|
pub fn style(theme: &crate::Theme) -> crate::widget::container::Appearance {
|
2023-02-27 19:56:53 -05:00
|
|
|
let container = &theme.current_container().component;
|
2023-09-01 07:29:19 +02:00
|
|
|
crate::widget::container::Appearance {
|
|
|
|
|
icon_color: Some(container.on.into()),
|
2023-02-27 17:42:17 -05:00
|
|
|
text_color: Some(container.on.into()),
|
|
|
|
|
background: Some(Background::Color(container.base.into())),
|
2023-05-30 12:03:15 -04:00
|
|
|
border_radius: 8.0.into(),
|
2022-12-06 16:12:59 +01:00
|
|
|
border_width: 0.0,
|
|
|
|
|
border_color: Color::TRANSPARENT,
|
|
|
|
|
}
|
2022-12-20 15:06:01 -07:00
|
|
|
}
|