From d053a3a2c4458586c40d5ead3216911f91bb8e05 Mon Sep 17 00:00:00 2001 From: Orchaldir Date: Wed, 1 Nov 2023 19:47:47 +0100 Subject: [PATCH] [#46] MR --- .../src/model/equipment/appearance/eyewear.rs | 2 +- rpg_tools_rendering/src/renderer/color.rs | 58 ------------------- rpg_tools_rendering/src/renderer/svg/mod.rs | 4 +- 3 files changed, 3 insertions(+), 61 deletions(-) diff --git a/rpg_tools_core/src/model/equipment/appearance/eyewear.rs b/rpg_tools_core/src/model/equipment/appearance/eyewear.rs index 51cc1a69..4794818b 100644 --- a/rpg_tools_core/src/model/equipment/appearance/eyewear.rs +++ b/rpg_tools_core/src/model/equipment/appearance/eyewear.rs @@ -31,7 +31,7 @@ pub struct LensStyle { pub lens_transparency: Transparency, } -/// The frame of the [`eyewear's`](Eyewear). +/// The frame of the [`eyewear`](Eyewear). #[derive(Convert, ui, Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] pub enum FrameType { Horn, diff --git a/rpg_tools_rendering/src/renderer/color.rs b/rpg_tools_rendering/src/renderer/color.rs index 0cc55b74..11abfdc2 100644 --- a/rpg_tools_rendering/src/renderer/color.rs +++ b/rpg_tools_rendering/src/renderer/color.rs @@ -40,33 +40,6 @@ impl WebColor { pub fn from_rgba(r: u8, g: u8, b: u8, a: u8) -> WebColor { WebColor::RBGA { r, g, b, a } } - - /// Converts a string to a color, if possible: - /// - /// ``` - ///# use rpg_tools_rendering::renderer::color::WebColor; - /// assert_eq!(WebColor::convert("#FFA500").unwrap(), WebColor::from_rgb(255, 165, 0)); - /// assert_eq!(WebColor::convert("#FFA50040").unwrap(), WebColor::from_rgba(255, 165, 0, 64)); - /// ``` - pub fn convert(hex_code: &str) -> Option { - if !hex_code.starts_with('#') { - return None; - } else if hex_code.len() != 7 && hex_code.len() != 9 { - return None; - } - - let r: u8 = u8::from_str_radix(&hex_code[1..3], 16).ok()?; - let g: u8 = u8::from_str_radix(&hex_code[3..5], 16).ok()?; - let b: u8 = u8::from_str_radix(&hex_code[5..7], 16).ok()?; - - if hex_code.len() == 7 { - return Some(WebColor::from_rgb(r, g, b)); - } - - let a: u8 = u8::from_str_radix(&hex_code[7..9], 16).ok()?; - - Some(WebColor::from_rgba(r, g, b, a)) - } } impl Display for WebColor { @@ -90,34 +63,3 @@ impl Display for WebColor { } } } - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_from_empty_string() { - assert!(WebColor::convert("").is_none()); - } - - #[test] - fn test_from_string_invalid_start() { - assert!(WebColor::convert("FFA500").is_none()); - } - - #[test] - fn test_from_string_wrong_length() { - assert!(WebColor::convert("#").is_none()); - assert!(WebColor::convert("#FF").is_none()); - assert!(WebColor::convert("#FFA5").is_none()); - assert!(WebColor::convert("#FFA50").is_none()); - assert!(WebColor::convert("#FFA500FFA5").is_none()); - } - - #[test] - fn test_from_string_ignore_case() { - let orange = WebColor::from_rgb(255, 165, 0); - assert_eq!(WebColor::convert("#FFA500").unwrap(), orange); - assert_eq!(WebColor::convert("#ffa500").unwrap(), orange); - } -} diff --git a/rpg_tools_rendering/src/renderer/svg/mod.rs b/rpg_tools_rendering/src/renderer/svg/mod.rs index 7948cac9..f7116590 100644 --- a/rpg_tools_rendering/src/renderer/svg/mod.rs +++ b/rpg_tools_rendering/src/renderer/svg/mod.rs @@ -204,12 +204,12 @@ fn to_color(color: &WebColor, text: &str) -> String { match color { WebColor::Transparent(name, transparency) => { let opacity = 1.0 - (*transparency as f32 / 255.0); - return format!( + format!( "{0}:{1};{0}-opacity:{2}", text, name.to_lowercase(), opacity - ); + ) } _ => format!("{}:{}", text, color.to_string().to_lowercase()), }