HslColor
struct · ferroui-base · v0.5.0
struct HslColor
Defines a color using the hue/saturation/lightness (HSL) model. This uses a cylindrical-coordinate representation of a color.
Members
ahslnewnew_with_clampfrom_colorequalsto_rgbto_hsvto_string_formatparsetry_parsefrom_ahslfrom_hslhsl_to_rgbhsl_to_hsv
a
a: f64
The Alpha (transparency) component in the range from 0..1 (percentage). 0 is fully transparent, 1 is fully opaque.
h
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
s: f64
The Saturation component in the range from 0..1 (percentage). HSL saturation is not the same as HSV saturation.
l
l: f64
The Lightness component in the range from 0..1 (percentage). 0 is fully black and 1 is fully white.
new
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.
new_with_clamp
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.
from_color
fn from_color(color: Color) -> Self
Initializes a new instance of the HslColor struct from an RGB color.
equals
fn equals(self: &Self, other: HslColor) -> bool
to_rgb
fn to_rgb(self: &Self) -> Color
Returns the RGB color model equivalent of this HSL color.
to_hsv
fn to_hsv(self: &Self) -> HsvColor
Returns the HSV color model equivalent of this HSL color.
to_string_format
fn to_string_format(self: &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: CSShsla(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 suchV,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.
parse
fn parse(s: &str) -> Result<HslColor, FormatError>
Parses an HSL color string (hsl(h, s, l) or hsla(h, s, l, a)).
try_parse
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.
from_ahsl
fn from_ahsl(a: f64, h: f64, s: f64, l: f64) -> HslColor
Creates an HslColor from alpha, hue, saturation and lightness (clamped).
from_hsl
fn from_hsl(h: f64, s: f64, l: f64) -> HslColor
Creates an opaque HslColor from hue, saturation and lightness (clamped).
hsl_to_rgb
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.
hsl_to_hsv
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
SendSyncFreezeUnsafeUnpinUnpinUnwindSafeRefUnwindSafePropertyValueAnyValueClassDefaultsBorrow<T>BorrowMut<T>CloneToUninitInto<U>From<T>TryInto<U>TryFrom<U>AnyToOwnedToStringErasedDestructorIntoEitherCloneCopyDebugStructuralPartialEqPartialEqDefaultFrom<HslColor>FromStrDisplayMarkupTypedValueTypeRegistration
Availability
Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.