freya_core/values/
paint.rs

1use freya_engine::prelude::*;
2
3use crate::parsing::{
4    Parse,
5    ParseError,
6};
7
8#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
9pub enum SvgPaint {
10    #[default]
11    None,
12    CurrentColor,
13    Color(Color),
14}
15
16impl Parse for SvgPaint {
17    fn parse(value: &str) -> Result<Self, ParseError> {
18        match value {
19            "current_color" => Ok(SvgPaint::CurrentColor),
20            "none" => Ok(SvgPaint::None),
21            value => Ok(SvgPaint::Color(Color::parse(value)?)),
22        }
23    }
24}
25
26impl From<SvgPaint> for svg::Paint {
27    fn from(value: SvgPaint) -> Self {
28        match value {
29            SvgPaint::None => svg::Paint::none(),
30            SvgPaint::CurrentColor => svg::Paint::current_color(),
31            SvgPaint::Color(color) => svg::Paint::from_color(color),
32        }
33    }
34}