palette/okhsl/
alpha.rs
1use crate::hues::OklabHue;
2use crate::{angle::FromAngle, stimulus::FromStimulus, Alpha};
3
4use super::Okhsl;
5
6pub type Okhsla<T = f32> = Alpha<Okhsl<T>, T>;
8
9impl<T, A> Alpha<Okhsl<T>, A> {
11 pub fn new<H: Into<OklabHue<T>>>(hue: H, saturation: T, lightness: T, alpha: A) -> Self {
13 Alpha {
14 color: Okhsl::new(hue, saturation, lightness),
15 alpha,
16 }
17 }
18
19 pub const fn new_const(hue: OklabHue<T>, saturation: T, lightness: T, alpha: A) -> Self {
22 Alpha {
23 color: Okhsl::new_const(hue, saturation, lightness),
24 alpha,
25 }
26 }
27
28 pub fn into_format<U, B>(self) -> Alpha<Okhsl<U>, B>
30 where
31 U: FromStimulus<T> + FromAngle<T>,
32 B: FromStimulus<A>,
33 {
34 Alpha {
35 color: self.color.into_format(),
36 alpha: B::from_stimulus(self.alpha),
37 }
38 }
39
40 pub fn from_format<U, B>(color: Alpha<Okhsl<U>, B>) -> Self
42 where
43 T: FromStimulus<U> + FromAngle<U>,
44 A: FromStimulus<B>,
45 {
46 color.into_format()
47 }
48
49 pub fn into_components(self) -> (OklabHue<T>, T, T, A) {
51 (
52 self.color.hue,
53 self.color.saturation,
54 self.color.lightness,
55 self.alpha,
56 )
57 }
58
59 pub fn from_components<H: Into<OklabHue<T>>>(
61 (hue, saturation, lightness, alpha): (H, T, T, A),
62 ) -> Self {
63 Self::new(hue, saturation, lightness, alpha)
64 }
65}