use maud::{Markup, Render, html}; use crate::ui::{UIWidget, color::UIColor}; #[allow(non_snake_case)] pub fn SVG(inner: T) -> SVGWidget { SVGWidget(Box::new(inner), None, None, None) } pub struct SVGWidget( Box, Option>, Option>, Option, ); impl SVGWidget { pub fn fill(mut self, color: C) -> Self { self.1 = Some(Box::new(color)); self } pub fn stroke(mut self, color: C) -> Self { self.2 = Some(Box::new(color)); self } pub fn stroke_width(mut self, width: u32) -> Self { self.3 = Some(width); self } } impl Render for SVGWidget { fn render(&self) -> Markup { self.render_with_class("") } } impl UIWidget for SVGWidget { fn can_inherit(&self) -> bool { false } fn base_class(&self) -> Vec { let mut ret = vec![]; if let Some(fill) = &self.1 { ret.push(format!("fill-{}", fill.color_class())); } if let Some(stroke) = &self.2 { ret.push(format!("stroke-{}", stroke.color_class())); } if let Some(stroke_width) = &self.3 { ret.push(format!("stroke-[{stroke_width}px]")); } ret } fn extended_class(&self) -> Vec { let mut c = self.base_class(); c.extend_from_slice(&self.0.extended_class()); c } fn render_with_class(&self, _: &str) -> Markup { html! { svg class=(self.base_class().join(" ")) { (self.0.as_ref()) } } } }