MutableColor

A mutable color that automatically updates it's RGB and HSL values based on new inputs. Generally this should be created from a ColorHolder, not instantiated directly

Author

fzzyhmstrs

Since

0.2.0

Parameters

hex

ValidatedString - defines the correction used on the hex string internally.

alphaMode
  • whether this classes parent supports transparency or not, passes this on to any new holders it creates

Samples

import me.fzzyhmstrs.fzzy_config.util.AllowableIdentifiers
import me.fzzyhmstrs.fzzy_config.util.EnumTranslatable
import me.fzzyhmstrs.fzzy_config.util.FcText.lit
import me.fzzyhmstrs.fzzy_config.util.ValidationResult
import me.fzzyhmstrs.fzzy_config.validation.collection.ValidatedList
import me.fzzyhmstrs.fzzy_config.validation.minecraft.ValidatedIdentifier
import me.fzzyhmstrs.fzzy_config.validation.minecraft.ValidatedRegistryType
import me.fzzyhmstrs.fzzy_config.validation.minecraft.ValidatedTagKey
import me.fzzyhmstrs.fzzy_config.validation.misc.*
import me.fzzyhmstrs.fzzy_config.validation.misc.ValidatedColor.Companion.validatedColor
import me.fzzyhmstrs.fzzy_config.validation.number.ValidatedInt
import net.minecraft.item.AxeItem
import net.minecraft.item.Items
import net.minecraft.registry.Registries
import net.minecraft.registry.tag.ItemTags
import net.minecraft.util.Identifier
import java.awt.Color
import java.util.function.Function

fun main() { 
   //sampleStart 
   //generate a color holder from a ValidatedColor wrapper
val validatedColor: ValidatedColor = ValidatedColor(255, 128, 0, 255)

// the wrapped ColorHolder
val holder: ValidatedColor.ColorHolder = validatedColor.get()

//we can get color values from it
val r: Int = holder.r //255
val g: Int = holder.g //128
val argb: Int = holder.argb()

//color holders are immutable, we can mutate them via a MutableColor though
val mutable: ValidatedColor.MutableColor = holder.mutable()

//update the RGB to something new
mutable.updateRGB(128, 0, 128)

//the colors HSL is automatically updated too
val h = mutable.h
val l = mutable.l

// once we are done, we can update our ValidatedColor
validatedColor.validateAndSet(mutable.createHolder()) 
   //sampleEnd
}

Properties

Link copied to clipboard
var a: Int
Link copied to clipboard
var b: Int
Link copied to clipboard
var g: Int
Link copied to clipboard
var h: Float
Link copied to clipboard
Link copied to clipboard
var l: Float
Link copied to clipboard
var r: Int
Link copied to clipboard
var s: Float

Functions

Link copied to clipboard
fun argb(): Int

ARGB color int representation of this color

Link copied to clipboard

Creates a color holder from this color

Link copied to clipboard
fun hexString(prefix: String = ""): String

Hex string representation of this color

Link copied to clipboard
fun updateA(a: Int)

updates this Mutable Color with new Alpha value

Link copied to clipboard
fun updateARGB(argb: Int)

updates this Mutable Color with new ARGB values. HSL and hex values automatically updated to match. If alphamode is false, alpha will be clamped to 255

Link copied to clipboard

Updates this color from a new hex-string color representation. Automatically strips common prefixes, and automatically updates HSL and RGB values

Link copied to clipboard
fun updateHex(new: String)

Updates this color from a new hex-string color representation. Automatically strips common prefixes, and automatically updates HSL and RGB values

Link copied to clipboard
fun updateHSL(h: Float, s: Float, l: Float)

updates this Mutable Color with new HSL values. RGB values automatically updated to match

Link copied to clipboard
fun updateRGB(r: Int, g: Int, b: Int)

updates this Mutable Color with new RGB values. HSL and hex values automatically updated to match