loom & weft
Made for Swift.

Published release 0.2.1. Unreleased PR #2 reference.

LOOM 0.2.1 / COLLECTIONS AND INTERACTION

FocusState

Application-owned focus traversal, hit testing, and nested modal scopes.

Only the top scope participates in traversal or mouse focus. Pop a scope to restore the previous focus. The caller still decides how to open/close dialogs and routes events to focusedID; no event loop or action dispatch is owned by this type.

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

FocusState

Structure
struct FocusState<ID> where ID : Hashable

Conforms to: Swift.Sendable, Swift.SendableMetatype.

Application-owned focus traversal, hit testing, and nested modal scopes.

Only the top scope participates in traversal or mouse focus. Pop a scope to restore the previous focus. The caller still decides how to open/close dialogs and routes events to focusedID; no event loop or action dispatch is owned by this type.

Source · FocusState.swift:19

wraps

Instance Property
var wraps: Bool

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

Source · FocusState.swift:26

focusedID

Instance Property
var focusedID: ID? { get }

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

Source · FocusState.swift:27

scopeDepth

Instance Property
var scopeDepth: Int { get }

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

Source · FocusState.swift:28

init(_:focusedID:)

Initializer
init(_ targets: [FocusTarget<ID>] = [], focusedID: ID? = nil)

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

Parameters (2)
targets
Argument type and any default are shown in the declaration; see the behavior notes above.
focusedID
Argument type and any default are shown in the declaration; see the behavior notes above.
Source · FocusState.swift:30

update(_:)

Instance Method
mutating func update(_ targets: [FocusTarget<ID>])

Reconciles the active scope after layout/data changes, skipping disabled targets.

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

focus(_:)

Instance Method
@discardableResult mutating func focus(_ id: ID) -> Bool

Focuses an enabled target in the current scope and returns whether a matching target exists.

Parameters (1)
id
Stable entry/icon identity, not an array index.

Returns Bool.

Source · FocusState.swift:46

moveForward()

Instance Method
mutating func moveForward()

Moves to the next enabled target in the active scope, respecting wraps.

Source · FocusState.swift:53

moveBackward()

Instance Method
mutating func moveBackward()

Moves to the previous enabled target in the active scope, respecting wraps.

Source · FocusState.swift:54

pushScope(_:focusedID:)

Instance Method
mutating func pushScope(_ targets: [FocusTarget<ID>], focusedID: ID? = nil)

Adds a nested set of focus targets, preserving the previous scope for restoration when popped.

Parameters (2)
targets
Argument type and any default are shown in the declaration; see the behavior notes above.
focusedID
Argument type and any default are shown in the declaration; see the behavior notes above.
Source · FocusState.swift:56

popScope()

Instance Method
@discardableResult mutating func popScope() -> Bool

Returns false at the root scope, which is never removed.

Returns Bool.

Source · FocusState.swift:63

handle(_:)

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

Handles Tab, Shift-Tab, or a mouse press.

Dispatch a press to the newly focused control too.

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

Returns Bool.

Source · FocusState.swift:73