loom & weft
Made for Swift.

Unreleased APIs from PR #2. Not in 0.2.1. Stable 0.2.1 reference.

LOOM Unreleased (PR #2) / WIDGETS

Paragraph

Paints a cached TextLayout. scroll is a row offset into that layout; selection uses layout coordinates. Style supplies the fallback where a glyph has no explicit style. Rebuild layout when text or available width changes.

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 text = TextLayout("One\nTwo\nThree", width: 40)
let paragraph = Paragraph(text, scroll: 1)
var frame = Frame(width: 40, height: 2)
frame.render(paragraph, in: frame.area)
Members on this page

Feature guides and release status

Paragraph

Structure
struct Paragraph

Conforms to: Widget.

A view of cached text layout, with optional scrolling and selection.

Source · Paragraph.swift:4

layout

Instance Property
let layout: TextLayout

The cached text layout to display.

Source · Paragraph.swift:5

scroll

Instance Property
var scroll: Int

Number of layout/document rows skipped above the visible region.

Source · Paragraph.swift:6

selection

Instance Property
var selection: TextSelection?

The current selection; coordinate semantics are defined by the containing type.

Source · Paragraph.swift:7

style

Instance Property
var style: Style

Visual attributes used when painting this value.

Source · Paragraph.swift:8

horizontalScroll

Instance Property
var horizontalScroll: Int

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

Source · Paragraph.swift:9

alignment

Instance Property
var alignment: CellAlignment

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

Source · Paragraph.swift:10

init(_:scroll:selection:style:horizontalScroll:alignment:)

Initializer
init(_ layout: TextLayout, scroll: Int = 0, selection: TextSelection? = nil, style: Style = Style(), horizontalScroll: Int = 0, alignment: CellAlignment = .left)

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

Parameters (6)
layout
Argument type and any default are shown in the declaration; see the behavior notes above.
scroll
Number of document/layout rows skipped above the viewport.
selection
Selection using the containing type’s coordinate convention.
style
Text/cell appearance.
horizontalScroll
Argument type and any default are shown in the declaration; see the behavior notes above.
alignment
Argument type and any default are shown in the declaration; see the behavior notes above.
Source · Paragraph.swift:12

contentPoint(at:in:)

Instance Method
func contentPoint(at point: Point, in area: Rect) -> Point?

Maps terminal cells to the content coordinates accepted by TextSelection.

Parameters (2)
at
Argument type and any default are shown in the declaration; see the behavior notes above.
in
Argument type and any default are shown in the declaration; see the behavior notes above.

Returns Point?.

Source · Paragraph.swift:25

viewportPoint(for:in:)

Instance Method
func viewportPoint(for point: Point, in area: Rect) -> Point?

Maps a layout point into the assigned viewport using the same scroll/alignment geometry as painting.

Parameters (2)
for
Argument type and any default are shown in the declaration; see the behavior notes above.
in
Argument type and any default are shown in the declaration; see the behavior notes above.

Returns Point?.

Source · Paragraph.swift:30

render(in:buffer:)

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

Paints this widget into the assigned terminal-cell rectangle. Application code owns state, input routing, and terminal lifetime.

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