wplot/
color.rs

1/// Internal namespace.
2pub( crate ) mod private
3{
4  use crate::protected::*;
5  use num_traits::{ Zero }; /* zzz : consider as submodule for wtools */
6
7  /// Convertable into RGBA.
8  pub trait RgbaInterface< T >
9  where
10    T : Zero + fmt::Debug + Clone + Copy,
11  {
12    /// Convert into RGBA.
13    fn into_rgba( self ) -> Rgba< T >;
14  }
15
16  // zzz : use type_constructor::Enumberable for indexed access to color components
17
18  /// RGBA
19  #[ derive( Debug, Clone ) ]
20  pub struct Rgba< T = f32 >
21  where
22    T : Zero + fmt::Debug + Clone + Copy,
23  {
24    /// Red.
25    pub r : T,
26    /// Green.
27    pub g : T,
28    /// Blue.
29    pub b : T,
30    /// Alpha.
31    pub a : T,
32  }
33
34  impl< T > Default for Rgba< T >
35  where
36    T : Zero + fmt::Debug + Clone + Copy,
37  {
38    fn default() -> Self
39    {
40      Self
41      {
42        r : Zero::zero(),
43        g : Zero::zero(),
44        b : Zero::zero(),
45        a : Zero::zero(),
46      }
47    }
48  }
49
50  impl< T > RgbaInterface< T > for Rgba< T >
51  where
52    T : Zero + fmt::Debug + Clone + Copy,
53  {
54    fn into_rgba( self ) -> Rgba< T >
55    {
56      self
57    }
58  }
59
60  impl RgbaInterface< f32 >
61  for [ f32 ; 3 ]
62  {
63    fn into_rgba( self ) -> Rgba< f32 >
64    {
65      Rgba::< f32 >
66      {
67        r : self[ 0 ],
68        g : self[ 1 ],
69        b : self[ 2 ],
70        a : 1.0,
71      }
72    }
73  }
74
75  impl RgbaInterface< f32 >
76  for [ f32 ; 4 ]
77  {
78    fn into_rgba( self ) -> Rgba< f32 >
79    {
80      Rgba::< f32 >
81      {
82        r : self[ 0 ],
83        g : self[ 1 ],
84        b : self[ 2 ],
85        a : self[ 3 ],
86      }
87    }
88  }
89
90}
91
92crate::mod_interface!
93{
94
95  protected use ::rgb::*;
96
97  #[ cfg( feature = "use_std" ) ]
98  exposed use Rgba;
99
100  #[ cfg( feature = "use_std" ) ]
101  prelude use RgbaInterface;
102
103}