csscolorparser/
color2.rs

1// Color deprecated methods
2
3use crate::Color;
4
5impl Color {
6    #[deprecated = "Use [new](#method.new) instead."]
7    /// Arguments:
8    ///
9    /// * `r`: Red value [0..1]
10    /// * `g`: Green value [0..1]
11    /// * `b`: Blue value [0..1]
12    pub fn from_rgb(r: f32, g: f32, b: f32) -> Self {
13        Self { r, g, b, a: 1.0 }
14    }
15
16    #[deprecated = "Use [new](#method.new) instead."]
17    /// Arguments:
18    ///
19    /// * `r`: Red value [0..1]
20    /// * `g`: Green value [0..1]
21    /// * `b`: Blue value [0..1]
22    /// * `a`: Alpha value [0..1]
23    pub fn from_rgba(r: f32, g: f32, b: f32, a: f32) -> Self {
24        Self { r, g, b, a }
25    }
26
27    #[deprecated = "Use [from_rgba8](#method.from_rgba8) instead."]
28    /// Arguments:
29    ///
30    /// * `r`: Red value [0..255]
31    /// * `g`: Green value [0..255]
32    /// * `b`: Blue value [0..255]
33    pub fn from_rgb_u8(r: u8, g: u8, b: u8) -> Self {
34        Self {
35            r: r as f32 / 255.0,
36            g: g as f32 / 255.0,
37            b: b as f32 / 255.0,
38            a: 1.0,
39        }
40    }
41
42    #[deprecated = "Use [from_rgba8](#method.from_rgba8) instead."]
43    /// Arguments:
44    ///
45    /// * `r`: Red value [0..255]
46    /// * `g`: Green value [0..255]
47    /// * `b`: Blue value [0..255]
48    /// * `a`: Alpha value [0..255]
49    pub fn from_rgba_u8(r: u8, g: u8, b: u8, a: u8) -> Self {
50        Self {
51            r: r as f32 / 255.0,
52            g: g as f32 / 255.0,
53            b: b as f32 / 255.0,
54            a: a as f32 / 255.0,
55        }
56    }
57
58    #[deprecated = "Use [from_linear_rgba](#method.from_linear_rgba) instead."]
59    /// Arguments:
60    ///
61    /// * `r`: Red value [0..1]
62    /// * `g`: Green value [0..1]
63    /// * `b`: Blue value [0..1]
64    pub fn from_linear_rgb(r: f32, g: f32, b: f32) -> Self {
65        Self::from_linear_rgba(r, g, b, 1.0)
66    }
67
68    #[deprecated = "Use [from_linear_rgba8](#method.from_linear_rgba8) instead."]
69    /// Arguments:
70    ///
71    /// * `r`: Red value [0..255]
72    /// * `g`: Green value [0..255]
73    /// * `b`: Blue value [0..255]
74    pub fn from_linear_rgb_u8(r: u8, g: u8, b: u8) -> Self {
75        Self::from_linear_rgba(r as f32 / 255.0, g as f32 / 255.0, b as f32 / 255.0, 1.0)
76    }
77
78    #[deprecated = "Use [from_linear_rgba8](#method.from_linear_rgba8) instead."]
79    /// Arguments:
80    ///
81    /// * `r`: Red value [0..255]
82    /// * `g`: Green value [0..255]
83    /// * `b`: Blue value [0..255]
84    /// * `a`: Alpha value [0..255]
85    pub fn from_linear_rgba_u8(r: u8, g: u8, b: u8, a: u8) -> Self {
86        Self::from_linear_rgba(
87            r as f32 / 255.0,
88            g as f32 / 255.0,
89            b as f32 / 255.0,
90            a as f32 / 255.0,
91        )
92    }
93
94    #[deprecated = "Use [from_hsva](#method.from_hsva) instead."]
95    /// Arguments:
96    ///
97    /// * `h`: Hue angle [0..360]
98    /// * `s`: Saturation [0..1]
99    /// * `v`: Value [0..1]
100    pub fn from_hsv(h: f32, s: f32, v: f32) -> Self {
101        Self::from_hsva(h, s, v, 1.0)
102    }
103
104    #[deprecated = "Use [from_hsla](#method.from_hsla) instead."]
105    /// Arguments:
106    ///
107    /// * `h`: Hue angle [0..360]
108    /// * `s`: Saturation [0..1]
109    /// * `l`: Lightness [0..1]
110    pub fn from_hsl(h: f32, s: f32, l: f32) -> Self {
111        Self::from_hsla(h, s, l, 1.0)
112    }
113
114    #[deprecated = "Use [from_hwba](#method.from_hwba) instead."]
115    /// Arguments:
116    ///
117    /// * `h`: Hue angle [0..360]
118    /// * `w`: Whiteness [0..1]
119    /// * `b`: Blackness [0..1]
120    pub fn from_hwb(h: f32, w: f32, b: f32) -> Self {
121        Self::from_hwba(h, w, b, 1.0)
122    }
123
124    #[deprecated = "Use [from_oklaba](#method.from_oklaba) instead."]
125    /// Arguments:
126    ///
127    /// * `l`: Perceived lightness
128    /// * `a`: How green/red the color is
129    /// * `b`: How blue/yellow the color is
130    pub fn from_oklab(l: f32, a: f32, b: f32) -> Self {
131        Self::from_oklaba(l, a, b, 1.0)
132    }
133
134    #[cfg(feature = "lab")]
135    #[deprecated = "Use [from_laba](#method.from_laba) instead."]
136    /// Arguments:
137    ///
138    /// * `l`: Lightness
139    /// * `a`: Distance along the `a` axis
140    /// * `b`: Distance along the `b` axis
141    /// * `alpha`: Alpha [0..1]
142    pub fn from_lab(l: f32, a: f32, b: f32, alpha: f32) -> Self {
143        Self::from_laba(l, a, b, alpha)
144    }
145
146    #[cfg(feature = "lab")]
147    #[deprecated = "Use [to_laba](#method.to_laba) instead."]
148    /// Returns: `[l, a, b, alpha]`
149    pub fn to_lab(&self) -> [f32; 4] {
150        self.to_laba()
151    }
152
153    #[cfg(feature = "lab")]
154    #[deprecated = "Use [from_lcha](#method.from_lcha) instead."]
155    /// Arguments:
156    ///
157    /// * `l`: Lightness
158    /// * `c`: Chroma
159    /// * `h`: Hue angle in radians
160    /// * `alpha`: Alpha [0..1]
161    pub fn from_lch(l: f32, c: f32, h: f32, alpha: f32) -> Self {
162        Self::from_lcha(l, c, h, alpha)
163    }
164
165    #[cfg(feature = "lab")]
166    #[deprecated = "Use [to_lcha](#method.to_lcha) instead."]
167    /// Returns: `[l, c, h, alpha]`
168    pub fn to_lch(&self) -> [f32; 4] {
169        self.to_lcha()
170    }
171
172    #[deprecated]
173    /// Returns: `(r, g, b, a)`
174    ///
175    /// * Red, green, blue and alpha in the range [0..1]
176    pub fn rgba(&self) -> (f32, f32, f32, f32) {
177        (self.r, self.g, self.b, self.a)
178    }
179
180    #[deprecated = "Use [to_rgba8](#method.to_rgba8) instead."]
181    /// Returns: `(r, g, b, a)`
182    ///
183    /// * Red, green, blue and alpha in the range [0..255]
184    pub fn rgba_u8(&self) -> (u8, u8, u8, u8) {
185        (
186            (self.r * 255.0).round() as u8,
187            (self.g * 255.0).round() as u8,
188            (self.b * 255.0).round() as u8,
189            (self.a * 255.0).round() as u8,
190        )
191    }
192
193    // --- Since version 0.7.2
194
195    #[deprecated = "Use [to_css_hex](#method.to_css_hex) instead."]
196    /// Get the RGB hexadecimal color string.
197    pub fn to_hex_string(&self) -> String {
198        self.to_css_hex()
199    }
200
201    #[deprecated = "Use [to_css_rgb](#method.to_css_rgb) instead."]
202    /// Get the CSS `rgb()` format string.
203    pub fn to_rgb_string(&self) -> String {
204        self.to_css_rgb()
205    }
206}