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: f64The Alpha (transparency) component in the range from 0..1 (percentage). 0 is fully transparent, 1 is fully opaque.
h: f64The 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: f64The Saturation component in the range from 0..1 (percentage). HSL saturation is not the same as HSV saturation.
l: f64The Lightness component in the range from 0..1 (percentage). 0 is fully black and 1 is fully white.
Implementations§
Source§impl HslColor
impl HslColor
Sourcepub fn new(alpha: f64, hue: f64, saturation: f64, lightness: f64) -> Self
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.
Sourcepub fn new_with_clamp(
alpha: f64,
hue: f64,
saturation: f64,
lightness: f64,
clamp_values: bool,
) -> Self
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.
Sourcepub fn from_color(color: Color) -> Self
pub fn from_color(color: Color) -> Self
Initializes a new instance of the HslColor struct from an RGB color.
pub fn equals(&self, other: HslColor) -> bool
Sourcepub fn to_string_format(
&self,
format: Option<&str>,
format_provider: Option<&CultureInfo>,
) -> Result<String, FormatError>
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: 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.
Sourcepub fn parse(s: &str) -> Result<HslColor, FormatError>
pub fn parse(s: &str) -> Result<HslColor, FormatError>
Parses an HSL color string (hsl(h, s, l) or hsla(h, s, l, a)).
Sourcepub fn try_parse(s: &str) -> Option<HslColor>
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.
Sourcepub fn from_ahsl(a: f64, h: f64, s: f64, l: f64) -> HslColor
pub fn from_ahsl(a: f64, h: f64, s: f64, l: f64) -> HslColor
Creates an HslColor from alpha, hue, saturation and lightness (clamped).
Sourcepub fn from_hsl(h: f64, s: f64, l: f64) -> HslColor
pub fn from_hsl(h: f64, s: f64, l: f64) -> HslColor
Creates an opaque HslColor from hue, saturation and lightness (clamped).
Trait Implementations§
impl Copy for HslColor
Source§impl From<HslColor> for Color
Converts the HSL color to RGB (an explicit conversion in the reference API).
impl From<HslColor> for Color
Converts the HSL color to RGB (an explicit conversion in the reference API).
Source§impl MarkupTyped for HslColor
impl MarkupTyped for HslColor
Source§const MARKUP: &'static MarkupType
const MARKUP: &'static MarkupType
impl StructuralPartialEq for HslColor
Auto Trait Implementations§
impl Freeze for HslColor
impl RefUnwindSafe for HslColor
impl Send for HslColor
impl Sync for HslColor
impl Unpin for HslColor
impl UnsafeUnpin for HslColor
impl UnwindSafe for HslColor
Blanket Implementations§
Source§impl<T> AnyValue for Twhere
T: PartialEq + 'static,
impl<T> AnyValue for Twhere
T: PartialEq + 'static,
fn any_value_as_any(&self) -> &(dyn Any + 'static)
fn any_value_eq(&self, other: &(dyn AnyValue + 'static)) -> bool
fn any_value_type_name(&self) -> &'static str
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> ClassDefaults for Twhere
T: ?Sized,
impl<T> ClassDefaults for Twhere
T: ?Sized,
Source§fn static_constructor()
fn static_constructor()
affects_render, metadata
overrides). Read more