plotters/style/
shape.rs

1use super::color::{Color, RGBAColor};
2use plotters_backend::{BackendColor, BackendStyle};
3
4/// Style for any of shape
5#[derive(Clone)]
6pub struct ShapeStyle {
7    pub color: RGBAColor,
8    pub filled: bool,
9    pub stroke_width: u32,
10}
11
12impl ShapeStyle {
13    /// Make a filled shape style
14    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
22    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
31impl<T: Color> From<T> for ShapeStyle {
32    fn from(f: T) -> Self {
33        ShapeStyle {
34            color: f.to_rgba(),
35            filled: false,
36            stroke_width: 1,
37        }
38    }
39}
40
41impl BackendStyle for ShapeStyle {
42    fn color(&self) -> BackendColor {
43        self.color.to_backend_color()
44    }
45    fn stroke_width(&self) -> u32 {
46        self.stroke_width
47    }
48}