plotters_unsable/style/
mod.rs

1/*!
2  The style for shapes and text, font, color, etc.
3*/
4mod color;
5mod font;
6mod palette;
7use std::borrow::Borrow;
8
9pub use color::{
10    Black, Blue, Color, Cyan, Green, HSLColor, Magenta, Mixable, PaletteColor, RGBColor, Red,
11    SimpleColor, Transparent, White, Yellow,
12};
13
14pub use font::{FontDesc, FontError, FontResult, FontTransform, IntoFont, LayoutBox};
15pub use palette::*;
16
17/// Style of a text
18#[derive(Clone)]
19pub struct TextStyle<'a> {
20    pub font: &'a FontDesc<'a>,
21    pub color: &'a dyn Color,
22}
23
24impl<'a> TextStyle<'a> {
25    /// Determine the color of the style
26    pub fn color<C: Color>(&self, color: &'a C) -> Self {
27        Self {
28            font: self.font,
29            color,
30        }
31    }
32}
33
34/// Make sure that we are able to automatically copy the `TextStyle`
35impl<'a, 'b: 'a> Into<TextStyle<'a>> for &'b TextStyle<'a> {
36    fn into(self) -> TextStyle<'a> {
37        self.clone()
38    }
39}
40
41impl<'a, T: Borrow<FontDesc<'a>>> From<&'a T> for TextStyle<'a> {
42    fn from(font: &'a T) -> Self {
43        Self {
44            font: font.borrow(),
45            color: &Black,
46        }
47    }
48}
49
50/// Style for any of shape
51#[derive(Clone)]
52pub struct ShapeStyle<'a> {
53    pub color: &'a dyn Color,
54    pub filled: bool,
55}
56
57impl<'a> ShapeStyle<'a> {
58    /// Make a filled shape style
59    pub fn filled(&self) -> Self {
60        Self {
61            color: self.color,
62            filled: true,
63        }
64    }
65}
66
67impl<'a, T: Color> From<&'a T> for ShapeStyle<'a> {
68    fn from(f: &'a T) -> Self {
69        ShapeStyle {
70            color: f,
71            filled: false,
72        }
73    }
74}