From b205a663471a8170d7b30cc59894425c09bea563 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 6 Dec 2022 04:34:00 +0100 Subject: Remove `appearance` from `Handle` ... and pass it directly to `Renderer::draw` instead. --- style/src/theme.rs | 61 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 23 deletions(-) (limited to 'style/src/theme.rs') 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 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>), +} + +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 { -- cgit