feat: SVG styling with icon fill color
This commit is contained in:
parent
0249640213
commit
75ae0de9bd
7 changed files with 137 additions and 22 deletions
|
|
@ -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;
|
||||
|
|
|
|||
21
style/src/svg.rs
Normal file
21
style/src/svg.rs
Normal file
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue