Skip to main content

HSL

Struct HSL 

Source
pub struct HSL {
    pub h: f32,
    pub s: f32,
    pub l: f32,
}
Expand description

HSL color.

FieldRangeDescription
h0..360Hue angle (wraps at 360)
s0..1Saturation
l0..1Lightness

§Why no arithmetic?

Same reasoning as HSV: hue wraparound makes naive componentwise operations incorrect. Convert to RGBA, manipulate there, convert back.

See HSV for details and alternatives.

Fields§

§h: f32§s: f32§l: f32

Implementations§

Source§

impl HSL

Source

pub fn new(h: f32, s: f32, l: f32) -> Self

Construct an HSL color with clamping.

Hue is clamped to 0..360, saturation and lightness to 0..1.

Source

pub fn to_rgba_alpha(self, alpha: f32) -> RGBA

Convert to RGBA with a custom alpha.

Equivalent to self.to_rgba().with_alpha(alpha).

Trait Implementations§

Source§

impl Clone for HSL

Source§

fn clone(&self) -> HSL

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for HSL

Source§

impl Debug for HSL

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<HSL> for RGBA

Source§

fn from(hsl: HSL) -> Self

Converts to this type from the input type.
Source§

impl From<RGBA> for HSL

Source§

fn from(rgba: RGBA) -> Self

Converts to this type from the input type.
Source§

impl FromRgba for HSL

Source§

fn from_rgba(rgba: RGBA) -> Self

Source§

impl ToRgba for HSL

Source§

fn to_rgba(self) -> RGBA

Convert to RGBA.

Auto Trait Implementations§

§

impl Freeze for HSL

§

impl RefUnwindSafe for HSL

§

impl Send for HSL

§

impl Sync for HSL

§

impl Unpin for HSL

§

impl UnsafeUnpin for HSL

§

impl UnwindSafe for HSL

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> ColorInfo for T
where T: ToRgba,

Source§

fn luminance(self) -> f32

Relative luminance per ITU-R BT.709. Read more
Source§

fn is_light(self) -> bool

Returns true if the luminance is greater than 0.5.
Source§

fn contrast_ratio(self, other: impl ToRgba) -> f32

Compute the WCAG contrast ratio against another color. Read more
Source§

fn to_hex(self) -> String

Encode as a hex string: #RRGGBBAA.
Source§

fn to_bytes(self) -> (u8, u8, u8, u8)

Convert to 8-bit byte channels: (r, g, b, a) in 0..255.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.