From c275fde67a7f5d1d5789540dc7905250a2f01fe7 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 1 Jun 2022 01:56:46 +0200 Subject: Implement theme styling for `Rule` --- style/src/rule.rs | 74 ++++++++++++++++-------------------------------------- style/src/theme.rs | 19 ++++++++++++++ 2 files changed, 40 insertions(+), 53 deletions(-) (limited to 'style/src') diff --git a/style/src/rule.rs b/style/src/rule.rs index 12a40f7d..af334912 100644 --- a/style/src/rule.rs +++ b/style/src/rule.rs @@ -1,6 +1,27 @@ //! Display a horizontal or vertical rule for dividing content. use iced_core::Color; +/// The appearance of a rule. +#[derive(Debug, Clone, Copy)] +pub struct Appearance { + /// The color of the rule. + pub color: Color, + /// The width (thickness) of the rule line. + pub width: u16, + /// The radius of the line corners. + pub radius: f32, + /// The [`FillMode`] of the rule. + pub fill_mode: FillMode, +} + +/// A set of rules that dictate the style of a rule. +pub trait StyleSheet { + type Style: Default + Copy; + + /// Produces the style of a rule. + fn style(&self, style: Self::Style) -> Appearance; +} + /// The fill mode of a rule. #[derive(Debug, Clone, Copy)] pub enum FillMode { @@ -64,56 +85,3 @@ impl FillMode { } } } - -/// The appearance of a rule. -#[derive(Debug, Clone, Copy)] -pub struct Style { - /// The color of the rule. - pub color: Color, - /// The width (thickness) of the rule line. - pub width: u16, - /// The radius of the line corners. - pub radius: f32, - /// The [`FillMode`] of the rule. - pub fill_mode: FillMode, -} - -impl std::default::Default for Style { - fn default() -> Self { - Style { - color: [0.6, 0.6, 0.6, 0.6].into(), - width: 1, - radius: 0.0, - fill_mode: FillMode::Full, - } - } -} - -/// A set of rules that dictate the style of a rule. -pub trait StyleSheet { - /// Produces the style of a rule. - fn style(&self) -> Style; -} - -struct Default; - -impl StyleSheet for Default { - fn style(&self) -> Style { - Style::default() - } -} - -impl<'a> std::default::Default for Box { - fn default() -> Self { - Box::new(Default) - } -} - -impl<'a, T> From for Box -where - T: 'a + StyleSheet, -{ - fn from(style: T) -> Self { - Box::new(style) - } -} diff --git a/style/src/theme.rs b/style/src/theme.rs index 71330c2e..713225e1 100644 --- a/style/src/theme.rs +++ b/style/src/theme.rs @@ -6,6 +6,7 @@ use crate::application; use crate::button; use crate::pane_grid; use crate::radio; +use crate::rule; use crate::slider; use crate::toggler; @@ -279,3 +280,21 @@ impl pane_grid::StyleSheet for Theme { }) } } + +/* + * Rule + */ +impl rule::StyleSheet for Theme { + type Style = (); + + fn style(&self, _style: Self::Style) -> rule::Appearance { + let palette = self.extended_palette(); + + rule::Appearance { + color: palette.background.strong.color, + width: 1, + radius: 0.0, + fill_mode: rule::FillMode::Full, + } + } +} -- cgit