# Color

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

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

```rust
struct Color
```

An ARGB color.

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

## Members

- [`a`](#struct_field-a)
- [`r`](#struct_field-r)
- [`g`](#struct_field-g)
- [`b`](#struct_field-b)
- [`new`](#function-new)
- [`from_argb`](#function-from_argb)
- [`from_rgb`](#function-from_rgb)
- [`from_uint32`](#function-from_uint32)
- [`parse`](#function-parse)
- [`try_parse`](#function-try_parse)
- [`to_string_format`](#function-to_string_format)
- [`to_uint32`](#function-to_uint32)
- [`to_hsl`](#function-to_hsl)
- [`to_hsv`](#function-to_hsv)
- [`equals`](#function-equals)
- [`rgb_to_hsl`](#function-rgb_to_hsl)
- [`normalized_rgb_to_hsl`](#function-normalized_rgb_to_hsl)
- [`rgb_to_hsv`](#function-rgb_to_hsv)
- [`normalized_rgb_to_hsv`](#function-normalized_rgb_to_hsv)

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

### a

```rust
a: u8
```

The Alpha component of the color.

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

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

### r

```rust
r: u8
```

The Red component of the color.

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

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

### g

```rust
g: u8
```

The Green component of the color.

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

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

### b

```rust
b: u8
```

The Blue component of the color.

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

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

### new

```rust
const fn new(a: u8, r: u8, g: u8, b: u8) -> Self
```

Initializes a new instance of the `Color` struct.

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

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

### from_argb

```rust
const fn from_argb(a: u8, r: u8, g: u8, b: u8) -> Color
```

Creates a `Color` from alpha, red, green and blue components.

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

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

### from_rgb

```rust
const fn from_rgb(r: u8, g: u8, b: u8) -> Color
```

Creates an opaque `Color` from red, green and blue components.

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

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

### from_uint32

```rust
const fn from_uint32(value: u32) -> Color
```

Creates a `Color` from an integer in `0xAARRGGBB` layout.

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

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

### parse

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

Parses a color string: `#rgb`, `#argb`, `#rrggbb`, `#aarrggbb`,
`rgb()`/`rgba()`, `hsl()`/`hsla()`, `hsv()`/`hsva()` or a known color name.

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

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

### try_parse

```rust
fn try_parse(s: &str) -> Option<Color>
```

Parses a color string, returning `None` when it is not a valid color.

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

<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:
- `X`: XAML hex with alpha, `#AARRGGBB`
- `x`: hex without alpha, `#RRGGBB`
- `H`: HTML/CSS hex with alpha, `#RRGGBBAA`
- `R` / `r`: CSS `rgba(r, g, b, a)` / `rgb(r, g, b)`
- `R%` / `r%`: CSS `rgba(r%, g%, b%, a%)` / `rgb(r%, g%, b%)`
- `L`, `l`, `L%`, `l%`: converted to HSL 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/color.rs#L298)

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

### to_uint32

```rust
const fn to_uint32(self: &Self) -> u32
```

Returns the integer representation of the color in `0xAARRGGBB` layout.

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

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

### to_hsl

```rust
fn to_hsl(self: &Self) -> HslColor
```

Returns the HSL color model equivalent of this RGB color.

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

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

### to_hsv

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

Returns the HSV color model equivalent of this RGB color.

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

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

### equals

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

Check if two colors are equal.

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

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

### rgb_to_hsl

```rust
fn rgb_to_hsl(red: u8, green: u8, blue: u8, alpha: u8) -> HslColor
```

Converts the given RGBA color component values to their HSL color equivalent.

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

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

### normalized_rgb_to_hsl

```rust
fn normalized_rgb_to_hsl(r: f64, g: f64, b: f64, a: f64) -> HslColor
```

Converts the given RGBA color component values to their HSL color equivalent.
Warning: no bounds checks or clamping is done on the input component values;
they are assumed to be within the 0..1 range. The result is not clamped either.

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

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

### rgb_to_hsv

```rust
fn rgb_to_hsv(red: u8, green: u8, blue: u8, alpha: u8) -> HsvColor
```

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

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

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

### normalized_rgb_to_hsv

```rust
fn normalized_rgb_to_hsv(r: f64, g: f64, b: f64, a: f64) -> HsvColor
```

Converts the given RGBA color component values to their HSV color equivalent.
Warning: no bounds checks or clamping is done on the input component values;
they are assumed to be within the 0..1 range. The result is not clamped either.

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

## Trait implementations

- `Send`
- `Sync`
- `Freeze`
- `UnsafeUnpin`
- `Unpin`
- `UnwindSafe`
- `RefUnwindSafe`
- [`ResourceKeyObject`](/docs/0.5.0/api/ferroui-base/controls/trait-resourcekeyobject/)
- [`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`
- [`Transition<Color>`](/docs/0.5.0/api/ferroui-base/animation/trait-transition/)
- `Clone`
- `Copy`
- `Debug`
- `StructuralPartialEq`
- `PartialEq`
- `Eq`
- `Hash`
- `Default`
- `FromStr`
- `Display`
- `From<HslColor>`
- `From<HsvColor>`
- `From<Color>`
- `IInterpolator<Color>`
- `ExpressionVariantValue`
- `ServerPropertyValue`
- `BatchValue`
- [`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/).
