Fzzy Config provides several utilities for creating and validating colors. Colors are handled in three pieces:
ValidatedColor
The core of a color setting. It validates instances of ColorHolder
, which 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, a color integer, or a hex string.
public ValidatedColor myColor = new ValidatedColor(255, 128, 0, 255);int colorRed = myColor.r(); //255int colorInt = myColor.toInt(); //16744448String colorHex = myColor.hexString(); //"FF8000"
ColorHolder
ColorHolder
is an Immutable ARGB color representation. It is the container that ValidatedColor
wraps and serializes.
To update a ValidatedColor
with new values requires passing a new ColorHolder into it. The general process for this is described below in MutableColor
Get the holder via ValidatedColor.get()
MutableColor
MutableColor
, as the name implies, are mutable ARGB color representations. They are used to mutate a ValidatedColor via ColorHolders
.
MutableColor
supports updating of colors via RGB, HSL, or hex string.
To update a ValidatedColor
internally, the following process can be followed. Generally 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.