Small ARGB color math helpers (the library never depends on a framework color type).

Static methods

staticinlinealphaOf(color:Int):Float

Extracts the alpha channel.

Parameters:

color

the ARGB color

Returns:

alpha as 0..1

staticinlinecontrastText(background:Int):Int

A readable, opaque text color for content sitting on background: near-white on dark fills, near-black on light ones (so accent/danger surfaces stay legible under any theme).

Parameters:

background

the background ARGB color

Returns:

an opaque ARGB text color

staticinlinedarken(color:Int, amount:Float):Int

Blends a color toward black, keeping its alpha.

Parameters:

color

the ARGB color

amount

blend amount 0..1

Returns:

the darkened ARGB color

@:value({ alpha : 255 })staticinlinefromRGB(red:Int, green:Int, blue:Int, alpha:Int = 255):Int

Builds an ARGB colour from 0..255 channels.

Parameters:

red

red 0..255

green

green 0..255

blue

blue 0..255

alpha

alpha 0..255 (default opaque)

Returns:

the packed 0xAARRGGBB colour

@:value({ alpha : 1.0 })statichsl(hue:Float, saturation:Float, lightness:Float, alpha:Float = 1.0):Int

Builds an ARGB colour from HSL.

Parameters:

hue

hue in degrees (wraps; any value)

saturation

saturation 0..1

lightness

lightness 0..1

alpha

opacity 0..1 (default opaque)

Returns:

the packed 0xAARRGGBB colour

@:value({ alpha : 1.0 })statichsv(hue:Float, saturation:Float, value:Float, alpha:Float = 1.0):Int

Builds an ARGB colour from HSV.

Parameters:

hue

hue in degrees (wraps; any value)

saturation

saturation 0..1

value

value/brightness 0..1

alpha

opacity 0..1 (default opaque)

Returns:

the packed 0xAARRGGBB colour

staticinlinelighten(color:Int, amount:Float):Int

Blends a color toward white.

Parameters:

color

the ARGB color

amount

blend amount 0..1

Returns:

the lightened ARGB color

staticinlineluminance(color:Int):Float

Perceived brightness of a color (ignores alpha).

Parameters:

color

the ARGB color

Returns:

luminance 0 (black) .. 1 (white)

staticmix(from:Int, to:Int, amount:Float):Int

Linear blend between two ARGB colors.

Parameters:

from

the start color (0xAARRGGBB)

to

the end color

amount

blend amount, 0 (all from) .. 1 (all to)

Returns:

the interpolated ARGB color

staticinlineopaque(rgb:Int):Int

Forces a colour opaque, keeping its RGB. Use on a plain 6-digit hex literal (0xRRGGBB), whose alpha byte is 0 — i.e. fully transparent — before passing it anywhere that expects a 0xAARRGGBB value.

Parameters:

rgb

the colour (any alpha; only the low 24 bits are kept)

Returns:

the colour with alpha forced to 0xFF

staticinlinergb(color:Int):Int

Drops the alpha channel, for APIs that take RGB + a separate alpha.

Parameters:

color

the ARGB color

Returns:

the 0xRRGGBB part

statictoHSL(color:Int):{saturation:Float, lightness:Float, hue:Float}

Decomposes an ARGB colour to HSL (alpha ignored).

Parameters:

color

the ARGB colour

Returns:

hue in degrees 0..360, saturation/lightness in 0..1

statictoHSV(color:Int):{value:Float, saturation:Float, hue:Float}

Decomposes an ARGB colour to HSV (alpha ignored).

Parameters:

color

the ARGB colour

Returns:

hue in degrees 0..360, saturation/value in 0..1

staticinlinewithAlpha(color:Int, alpha:Float):Int

Replaces a colour's alpha channel from a 0..1 opacity, keeping its RGB.

Parameters:

color

the ARGB colour

alpha

opacity 0..1

Returns:

the colour with the new alpha