1 use super::color::{Color, RGBAColor}; 2 use plotters_backend::{BackendColor, BackendStyle}; 3 4 /// Style for any of shape 5 #[derive(Clone)] 6 pub struct ShapeStyle { 7 pub color: RGBAColor, 8 pub filled: bool, 9 pub stroke_width: u32, 10 } 11 12 impl ShapeStyle { 13 /// Make a filled shape style filled(&self) -> Self14 pub fn filled(&self) -> Self { 15 Self { 16 color: self.color.to_rgba(), 17 filled: true, 18 stroke_width: self.stroke_width, 19 } 20 } 21 stroke_width(&self, width: u32) -> Self22 pub fn stroke_width(&self, width: u32) -> Self { 23 Self { 24 color: self.color.to_rgba(), 25 filled: self.filled, 26 stroke_width: width, 27 } 28 } 29 } 30 31 impl<T: Color> From<T> for ShapeStyle { from(f: T) -> Self32 fn from(f: T) -> Self { 33 ShapeStyle { 34 color: f.to_rgba(), 35 filled: false, 36 stroke_width: 1, 37 } 38 } 39 } 40 41 impl BackendStyle for ShapeStyle { color(&self) -> BackendColor42 fn color(&self) -> BackendColor { 43 self.color.to_backend_color() 44 } stroke_width(&self) -> u3245 fn stroke_width(&self) -> u32 { 46 self.stroke_width 47 } 48 } 49