loom & weft
Made for Swift.

Published release 0.2.1. Unreleased PR #2 reference.

LOOM 0.2.1 / RENDERING AND LAYOUT

Widget

Implement render(in:buffer:) to paint into the assigned rectangle. Keep writes clipped to both that rectangle and buffer.area. Widgets do not own terminal sessions, input handling, timers, or app state. Use Buffer.put for safe whole-grapheme writes.

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

struct Marker: Widget {
    func render(in area: Rect, buffer: inout Buffer) {
        guard area.width > 0, area.height > 0 else { return }
        buffer.put("*", width: 1, at: Point(x: area.x, y: area.y))
    }
}
var frame = Frame(width: 10, height: 2)
frame.render(Marker(), in: frame.area)
Members on this page

Feature guides and release status

Widget

Protocol
protocol Widget

A value that draws its content into an assigned region of a buffer.

Source · Widget.swift:4

render(in:buffer:)

Instance Method
func render(in area: Rect, buffer: inout Buffer)

Renders within the supplied area without writing directly to the terminal.

Parameters (2)
in
Argument type and any default are shown in the declaration; see the behavior notes above.
buffer
Mutable destination cell grid.
Source · Widget.swift:7