LavaUI docs GitHub

struct Text

Swift

struct Text

Text label primitive — Phase 4: Yoga measure via canvas::Font + layout cache.

Sources/LavaUI/Text.swift:2

Constructors

init(_ string: String, color: Color = .primary, font: UIFont? = nil, hoverFill: Color? = nil, hoverColor: Color? = nil, cornerRadius: Float = 0, lineLimit: Int? = nil, align: Alignment = .topLeading, onClick: (() -> Void)? = nil)

Creates a text label.

A text with an onClick gets the theme's hover fill unless it is given one (or a hoverColor).

Sources/LavaUI/Text.swift:51

Properties

var align: Alignment

Where the glyphs sit when the node is wider than they are.

A label that states its own width — .frame(width:), a grid cell, a stack that stretches it — is a box with room left over, and until this existed the text was always jammed against the leading edge of it. The only way to centre one was .frame(width:alignment:), which is a different thing entirely: it wraps the text in a box it does not own, and that box is where the width, the background, the hover fill and the cursor then land, while onClick stays on the text inside. The control ends up hovering at one size and clicking at another.

So this is deliberately not a layout property. It moves the pen inside a node that already exists, and adds no node — which is what keeps a centred label the same click target as a leading one.

Both axes, and the same Alignment the frame takes, so moving a call site across is the same word in a different place. The default is .topLeading rather than .center, because top-leading is where a text's glyphs have always gone and every existing caller is drawn against that.

Sources/LavaUI/Text.swift:45

var color: Color

Colour of the glyphs.

Sources/LavaUI/Text.swift:6

var cornerRadius: Float

Corner radius of the hover fill, in points.

Sources/LavaUI/Text.swift:21

var dumpDetail: String { get }

Not documented.

Sources/LavaUI/Text.swift:78

var font: UIFont?

nil → FontStore.default (global UI face).

Sources/LavaUI/Text.swift:8

var hoverColor: Color?

Text colour meant for when the pointer is over the text.

Setting it makes the text a hover target and drops the default hover fill a clickable text gets; the glyphs themselves are not yet recoloured.

Sources/LavaUI/Text.swift:19

var hoverFill: Color?

Row highlight under the pointer. Defaults to the theme's hover surface for clickable text, since an unclickable label highlighting on hover would be lying about being interactive.

Sources/LavaUI/Text.swift:14

var lineLimit: Int?

Most lines shown before the text is cut off with an ellipsis, or nil for no limit. Values below 1 are treated as 1.

Sources/LavaUI/Text.swift:24

var onClick: (() -> Void)?

Closures break value equality (SwiftUI wart) — fine until Phase 5 skip-recompute.

Sources/LavaUI/Text.swift:10

var resolvedFont: UIFont? { get }

Resolved face for measure (explicit or environment default).

Sources/LavaUI/Text.swift:76

var string: String

The text shown. \n starts a new line.

Sources/LavaUI/Text.swift:4

Methods

func lineLimit(_ limit: Int?) -> Text

Limits wrapped rows and truncates the final visible row with an ellipsis when additional content exists.

Sources/LavaUI/Text.swift:159

func mountPrimitive() -> any AnyViewNode

Not documented.

Sources/LavaUI/Text.swift:84

func reconcilePrimitive(_ node: any AnyViewNode) -> any AnyViewNode

Not documented.

Sources/LavaUI/Text.swift:105