Fzzy Config

Validated Colors

Fzzy Config provides three utilities for creating and validating colors:

ValidatedColor

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

Creating

//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)

Using

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

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"

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.

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.