# HslColor

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-base/media/struct-hslcolor/

**struct** · [`ferroui-base`](/docs/0.5.0/api/ferroui-base/) · v0.5.0

```rust
struct HslColor
```

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

[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/hsl_color.rs#L19)

## Members

- [`a`](#struct_field-a)
- [`h`](#struct_field-h)
- [`s`](#struct_field-s)
- [`l`](#struct_field-l)
- [`new`](#function-new)
- [`new_with_clamp`](#function-new_with_clamp)
- [`from_color`](#function-from_color)
- [`equals`](#function-equals)
- [`to_rgb`](#function-to_rgb)
- [`to_hsv`](#function-to_hsv)
- [`to_string_format`](#function-to_string_format)
- [`parse`](#function-parse)
- [`try_parse`](#function-try_parse)
- [`from_ahsl`](#function-from_ahsl)
- [`from_hsl`](#function-from_hsl)
- [`hsl_to_rgb`](#function-hsl_to_rgb)
- [`hsl_to_hsv`](#function-hsl_to_hsv)

<a id="struct_field-a"></a>

### a

```rust
a: f64
```

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

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/hsl_color.rs#L22)

<a id="struct_field-h"></a>

### h

```rust
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.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/hsl_color.rs#L26)

<a id="struct_field-s"></a>

### s

```rust
s: f64
```

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

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/hsl_color.rs#L29)

<a id="struct_field-l"></a>

### l

```rust
l: f64
```

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

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/hsl_color.rs#L32)

<a id="function-new"></a>

### new

```rust
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](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/hsl_color.rs#L87)

<a id="function-new_with_clamp"></a>

### new_with_clamp

```rust
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](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/hsl_color.rs#L97)

<a id="function-from_color"></a>

### from_color

```rust
fn from_color(color: Color) -> Self
```

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

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/hsl_color.rs#L127)

<a id="function-equals"></a>

### equals

```rust
fn equals(self: &Self, other: HslColor) -> bool
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/hsl_color.rs#L132)

<a id="function-to_rgb"></a>

### to_rgb

```rust
fn to_rgb(self: &Self) -> Color
```

Returns the RGB color model equivalent of this HSL color.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/hsl_color.rs#L138)

<a id="function-to_hsv"></a>

### to_hsv

```rust
fn to_hsv(self: &Self) -> HsvColor
```

Returns the HSV color model equivalent of this HSL color.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/hsl_color.rs#L144)

<a id="function-to_string_format"></a>

### to_string_format

```rust
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`: 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](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/hsl_color.rs#L158)

<a id="function-parse"></a>

### parse

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

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

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/hsl_color.rs#L207)

<a id="function-try_parse"></a>

### try_parse

```rust
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](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/hsl_color.rs#L219)

<a id="function-from_ahsl"></a>

### from_ahsl

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

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

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/hsl_color.rs#L245)

<a id="function-from_hsl"></a>

### from_hsl

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

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

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/hsl_color.rs#L251)

<a id="function-hsl_to_rgb"></a>

### hsl_to_rgb

```rust
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](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/hsl_color.rs#L258)

<a id="function-hsl_to_hsv"></a>

### hsl_to_hsv

```rust
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.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/hsl_color.rs#L312)

## Trait implementations

- `Send`
- `Sync`
- `Freeze`
- `UnsafeUnpin`
- `Unpin`
- `UnwindSafe`
- `RefUnwindSafe`
- [`PropertyValue`](/docs/0.5.0/api/ferroui-base/trait-propertyvalue/)
- [`AnyValue`](/docs/0.5.0/api/ferroui-base/trait-anyvalue/)
- [`ClassDefaults`](/docs/0.5.0/api/ferroui-base/trait-classdefaults/)
- `Borrow<T>`
- `BorrowMut<T>`
- `CloneToUninit`
- `Into<U>`
- `From<T>`
- `TryInto<U>`
- `TryFrom<U>`
- `Any`
- `ToOwned`
- `ToString`
- `ErasedDestructor`
- `IntoEither`
- `Clone`
- `Copy`
- `Debug`
- `StructuralPartialEq`
- `PartialEq`
- `Default`
- `From<HslColor>`
- `FromStr`
- `Display`
- [`MarkupTyped`](/docs/0.5.0/api/ferroui-base/metadata/trait-markuptyped/)
- [`ValueTypeRegistration`](/docs/0.5.0/api/ferroui-base/data/core/trait-valuetyperegistration/)

## Availability

Extracted for `aarch64-apple-darwin`. Cargo features are listed in the [crate index](/docs/0.5.0/api/).
