LavaUI docs

struct Color

Swift

struct Color

sRGB colour with alpha. Components are what a colour picker shows — Color(r: 0.5, g: 0, b: 0) is #800000, and that is what reaches the screen. Nothing between here and the attachment applies a transfer function: the whole 2D pipeline works on these encoded values. See docs/colour-and-blending.md.

Sources/LavaUI/Color.swift:8

Constructors

init(r: Float, g: Float, b: Float, a: Float = 1)

Not documented.

Sources/LavaUI/Color.swift:14

init(hue: Float, saturation: Float, lightness: Float, alpha: Float = 1)

From hue (turns, 0…1 and wrapping), saturation and lightness.

Here rather than at a call site because the useful thing about HSL is generating a family — a row of tints that vary in hue while holding saturation and lightness fixed, so they read as one set instead of as an argument. Doing that in RGB means picking every member by hand and getting the brightness subtly wrong on the ones near yellow.

lightness is in the same space as r/g/b: authored sRGB, the numbers a colour picker shows.

Sources/LavaUI/Color.swift:140

init(hue: Float, saturation: Float, value: Float, alpha: Float = 1)

From hue (turns, 0…1), saturation and value — the square a colour picker draws. Distinct from hue:saturation:lightness:: value is the brightest channel, so the top-right of the square is the pure hue rather than a pastel, which is what the hand expects to land on.

Same authored sRGB as r/g/b. A picker that used linear components here would disagree with the hex it prints.

Sources/LavaUI/Color.swift:166

init?(hex: String)

Reads #rgb, #rrggbb, #rrggbbaa, with or without the hash. Nil if the string is not one of those — including a half-typed field.

Sources/LavaUI/Color.swift:225

init(rgb24: UInt32, alpha: Float = 1)

Not documented.

Sources/LavaUI/Color.swift:270

Properties

var a: Float

Not documented.

Sources/LavaUI/Color.swift:12

static var accent: Color { get }

Not documented.

Sources/LavaUI/Theme.swift:298

var b: Float

Not documented.

Sources/LavaUI/Color.swift:11

static let clear: Color

Fully transparent — draws nothing at all.

What a conditional background needs for its "neither" case. A row that is highlighted when selected and hovered has to fall back to no fill the rest of the time, and the nearest thing without this is the theme's own background painted over whatever the row actually sits on, which is right until the day something sits behind it.

Sources/LavaUI/Color.swift:28

static var dim: Color { get }

Not documented.

Sources/LavaUI/Theme.swift:301

var g: Float

Not documented.

Sources/LavaUI/Color.swift:10

var hex: String { get }

#rrggbb when opaque, #rrggbbaa otherwise. The bytes a picker and a CSS author share.

Sources/LavaUI/Color.swift:212

var hsv: (hue: Float, saturation: Float, value: Float) { get }

Hue / saturation / value of these authored components.

Hue is undefined (and returned as 0) when the colour is grey. A picker that has to keep the strip still while the user drags through white should remember the last non-zero hue itself.

Sources/LavaUI/Color.swift:190

var linear: Color { get }

This colour with the sRGB curve removed — components proportional to light rather than to perceived brightness.

Needed wherever colours are multiplied rather than merely carried: a light times a surface, a fade times a fill. Doing that arithmetic on authored components is the classic error — it looks like a dimming that is simply too strong, because halving an encoded value takes far more than half the light out. See docs/colour-and-blending.md.

Not what to hand to the renderer: the wire format is authored sRGB and nothing downstream re-encodes. Convert back with fromLinear first. Alpha is a coverage fraction, not light, and is carried through.

Sources/LavaUI/Color.swift:112

var luminance: Float { get }

Perceived brightness, 0…1 (Rec. 601 weights). For deciding whether a foreground drawn on this colour should be light or dark.

Sources/LavaUI/Color.swift:98

static var muted: Color { get }

Not documented.

Sources/LavaUI/Theme.swift:300

static var primary: Color { get }

Not documented.

Sources/LavaUI/Theme.swift:296

var r: Float

Not documented.

Sources/LavaUI/Color.swift:9

var rgb24: UInt32 { get }

Packed 0x00RRGGBB, the compositor wallpaper spelling. Alpha is dropped on the way out and assumed opaque on the way in.

Sources/LavaUI/Color.swift:263

var rgba8: UInt32 { get }

Pack as authored sRGB RGBA8 (R in the low byte). Carried through unchanged — do not pre-linearise here, or the colour arrives dark.

Sources/LavaUI/Color.swift:32

static var secondary: Color { get }

Not documented.

Sources/LavaUI/Theme.swift:297

static var selected: Color { get }

Not documented.

Sources/LavaUI/Theme.swift:299

Methods

static func fromLinear(_ c: Color) -> Color

The inverse of linear: re-applies the sRGB curve, so the result can be packed and sent like any authored colour. Clamps, because lighting arithmetic overshoots and 8-bit packing has nowhere to put it.

Sources/LavaUI/Color.swift:122

func hoverOverlay(over surface: Color, maxAlpha: Float = 0.40) -> Color

Renderer overlay for a hover fill sitting on surface.

hover is a fill colour. The renderer paints this over the whole node, so alpha is capped: past ~0.40 the letters take the hover's hue and a row of light text on a dark chip turns muddy.

Sources/LavaUI/Color.swift:85

static func interpolate(_ from: Color, _ to: Color, _ t: Float) -> Color

Not documented.

Sources/LavaUI/Animation.swift:15

func lightened(_ amount: Float) -> Color

Moves toward white by amount (0…1), keeping alpha.

For deriving a hover or pressed variant from a semantic token, so a control does not have to hard-code a second colour that a theme swap would then fail to update.

Sources/LavaUI/Color.swift:45

func opacity(_ alpha: Float) -> Color

Returns a copy with alpha replaced (0…1). Useful for glass tints on top of .blur().

Sources/LavaUI/Color.swift:92

func overlay(over base: Color) -> Color

Smallest source-over tint that turns a uniform base into this colour.

What the renderer needs for a hover chip: it paints the tint over the node, glyphs included, so the overlay has to carry as little alpha as will still land on self when composited with base.

Sources/LavaUI/Color.swift:59