diff options
author | 2022-12-06 04:34:00 +0100 | |
---|---|---|
committer | 2022-12-06 04:34:00 +0100 | |
commit | b205a663471a8170d7b30cc59894425c09bea563 (patch) | |
tree | 53514f16226949f1e2440eed8ead4dec968c8d95 /style | |
parent | 314b0f7dc52c844669c224060a7b03e842762370 (diff) | |
download | iced-b205a663471a8170d7b30cc59894425c09bea563.tar.gz iced-b205a663471a8170d7b30cc59894425c09bea563.tar.bz2 iced-b205a663471a8170d7b30cc59894425c09bea563.zip |
Remove `appearance` from `Handle`
... and pass it directly to `Renderer::draw` instead.
Diffstat (limited to 'style')
-rw-r--r-- | style/src/svg.rs | 12 | ||||
-rw-r--r-- | style/src/theme.rs | 61 |
2 files changed, 45 insertions, 28 deletions
diff --git a/style/src/svg.rs b/style/src/svg.rs index 66791d04..9378c1a7 100644 --- a/style/src/svg.rs +++ b/style/src/svg.rs @@ -2,20 +2,22 @@ use iced_core::Color; -/// The appearance of a svg. +/// The appearance of an SVG. #[derive(Debug, Default, Clone, Copy)] pub struct Appearance { - /// Changes the fill color + /// The [`Color`] filter of an SVG. /// /// Useful for coloring a symbolic icon. - pub fill: Option<Color>, + /// + /// `None` keeps the original color. + pub color: Option<Color>, } /// The stylesheet of a svg. pub trait StyleSheet { /// The supported style of the [`StyleSheet`]. - type Style: Default + Copy; + type Style: Default; /// Produces the [`Appearance`] of the svg. - fn appearance(&self, style: Self::Style) -> Appearance; + fn appearance(&self, style: &Self::Style) -> Appearance; } diff --git a/style/src/theme.rs b/style/src/theme.rs index d825b086..d2b583ed 100644 --- a/style/src/theme.rs +++ b/style/src/theme.rs @@ -798,29 +798,6 @@ impl From<fn(&Theme) -> rule::Appearance> for Rule { } } -/** - * SVG - */ -#[derive(Default, Clone, Copy)] -pub enum Svg { - /// No filtering to the rendered SVG. - #[default] - Default, - /// Apply custom filtering to the SVG. - Custom(fn(&Theme) -> svg::Appearance), -} - -impl svg::StyleSheet for Theme { - type Style = Svg; - - fn appearance(&self, style: Self::Style) -> svg::Appearance { - match style { - Svg::Default => Default::default(), - Svg::Custom(appearance) => appearance(self), - } - } -} - impl rule::StyleSheet for Theme { type Style = Rule; @@ -847,6 +824,44 @@ impl rule::StyleSheet for fn(&Theme) -> rule::Appearance { } } +/** + * SVG + */ +#[derive(Default)] +pub enum Svg { + /// No filtering to the rendered SVG. + #[default] + Default, + /// A custom style. + Custom(Box<dyn svg::StyleSheet<Style = Theme>>), +} + +impl Svg { + /// Creates a custom [`Svg`] style. + pub fn custom_fn(f: fn(&Theme) -> svg::Appearance) -> Self { + Self::Custom(Box::new(f)) + } +} + +impl svg::StyleSheet for Theme { + type Style = Svg; + + fn appearance(&self, style: &Self::Style) -> svg::Appearance { + match style { + Svg::Default => Default::default(), + Svg::Custom(custom) => custom.appearance(self), + } + } +} + +impl svg::StyleSheet for fn(&Theme) -> svg::Appearance { + type Style = Theme; + + fn appearance(&self, style: &Self::Style) -> svg::Appearance { + (self)(style) + } +} + /// The style of a scrollable. #[derive(Default)] pub enum Scrollable { |