loom & weft
Made for Swift.

Published release 0.2.1. Unreleased PR #2 reference.

LOOM 0.2.1 / COLLECTIONS AND INTERACTION

SelectionState

Stable single selection, optional marked items, and vertical scrolling for lists and tables.

IDs must be unique. Synchronizing a filtered data set preserves surviving IDs and removes hidden marks. If the selected ID disappears, selection moves to the nearest surviving index. No item is selected automatically when selection was nil.

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.

Members on this page

Feature guides and release status

SelectionState

Structure
struct SelectionState<ID> where ID : Hashable

Conforms to: Swift.Sendable, Swift.SendableMetatype.

Stable single selection, optional marked items, and vertical scrolling for lists and tables.

IDs must be unique. Synchronizing a filtered data set preserves surviving IDs and removes hidden marks. If the selected ID disappears, selection moves to the nearest surviving index. No item is selected automatically when selection was nil.

Source · SelectionState.swift:6

selectedID

Instance Property
var selectedID: ID? { get }

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

Source · SelectionState.swift:7

markedIDs

Instance Property
var markedIDs: Set<ID> { get }

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

Source · SelectionState.swift:8

scroll

Instance Property
var scroll: ScrollState

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

Source · SelectionState.swift:9

revealPadding

Instance Property
var revealPadding: Int

Preferred terminal rows around a selection, clamped to fit the viewport.

Source · SelectionState.swift:11

ids

Instance Property
var ids: [ID] { get }

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

Source · SelectionState.swift:12

selectedIndex

Instance Property
var selectedIndex: Int? { get }

Caller-selected zero-based item index.

Source · SelectionState.swift:17

init(selectedID:)

Initializer
init(selectedID: ID? = nil)

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

Parameters (1)
selectedID
Argument type and any default are shown in the declaration; see the behavior notes above.
Source · SelectionState.swift:19

update(ids:heights:viewportLength:reversed:)

Instance Method
mutating func update(ids: [ID], heights: [Int], viewportLength: Int, reversed: Bool = false)

Updates row geometry in terminal rows.

Row heights are at least one. Call after data or geometry changes, before dispatching events. Stateful widgets also call this when drawing. An unchanged draw does not pull a manually scrolled view back.

Parameters (4)
ids
Argument type and any default are shown in the declaration; see the behavior notes above.
heights
Argument type and any default are shown in the declaration; see the behavior notes above.
viewportLength
Argument type and any default are shown in the declaration; see the behavior notes above.
reversed
Argument type and any default are shown in the declaration; see the behavior notes above.
Source · SelectionState.swift:27

select(_:)

Instance Method
mutating func select(_ id: ID?)

Selects an existing stable ID or clears selection with nil, then reveals it using current metrics.

Parameters (1)
id
Stable entry/icon identity, not an array index.
Source · SelectionState.swift:54

moveSelection(by:)

Instance Method
mutating func moveSelection(by distance: Int)

Moves by signed selection steps in screen direction, including reversed-list geometry, and reveals the result.

Parameters (1)
by
Argument type and any default are shown in the declaration; see the behavior notes above.
Source · SelectionState.swift:60

selectFirst()

Instance Method
mutating func selectFirst()

Selects the first item in screen order; reversed lists use the opposite data end.

Source · SelectionState.swift:71

selectLast()

Instance Method
mutating func selectLast()

Selects the last item in screen order; reversed lists use the opposite data end.

Source · SelectionState.swift:72

pageSelection(by:)

Instance Method
mutating func pageSelection(by pages: Int)

Moves selection by a viewport of rows, including variable-height items.

Parameters (1)
by
Argument type and any default are shown in the declaration; see the behavior notes above.
Source · SelectionState.swift:75

toggleMarked(_:)

Instance Method
mutating func toggleMarked(_ id: ID)

Toggles one visible, valid stable ID in the marked set.

Parameters (1)
id
Stable entry/icon identity, not an array index.
Source · SelectionState.swift:89

markAll()

Instance Method
mutating func markAll()

Marks every ID in the current synchronized data set.

Source · SelectionState.swift:94

clearMarks()

Instance Method
mutating func clearMarks()

Clears all marked IDs while retaining selection.

Source · SelectionState.swift:95

revealSelection()

Instance Method
mutating func revealSelection()

Reveals the selected item extent using current measured rows and revealPadding.

Source · SelectionState.swift:97

rowRange(at:)

Instance Method
func rowRange(at index: Int) -> Range<Int>

Content rows occupied by an item; the index must belong to ids.

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

Returns Range<Int>.

Source · SelectionState.swift:102

index(atRow:)

Instance Method
func index(atRow row: Int) -> Int?

Finds the item under a content row using the same geometry as rendering.

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

Returns Int?.

Source · SelectionState.swift:108

visibleIndices

Instance Property
var visibleIndices: Range<Int> { get }

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

Source · SelectionState.swift:120

handle(_:allowsMultipleSelection:)

Instance Method
@discardableResult mutating func handle(_ event: InputEvent, allowsMultipleSelection: Bool = false) -> Bool

Optional default keys; Space toggles marks only when explicitly enabled.

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

Returns Bool.

Source · SelectionState.swift:129