use crate::render::svglib::{att, att_to_string, Att, SvgElement, ElementType, Shape, Value}; use std::fmt::Display; pub fn circle() -> Circle { Circle::default() } #[derive(Debug, Default, Clone)] pub struct Circle(Vec); impl Circle { pub fn id>(mut self, id: V) -> Self { self.0.push(att("id", id)); self } pub fn cx>(mut self, cx: V) -> Self { self.0.push(att("cx", cx)); self } pub fn cy>(mut self, cy: V) -> Self { self.0.push(att("cy", cy)); self } pub fn r>(mut self, r: V) -> Self { self.0.push(att("r", r)); self } } impl Shape for Circle { fn fill>(mut self, value: V) -> Self { self.0.push(att("fill", value)); self } fn stroke>(mut self, value: V) -> Self { self.0.push(att("stroke", value)); self } fn transform>(mut self, value: V) -> Self { self.0.push(att("transform", value)); self } } impl Display for Circle { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!( f, r#""#, self.0.iter().map(att_to_string).collect::() ) } } impl SvgElement for Circle { fn get_type(&self) -> ElementType { ElementType::Circle } fn atts(&self) -> &[Att] { &self.0 } } #[cfg(test)] mod tests { use super::*; #[test] fn test_circle() { let circle = circle().cx("1em").cy(0).r("10").id("c"); assert_eq!( r#""#, circle.to_string() ) } }