1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use freya_engine::prelude::*;

use crate::parsing::{
    Parse,
    ParseError,
};

#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
pub enum SvgPaint {
    #[default]
    None,
    CurrentColor,
    Color(Color),
}

impl Parse for SvgPaint {
    fn parse(value: &str) -> Result<Self, ParseError> {
        match value {
            "current_color" => Ok(SvgPaint::CurrentColor),
            "none" => Ok(SvgPaint::None),
            value => Ok(SvgPaint::Color(Color::parse(value)?)),
        }
    }
}

impl From<SvgPaint> for svg::Paint {
    fn from(value: SvgPaint) -> Self {
        match value {
            SvgPaint::None => svg::Paint::none(),
            SvgPaint::CurrentColor => svg::Paint::current_color(),
            SvgPaint::Color(color) => svg::Paint::from_color(color),
        }
    }
}