enum CaretBlink
Swift
enum CaretBlink
Caret blink, expressed as a phase rather than a timer.
The plan called for deciding this deliberately rather than drifting into it: a blinking caret dirties a frame twice a second forever, which is the one thing that defeats idle frame-gating. The compromise here is to blink only while focused, and to hold the caret solid for a moment after any edit so it never blinks mid-typing.
The phase is a pure function of the clock, so it is shared; what is per
window (WindowScope.caretLastPhase) is the last phase this window
drew, since two windows both showing a caret would otherwise consume each
other's flips and one of them would stop blinking.
Sources/LavaUI/Focus.swift:167
Properties
static var isVisible: Bool { get }
Whether the caret should be drawn right now.
Sources/LavaUI/Focus.swift:180
static let period: Double
One full blink, in seconds: shown for the first half, hidden for the second.
Sources/LavaUI/Focus.swift:169
Methods
static func noteEdit()
Records an edit, which holds the caret solid for half a second so it is visible while typing.
Sources/LavaUI/Focus.swift:174
static func phaseChanged() -> Bool
Call once per frame while a field is focused: reports whether the blink phase flipped, which is the only reason an idle app needs to redraw.
Sources/LavaUI/Focus.swift:189
static func resync()
Adopts the current phase without reporting a change. The blink is
suspended while the window is invisible, so lastPhase is stale by an
arbitrary number of periods on restore; the caller redraws once anyway
and only wants the next phaseChanged() to be meaningful.
Sources/LavaUI/Focus.swift:200