Debian Codegraph @

src/oklch/alpha.rs

raw symbols SCIP
1 use crate::{Alpha, OklabHue};
2
3 use super::Oklch;
4
5 /// Oklch with an alpha component. See the [`Oklcha` implementation in
6 /// `Alpha`](crate::Alpha#Oklcha).
7 pub type Oklcha<T = f32> = Alpha<Oklch<T>, T>;
8
9 ///<span id="Oklcha"></span>[`Oklcha`](crate::Oklcha) implementations.
10 impl<T, A> Alpha<Oklch<T>, A> {
11 /// Create an Oklch color with transparency.
12 pub fn new<H: Into<OklabHue<T>>>(l: T, chroma: T, hue: H, alpha: A) -> Self {
13 Alpha {
14 color: Oklch::new(l, chroma, hue),
15 alpha,
16 }
17 }
18
19 /// Create an `Oklcha` color. This is the same as `Oklcha::new` without the
20 /// generic hue type. It's temporary until `const fn` supports traits.
21 pub const fn new_const(l: T, chroma: T, hue: OklabHue<T>, alpha: A) -> Self {
22 Alpha {
23 color: Oklch::new_const(l, chroma, hue),
24 alpha,
25 }
26 }
27
28 /// Convert to a `(L, C, h, alpha)` tuple.
29 pub fn into_components(self) -> (T, T, OklabHue<T>, A) {
30 (self.color.l, self.color.chroma, self.color.hue, self.alpha)
31 }
32
33 /// Convert from a `(L, C, h, alpha)` tuple.
34 pub fn from_components<H: Into<OklabHue<T>>>((l, chroma, hue, alpha): (T, T, H, A)) -> Self {
35 Self::new(l, chroma, hue, alpha)
36 }
37 }