LavaUI docs

struct Gradient

Swift

struct Gradient

A two-stop linear ramp, for .background(_:).

Two stops rather than an arbitrary list, and linear rather than radial, because that is what the renderer evaluates exactly: the ramp is computed per vertex and interpolated across the quad, and a two-stop linear gradient is the one family that survives that without error. Multi-stop and radial would need the ramp evaluated per fragment, which is a different pipeline rather than a longer array here.

Both stops carry their own alpha, so a fade to transparent is an ordinary gradient with to: .clear rather than a separate mechanism.

Sources/LavaUI/Gradient.swift:12

Constructors

init(from: Color, to: Color, angle: Float = .pi / 2)

Not documented.

Sources/LavaUI/Gradient.swift:21

Properties

var angle: Float

Radians, from +x towards +y: 0 runs left to right, .pi / 2 top to bottom. The ramp spans the box exactly whatever the angle and whatever the aspect ratio, so a 45° gradient looks like 45° on a wide box rather than being sheared by it.

Sources/LavaUI/Gradient.swift:19

var from: Color

Not documented.

Sources/LavaUI/Gradient.swift:13

var to: Color

Not documented.

Sources/LavaUI/Gradient.swift:14

Methods

static func horizontal(_ from: Color, _ to: Color) -> Gradient

Left to right.

Sources/LavaUI/Gradient.swift:33

static func vertical(_ from: Color, _ to: Color) -> Gradient

Top to bottom — the direction nearly every panel and header wants.

Sources/LavaUI/Gradient.swift:28