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_VALUEvar validatedColor = ValidatedColor(255, 128, 0, 255)//this validated color allows opaque colors onlyvar validatedColorOpaque = ValidatedColor(0, 128, 255)//this validated color allows opaque colors onlyvar validatedColorSimple = ValidatedColor()//Validated color built from a java Color. This color will not allow transparencyvar 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 = 255int colorInt = myColor.toInt(); //int = 16744448String 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, 0MutableColor mutable = holder.mutable(); //create a MutableColor instancemutable.updateRGB(0, 128, 255); //mutate!myColor.accept(mutable.createHolder()); //ValidatedFields are consumers of their held type. consume a new holder created from the mutable.