Unreleased APIs from PR #2. Not in 0.2.1. Stable 0.2.1 reference.
LOOM Unreleased (PR #2) / 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
struct SelectionState<ID> where ID : HashableConforms 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:6selectedID
var selectedID: ID? { get }A public field of this type. Its value type and mutability are shown in the declaration.
Source · SelectionState.swift:7markedIDs
var markedIDs: Set<ID> { get }A public field of this type. Its value type and mutability are shown in the declaration.
Source · SelectionState.swift:8scroll
var scroll: ScrollStateNumber of layout/document rows skipped above the visible region.
Source · SelectionState.swift:9revealPadding
var revealPadding: IntPreferred terminal rows around a selection, clamped to fit the viewport.
Source · SelectionState.swift:11ids
var ids: [ID] { get }A public field of this type. Its value type and mutability are shown in the declaration.
Source · SelectionState.swift:12selectedIndex
var selectedIndex: Int? { get }Caller-selected zero-based item index.
Source · SelectionState.swift:17init(selectedID:)
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.
update(ids:heights:viewportLength:reversed:)
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.
select(_:)
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.
moveSelection(by:)
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.
selectFirst()
mutating func selectFirst()Selects the first item in screen order; reversed lists use the opposite data end.
Source · SelectionState.swift:71selectLast()
mutating func selectLast()Selects the last item in screen order; reversed lists use the opposite data end.
Source · SelectionState.swift:72pageSelection(by:)
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.
toggleMarked(_:)
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.
markAll()
mutating func markAll()Marks every ID in the current synchronized data set.
Source · SelectionState.swift:94clearMarks()
mutating func clearMarks()Clears all marked IDs while retaining selection.
Source · SelectionState.swift:95revealSelection()
mutating func revealSelection()Reveals the selected item extent using current measured rows and revealPadding.
Source · SelectionState.swift:97rowRange(at:)
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>.
index(atRow:)
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?.
visibleIndices
var visibleIndices: Range<Int> { get }A public field of this type. Its value type and mutability are shown in the declaration.
Source · SelectionState.swift:120handle(_:allowsMultipleSelection:)
@discardableResult mutating func handle(_ event: InputEvent, allowsMultipleSelection: Bool = false) -> BoolOptional 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.