diff options
author | 2022-11-16 17:42:41 +0100 | |
---|---|---|
committer | 2022-12-06 03:59:53 +0100 | |
commit | 75ae0de9bdd3376b6e537bf59030059c926114ee (patch) | |
tree | f9b701705ccce1ef0bb391f04dc1db8af18dcf09 /style | |
parent | 0249640213120e039462f5fc12c677f15ecbc7cc (diff) | |
download | iced-75ae0de9bdd3376b6e537bf59030059c926114ee.tar.gz iced-75ae0de9bdd3376b6e537bf59030059c926114ee.tar.bz2 iced-75ae0de9bdd3376b6e537bf59030059c926114ee.zip |
feat: SVG styling with icon fill color
Diffstat (limited to 'style')
-rw-r--r-- | style/src/lib.rs | 1 | ||||
-rw-r--r-- | style/src/svg.rs | 21 | ||||
-rw-r--r-- | style/src/theme.rs | 24 |
3 files changed, 46 insertions, 0 deletions
diff --git a/style/src/lib.rs b/style/src/lib.rs index 3242602c..59eb1eb8 100644 --- a/style/src/lib.rs +++ b/style/src/lib.rs @@ -32,6 +32,7 @@ pub mod radio; pub mod rule; pub mod scrollable; pub mod slider; +pub mod svg; pub mod text; pub mod text_input; pub mod theme; diff --git a/style/src/svg.rs b/style/src/svg.rs new file mode 100644 index 00000000..66791d04 --- /dev/null +++ b/style/src/svg.rs @@ -0,0 +1,21 @@ +//! Change the appearance of a svg. + +use iced_core::Color; + +/// The appearance of a svg. +#[derive(Debug, Default, Clone, Copy)] +pub struct Appearance { + /// Changes the fill color + /// + /// Useful for coloring a symbolic icon. + pub fill: Option<Color>, +} + +/// The stylesheet of a svg. +pub trait StyleSheet { + /// The supported style of the [`StyleSheet`]. + type Style: Default + Copy; + + /// Produces the [`Appearance`] of the svg. + fn appearance(&self, style: Self::Style) -> Appearance; +} diff --git a/style/src/theme.rs b/style/src/theme.rs index dde0df5d..d825b086 100644 --- a/style/src/theme.rs +++ b/style/src/theme.rs @@ -16,6 +16,7 @@ use crate::radio; use crate::rule; use crate::scrollable; use crate::slider; +use crate::svg; use crate::text; use crate::text_input; use crate::toggler; @@ -797,6 +798,29 @@ 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; |