LavaUI docs GitHub

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)

Creates a gradient. The default angle runs top to bottom.

Sources/LavaUI/Gradient.swift:24

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:21

var from: Color

The colour at the start of the ramp.

Sources/LavaUI/Gradient.swift:14

var to: Color

The colour at the end of the ramp.

Sources/LavaUI/Gradient.swift:16

Methods

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

Left to right.

Sources/LavaUI/Gradient.swift:36

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

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

Sources/LavaUI/Gradient.swift:31