Skip to main content

HslColor

Struct HslColor 

Source
pub struct HslColor {
    pub a: f64,
    pub h: f64,
    pub s: f64,
    pub l: f64,
}
Expand description

Defines a color using the hue/saturation/lightness (HSL) model. This uses a cylindrical-coordinate representation of a color.

Fields§

§a: f64

The Alpha (transparency) component in the range from 0..1 (percentage). 0 is fully transparent, 1 is fully opaque.

§h: f64

The Hue component in the range from 0..360 (degrees). This is the color’s location, in degrees, on a color wheel/circle from 0 to 360. Note that 360 is equivalent to 0 and will be adjusted automatically.

§s: f64

The Saturation component in the range from 0..1 (percentage). HSL saturation is not the same as HSV saturation.

§l: f64

The Lightness component in the range from 0..1 (percentage). 0 is fully black and 1 is fully white.

Implementations§

Source§

impl HslColor

Source

pub fn new(alpha: f64, hue: f64, saturation: f64, lightness: f64) -> Self

Initializes a new instance of the HslColor struct. Components are clamped to their ranges and a hue of 360 becomes 0.

Source

pub fn new_with_clamp( alpha: f64, hue: f64, saturation: f64, lightness: f64, clamp_values: bool, ) -> Self

Initializes a new instance of the HslColor struct.

This constructor exists only for internal use where performance is critical. Whether or not the channel values are in the correct range must be known: when clamp_values is false the components are stored as given.

Source

pub fn from_color(color: Color) -> Self

Initializes a new instance of the HslColor struct from an RGB color.

Source

pub fn equals(&self, other: HslColor) -> bool

Source

pub fn to_rgb(&self) -> Color

Returns the RGB color model equivalent of this HSL color.

Source

pub fn to_hsv(&self) -> HsvColor

Returns the HSV color model equivalent of this HSL color.

Source

pub fn to_string_format( &self, format: Option<&str>, format_provider: Option<&CultureInfo>, ) -> Result<String, FormatError>

Returns the string representation of the color using a format specifier.

Supported format specifiers:

  • L / l: CSS hsla(h, s%, l%, a) / hsl(h, s%, l%)
  • L% / l%: hsla(h%, s%, l%, a%) / hsl(h%, s%, l%)
  • X, x, H, R, r, R%, r%: converted to RGB and formatted as such
  • V, v, V%, v%: converted to HSV and formatted as such

A null or empty format is the same as to_string(). Any other format is an error. format_provider is ignored: color formatting is culture-invariant.

Source

pub fn parse(s: &str) -> Result<HslColor, FormatError>

Parses an HSL color string (hsl(h, s, l) or hsla(h, s, l, a)).

Source

pub fn try_parse(s: &str) -> Option<HslColor>

Parses an HSL color string (hsl(h, s, l) or hsla(h, s, l, a)), returning None when it is not valid. Saturation, lightness and alpha may be given as fractions or percentages.

Source

pub fn from_ahsl(a: f64, h: f64, s: f64, l: f64) -> HslColor

Creates an HslColor from alpha, hue, saturation and lightness (clamped).

Source

pub fn from_hsl(h: f64, s: f64, l: f64) -> HslColor

Creates an opaque HslColor from hue, saturation and lightness (clamped).

Source

pub fn hsl_to_rgb( hue: f64, saturation: f64, lightness: f64, alpha: f64, ) -> Color

Converts the given HSLA color component values to their RGB color equivalent.

The hue is wrapped into [0, 360); the other components are clamped to 0..1.

Source

pub fn hsl_to_hsv( hue: f64, saturation: f64, lightness: f64, alpha: f64, ) -> HsvColor

Converts the given HSLA color component values to their HSV color equivalent.

Trait Implementations§

Source§

impl Clone for HslColor

Source§

fn clone(&self) -> Self

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 HslColor

Source§

impl Debug for HslColor

Source§

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

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

impl Default for HslColor

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for HslColor

Source§

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

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

impl From<HslColor> for Color

Converts the HSL color to RGB (an explicit conversion in the reference API).

Source§

fn from(hsl_color: HslColor) -> Color

Converts to this type from the input type.
Source§

impl FromStr for HslColor

Source§

type Err = FormatError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, FormatError>

Parses a string s to return a value of this type. Read more
Source§

impl MarkupTyped for HslColor

Source§

const MARKUP: &'static MarkupType

The markup metadata of the type.
Source§

impl PartialEq for HslColor

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for HslColor

Auto Trait Implementations§

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> AnyValue for T
where T: PartialEq + 'static,

Source§

fn any_value_as_any(&self) -> &(dyn Any + 'static)

Source§

fn any_value_eq(&self, other: &(dyn AnyValue + 'static)) -> bool

Source§

fn any_value_type_name(&self) -> &'static str

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> ClassDefaults for T
where T: ?Sized,

Source§

fn static_constructor()

The static constructor of a type: work done once per thread, after the properties of the type are registered and before its first instance exists (class handlers, affects_render, metadata overrides). 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> 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> PropertyValue for T
where T: Clone + PartialEq + 'static,

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.