diff options
Diffstat (limited to 'style')
-rw-r--r-- | style/Cargo.toml | 2 | ||||
-rw-r--r-- | style/src/lib.rs | 1 | ||||
-rw-r--r-- | style/src/svg.rs | 23 | ||||
-rw-r--r-- | style/src/theme.rs | 41 |
4 files changed, 65 insertions, 2 deletions
diff --git a/style/Cargo.toml b/style/Cargo.toml index 559b4462..9f7d904a 100644 --- a/style/Cargo.toml +++ b/style/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "iced_style" -version = "0.5.0" +version = "0.5.1" authors = ["Héctor Ramón Jiménez <hector0193@gmail.com>"] edition = "2021" description = "The default set of styles of Iced" 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..9378c1a7 --- /dev/null +++ b/style/src/svg.rs @@ -0,0 +1,23 @@ +//! Change the appearance of a svg. + +use iced_core::Color; + +/// The appearance of an SVG. +#[derive(Debug, Default, Clone, Copy)] +pub struct Appearance { + /// The [`Color`] filter of an SVG. + /// + /// Useful for coloring a symbolic icon. + /// + /// `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; + + /// 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 bd0ae28e..a766b279 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; @@ -559,7 +560,7 @@ impl pick_list::StyleSheet for Theme { border_color: palette.primary.strong.color, } } - PickList::Custom(custom, _) => custom.active(self), + PickList::Custom(custom, _) => custom.hovered(self), } } } @@ -823,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 { |