Remove appearance from Handle
... and pass it directly to `Renderer::draw` instead.
This commit is contained in:
parent
314b0f7dc5
commit
b205a66347
14 changed files with 112 additions and 75 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue