1 //! Basic predefined colors.
2 use super::{RGBAColor, RGBColor};
3 
4 // Taken from https://stackoverflow.com/questions/60905060/prevent-line-break-in-doc-test
5 /// Macro for allowing dynamic creation of doc attributes.
6 #[macro_export]
7 macro_rules! doc {
8     {
9         $(#[$m:meta])*
10         $(
11             [$doc:expr]
12             $(#[$n:meta])*
13         )*
14         @ $thing:item
15     } => {
16         $(#[$m])*
17         $(
18             #[doc = $doc]
19             $(#[$n])*
20         )*
21         $thing
22     }
23 }
24 
25 /// Defines and names a color based on its R, G, B, A values.
26 #[macro_export]
27 macro_rules! define_color {
28     ($name:ident, $r:expr, $g:expr, $b:expr, $doc:expr) => {
29         doc! {
30         [$doc]
31         // Format a colored box that will show up in the docs
32         [concat!("(<span style='color: rgb(",  $r,",", $g, ",", $b, "); background-color: #ddd; padding: 0 0.2em;'>■</span>" )]
33         [concat!("*rgb = (", $r,", ", $g, ", ", $b, ")*)")]
34         @pub const $name: RGBColor = RGBColor($r, $g, $b);
35         }
36     };
37 
38     ($name:ident, $r:expr, $g:expr, $b:expr, $a: expr, $doc:expr) => {
39         doc! {
40         [$doc]
41         // Format a colored box that will show up in the docs
42         [concat!("(<span style='color: rgba(",  $r,",", $g, ",", $b, ",", $a, "); background-color: #ddd; padding: 0 0.2em;'>■</span>" )]
43         [concat!("*rgba = (", $r,", ", $g, ", ", $b, ", ", $a, ")*)")]
44         @pub const $name: RGBAColor = RGBAColor($r, $g, $b, $a);
45         }
46     };
47 }
48 
49 define_color!(WHITE, 255, 255, 255, "White");
50 define_color!(BLACK, 0, 0, 0, "Black");
51 define_color!(RED, 255, 0, 0, "Red");
52 define_color!(GREEN, 0, 255, 0, "Green");
53 define_color!(BLUE, 0, 0, 255, "Blue");
54 define_color!(YELLOW, 255, 255, 0, "Yellow");
55 define_color!(CYAN, 0, 255, 255, "Cyan");
56 define_color!(MAGENTA, 255, 0, 255, "Magenta");
57 define_color!(TRANSPARENT, 0, 0, 0, 0.0, "Transparent");
58 
59 #[cfg(feature = "colormaps")]
60 /// Colormaps can be used to simply go from a scalar value to a color value which will be more/less
61 /// intense corresponding to the value of the supplied scalar.
62 /// These colormaps can also be defined by the user and be used with lower and upper bounds.
63 pub mod colormaps;
64 #[cfg(feature = "full_palette")]
65 pub mod full_palette;
66