LavaUI docs

enum FocusManager

Swift

enum FocusManager

Which node currently receives keyboard input.

Focus is keyed by NodeID rather than by a view value, because the view struct is rebuilt every frame while the node persists — the same reason @State storage lives on the node side.

Per window (state lives on WindowScope), which is both what the OS does and what users expect: clicking into another window and back leaves the field you were editing still focused. A single process-wide focus would also mean a key event delivered to one window reaching a field in another.

Sources/LavaUI/Focus.swift:13

Properties

static var focusedID: NodeID? { get }

Not documented.

Sources/LavaUI/Focus.swift:14

Methods

static func clear()

Not documented.

Sources/LavaUI/Focus.swift:37

static func focus(_ id: NodeID, onKey: @escaping (KeyEvent) -> Bool, onChar: @escaping (Character) -> Bool)

Not documented.

Sources/LavaUI/Focus.swift:20

@discardableResult static func handle(_ event: KeyEvent) -> Bool

Routes a key to the focused node. Returns true if it was consumed, so the app can fall through to global shortcuts otherwise.

Sources/LavaUI/Focus.swift:78

@discardableResult static func handle(character: Character) -> Bool

Not documented.

Sources/LavaUI/Focus.swift:85

static func isActive(_ id: NodeID) -> Bool

Whether id receives keys right now, either by holding focus or by being the default while nothing does. What a caret should be drawn on.

Sources/LavaUI/Focus.swift:70

static func isFocused(_ id: NodeID) -> Bool

Not documented.

Sources/LavaUI/Focus.swift:16

static func resignFocus(_ id: NodeID)

Not documented.

Sources/LavaUI/Focus.swift:32

static func setDefault(_ id: NodeID, onKey: @escaping (KeyEvent) -> Bool, onChar: @escaping (Character) -> Bool)

Declares where keys go when nothing is focused.

For a window whose whole purpose is one keyboard target — a terminal, a game, a full-window editor. Focus is a click-driven idea, and it is the right one where a window holds several things worth typing into; applied to a window holding exactly one, it produces an application that ignores the keyboard until you have told it which of its one thing you meant.

A fallback rather than a permanent claim, so anything that genuinely wants focus — a find bar, a rename prompt — still takes it and gives it back on its own terms. Nothing here overrides focus.

Sources/LavaUI/Focus.swift:57