From 9a095e4d94b569eb3b4e150dce7607c2fe58fc49 Mon Sep 17 00:00:00 2001 From: Michael Aaron Murphy Date: Tue, 24 Jan 2023 21:13:50 +0100 Subject: [PATCH] feat(divider): add functions for divider style variants of a Rule --- src/theme/mod.rs | 20 ++++++++++++++++++++ src/widget/list/column.rs | 5 ++--- src/widget/mod.rs | 23 ++++++++++++++++++++--- src/widget/separator.rs | 26 -------------------------- 4 files changed, 42 insertions(+), 32 deletions(-) delete mode 100644 src/widget/separator.rs diff --git a/src/theme/mod.rs b/src/theme/mod.rs index 5be61bbb..71fb542b 100644 --- a/src/theme/mod.rs +++ b/src/theme/mod.rs @@ -652,6 +652,8 @@ impl progress_bar::StyleSheet for Theme { #[derive(Clone, Copy)] pub enum Rule { Default, + LightDivider, + HeavyDivider, Custom(fn(&Theme) -> rule::Appearance), } @@ -674,6 +676,24 @@ impl rule::StyleSheet for Theme { radius: 0.0, fill_mode: rule::FillMode::Full, }, + Rule::LightDivider => { + let cosmic = &self.cosmic().primary; + rule::Appearance { + color: cosmic.divider.into(), + width: 1, + radius: 0.0, + fill_mode: rule::FillMode::Padded(10), + } + } + Rule::HeavyDivider => { + let cosmic = &self.cosmic().primary; + rule::Appearance { + color: cosmic.divider.into(), + width: 4, + radius: 4.0, + fill_mode: rule::FillMode::Full, + } + } Rule::Custom(f) => f(self), } } diff --git a/src/widget/list/column.rs b/src/widget/list/column.rs index f39fa0fb..db6edcba 100644 --- a/src/widget/list/column.rs +++ b/src/widget/list/column.rs @@ -1,8 +1,7 @@ // Copyright 2022 System76 // SPDX-License-Identifier: MPL-2.0 -use crate::widget::horizontal_rule; -use crate::{theme, Element}; +use crate::{theme, widget::divider, Element}; use apply::Apply; use iced::{Background, Color}; @@ -33,7 +32,7 @@ impl<'a, Message: 'static> ListColumn<'a, Message> { #[allow(clippy::should_implement_trait)] pub fn add(mut self, item: impl Into>) -> Self { if !self.children.is_empty() { - self.children.push(horizontal_rule(10).into()); + self.children.push(divider::horizontal::light().into()); } self.children.push(item.into()); diff --git a/src/widget/mod.rs b/src/widget/mod.rs index d6bf8b82..121920b9 100644 --- a/src/widget/mod.rs +++ b/src/widget/mod.rs @@ -40,9 +40,6 @@ pub use scrollable::*; mod text; pub use text::{text, Text}; -pub mod separator; -pub use separator::{horizontal_rule, vertical_rule}; - pub mod spin_button; pub use spin_button::{spin_button, SpinButton}; @@ -56,3 +53,23 @@ pub use view_switcher::vertical as vertical_view_switcher; pub mod warning; pub use warning::*; + +/// An element to distinguish a boundary between two elements. +pub mod divider { + /// Horizontal variant of a divider. + pub mod horizontal { + use iced::widget::{horizontal_rule, Rule}; + + /// Horizontal divider with light thickness + #[must_use] + pub fn light() -> Rule { + horizontal_rule(4).style(crate::theme::Rule::LightDivider) + } + + /// Horizontal divider with heavy thickness. + #[must_use] + pub fn heavy() -> Rule { + horizontal_rule(10).style(crate::theme::Rule::HeavyDivider) + } + } +} diff --git a/src/widget/separator.rs b/src/widget/separator.rs deleted file mode 100644 index 3ace5518..00000000 --- a/src/widget/separator.rs +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2022 System76 -// SPDX-License-Identifier: MPL-2.0 - -use crate::iced::widget; -use crate::{theme, Renderer, Theme}; - -#[must_use] -pub fn horizontal_rule(size: u16) -> widget::Rule { - widget::horizontal_rule(size).style(theme::Rule::Custom(separator_style)) -} - -#[must_use] -pub fn vertical_rule(size: u16) -> widget::Rule { - widget::vertical_rule(size).style(theme::Rule::Custom(separator_style)) -} - -#[allow(clippy::trivially_copy_pass_by_ref)] -fn separator_style(theme: &Theme) -> widget::rule::Appearance { - let cosmic = &theme.cosmic().primary; - widget::rule::Appearance { - color: cosmic.divider.into(), - width: 1, - radius: 0.0, - fill_mode: widget::rule::FillMode::Padded(10), - } -}