From 51ac288eede5a6e24b2bba181ed3e4830689525b Mon Sep 17 00:00:00 2001 From: Michael Aaron Murphy Date: Wed, 13 Sep 2023 15:43:24 +0200 Subject: [PATCH] feat(widget): create list-styled containers with `list::container()` --- src/widget/list/column.rs | 22 ++-------------------- src/widget/list/mod.rs | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/src/widget/list/column.rs b/src/widget/list/column.rs index 0ae79ce3..529f7369 100644 --- a/src/widget/list/column.rs +++ b/src/widget/list/column.rs @@ -1,9 +1,7 @@ // Copyright 2022 System76 // SPDX-License-Identifier: MPL-2.0 -use crate::{theme, widget::divider, Element}; -use apply::Apply; -use iced::{Background, Color}; +use crate::{widget::divider, Apply, Element}; #[must_use] pub fn list_column<'a, Message: 'static>() -> ListColumn<'a, Message> { @@ -43,9 +41,7 @@ impl<'a, Message: 'static> ListColumn<'a, Message> { pub fn into_element(self) -> Element<'a, Message> { crate::widget::column::with_children(self.children) .spacing(12) - .apply(crate::widget::container) - .padding([16, 6]) - .style(theme::Container::custom(style)) + .apply(super::container) .into() } } @@ -55,17 +51,3 @@ impl<'a, Message: 'static> From> for Element<'a, Message column.into_element() } } - -#[must_use] -#[allow(clippy::trivially_copy_pass_by_ref)] -pub fn style(theme: &crate::Theme) -> crate::widget::container::Appearance { - let container = &theme.current_container().component; - crate::widget::container::Appearance { - icon_color: Some(container.on.into()), - text_color: Some(container.on.into()), - background: Some(Background::Color(container.base.into())), - border_radius: 8.0.into(), - border_width: 0.0, - border_color: Color::TRANSPARENT, - } -} diff --git a/src/widget/list/mod.rs b/src/widget/list/mod.rs index f7170d10..0217fe4f 100644 --- a/src/widget/list/mod.rs +++ b/src/widget/list/mod.rs @@ -6,3 +6,30 @@ pub mod column; pub use self::column::{list_column, ListColumn}; // pub use self::item::{ListItem, list_item}; + +use crate::widget::Container; +use crate::Element; +use iced::{Background, Color}; + +pub fn container<'a, Message>( + content: impl Into>, +) -> Container<'a, Message, crate::Renderer> { + super::container(content) + .padding([16, 6]) + .style(crate::theme::Container::custom(style)) + .width(iced::Length::Fill) +} + +#[must_use] +#[allow(clippy::trivially_copy_pass_by_ref)] +pub fn style(theme: &crate::Theme) -> crate::widget::container::Appearance { + let container = &theme.current_container().component; + crate::widget::container::Appearance { + icon_color: Some(container.on.into()), + text_color: Some(container.on.into()), + background: Some(Background::Color(container.base.into())), + border_radius: 8.0.into(), + border_width: 0.0, + border_color: Color::TRANSPARENT, + } +}