---
title: Validated Colors
---

Fzzy Config provides three utilities for creating and validating colors:
* [ValidatedColor 🗗](https://fzzyhmstrs.github.io/fconfig/-fzzy%20-config/me.fzzyhmstrs.fzzy_config.validation.misc/-validated-color/index.html)
* [ColorHolder 🗗](https://fzzyhmstrs.github.io/fconfig/-fzzy%20-config/me.fzzyhmstrs.fzzy_config.validation.misc/-validated-color/-color-holder/index.html)
* [MutableColor 🗗](https://fzzyhmstrs.github.io/fconfig/-fzzy%20-config/me.fzzyhmstrs.fzzy_config.validation.misc/-validated-color/-mutable-color/index.html)

## ValidatedColor
The core of a color setting. It validates `ColorHolder` and is edited via `MutableColor`, which both support ARGB colors.

### Creating

<CodeTabs>

```kotlin !!tabs Kotlin
//example validated color. defined with standard integer RGBA color components [0-225]
//this example has transparency enabled. To allow only opaque colors, use the RGB overload or input Int.MIN_VALUE
var validatedColor = ValidatedColor(255, 128, 0, 255)

//this validated color allows opaque colors only
var validatedColorOpaque = ValidatedColor(0, 128, 255)

//this validated color allows opaque colors only
var validatedColorSimple = ValidatedColor()

//Validated color built from a java Color. This color will not allow transparency
var validatedColorColor = ValidatedColor(Color(1f,0.5f,0f), false)

//kotlin extension function. validated color built from a hex string, with transparency enabled.
var validatedColorString = "D6FF00AA".validatedColor(true)
```

```java !!tabs Java
//example validated color. defined with standard integer RGBA color components [0-225]
//this example has transparency enabled. To allow only opaque colors, use the RGB overload or input Int.MIN_VALUE
public ValidatedColor validatedColor = new ValidatedColor(255, 128, 0, 255);

//this validated color allows opaque colors only
public ValidatedColor validatedColorOpaque = new ValidatedColor(0, 128, 255);

//this validated color allows opaque colors only
public ValidatedColor validatedColorSimple = new ValidatedColor();

//Validated color built from a java Color. This color will not allow transparency
public ValidatedColor validatedColorColor = new ValidatedColor(new Color(1f, 0.5f, 0f), false);
```

</CodeTabs>

### Using
Validated Colors can supply colors as components, an int, or a hex string.

<CodeTabs>

```java !!tabs Java
public ValidatedColor myColor = new ValidatedColor(255, 128, 0, 255);
int colorRed = myColor.r(); //component = 255
int colorInt = myColor.toInt(); //int = 16744448
String colorHex = myColor.hexString(); //hex string = "FF8000"
```

```kotlin !!tabs Kotlin
var myColor = ValidatedColor(255, 128, 0, 255)
val colorRed = myColor.r() //component = 255
val colorInt = myColor.toInt() //int = 16744448
val colorHex = myColor.hexString() //hex string = "FF8000"
```

</CodeTabs>

## ColorHolder
`ColorHolder` is an immutable ARGB color instance. It is the container that `ValidatedColor` wraps and serializes.

To update a `ValidatedColor` with new values, pass a new ColorHolder into it. The process for this is below in `MutableColor`.

Get the holder via `ValidatedColor.get()`. You typically won't need to do this directly, see above.

## MutableColor
`MutableColor` is a mutable ARGB color instance. They are used to mutate a `ColorHolder`.

`MutableColor` supports updates via RGB, HSL, or hex string.

Update a `ValidatedColor` in-code with the below process. Usually the color will be updated externally via GUI or the .toml file.

<CodeTabs>

```java !!tabs Java
ValidatedColor myColor = new ValidatedColor(255, 128, 0, 255);

ColorHolder holder = myColor.get(); // the old holder, rgb 255, 128, 0
MutableColor mutable = holder.mutable(); //create a MutableColor instance
mutable.updateRGB(0, 128, 255); //mutate!
myColor.accept(mutable.createHolder()); //ValidatedFields are consumers of their held type. consume a new holder created from the mutable.
```

```kotlin !!tabs Kotlin
var myColor = ValidatedColor(255, 128, 0, 255)

val holder = myColor.get() // the old holder, rgb 255, 128, 0
val mutable = holder.mutable() //create a MutableColor instance
mutable.updateRGB(0, 128, 255) //mutate!
myColor.accept(mutable.createHolder()) //ValidatedFields are consumers of their held type. consume a new holder created from the mutable.
```

</CodeTabs>