loom & weft
Made for Swift.

Published release 0.2.1. Unreleased PR #2 reference.

LOOM 0.2.1 / RENDERING AND LAYOUT

Layout

Allocates the supplied constraints along one axis, with insets, explicit gaps/overlap, and a Flex policy for unused space. split returns one rectangle per constraint, including zero-sized rectangles. Optional caller-owned LayoutCache retains complete input/output pairs; uncached split has no global state.

Standard inherited Swift protocol operations such as synthesized equality and OptionSet set operations are not repeated. The public declarations below are extracted from the exact source revision listed in the coverage manifest.

Example

let rows = Layout(.vertical, [.length(1), .fill(1), .length(1)])
    .split(Rect(width: 80, height: 24))
_ = rows[1]
Members on this page

Feature guides and release status

Layout

Structure
struct Layout

Conforms to: Swift.Equatable, Swift.Hashable, Swift.Sendable, Swift.SendableMetatype.

Splits an area into regions in its original constraint order; explicit overlap is opt-in.

Minimum bounds are reserved first, followed by length, percentage, and ratio requests. Equal-priority requests are clipped in source order when the area is too small. Maximum-bounded regions then share excess cells equally until their caps are reached. Weighted fills consume what remains, or minimum-bounded regions grow equally if no positive fill exists. Otherwise unused cells trail the last region.

Source · Layout.swift:61

direction

Instance Property
var direction: Direction

The horizontal or vertical allocation axis.

Source · Layout.swift:62

constraints

Instance Property
var constraints: [Constraint]

Constraints in the order returned by split.

Source · Layout.swift:63

insets

Instance Property
var insets: LayoutInsets

A public field of this type. Its value type and mutability are shown in the declaration.

Source · Layout.swift:64

spacing

Instance Property
var spacing: Int

A public field of this type. Its value type and mutability are shown in the declaration.

Source · Layout.swift:65

flex

Instance Property
var flex: Flex

A public field of this type. Its value type and mutability are shown in the declaration.

Source · Layout.swift:66

overlap

Instance Property
var overlap: Int

A public field of this type. Its value type and mutability are shown in the declaration.

Source · Layout.swift:67

init(_:_:insets:spacing:flex:)

Initializer
init(_ direction: Direction, _ constraints: [Constraint], insets: LayoutInsets = LayoutInsets(), spacing: Int = 0, flex: Flex = .start)

Creates a value with the supplied arguments. Default arguments are shown in the declaration.

Parameters (5)
direction
Argument type and any default are shown in the declaration; see the behavior notes above.
constraints
Argument type and any default are shown in the declaration; see the behavior notes above.
insets
Argument type and any default are shown in the declaration; see the behavior notes above.
spacing
Argument type and any default are shown in the declaration; see the behavior notes above.
flex
Argument type and any default are shown in the declaration; see the behavior notes above.
Source · Layout.swift:69

init(_:_:insets:spacing:flex:)

Initializer
init(_ direction: Direction, _ constraints: [Constraint], insets: LayoutInsets = LayoutInsets(), spacing: LayoutSpacing, flex: Flex = .start)

Explicitly chooses a gap or overlap in terminal cells.

Negative amounts clamp to zero.

Parameters (5)
direction
Argument type and any default are shown in the declaration; see the behavior notes above.
constraints
Argument type and any default are shown in the declaration; see the behavior notes above.
insets
Argument type and any default are shown in the declaration; see the behavior notes above.
spacing
Argument type and any default are shown in the declaration; see the behavior notes above.
flex
Argument type and any default are shown in the declaration; see the behavior notes above.
Source · Layout.swift:83

split(_:cache:)

Instance Method
func split(_ area: Rect, cache: inout LayoutCache) -> [Rect]

Uses only the caller-owned cache; ordinary split calls remain uncached.

Parameters (2)
area
Assigned absolute terminal-cell rectangle.
cache
Argument type and any default are shown in the declaration; see the behavior notes above.

Returns [Rect].

Source · Layout.swift:95

split(_:)

Instance Method
func split(_ area: Rect) -> [Rect]

Returns a region for every constraint, including zero-sized regions.

Parameters (1)
area
Assigned absolute terminal-cell rectangle.

Returns [Rect].

Source · Layout.swift:100