struct ShapedRun
Swift
struct ShapedRun
A shaped line plus the two mappings text editing needs.
Both directions go through HarfBuzz cluster values (byte offsets into the source string), because shaping is not one-glyph-per-character: a ligature is several characters and one glyph, a combining mark is one glyph with no advance of its own. Any attempt to guess caret positions from character counts falls apart on the first "ffi" or accented vowel.
Because this is built from the same Font::shape call that measurement
uses, hit-testing and drawing agree by construction — the invariant
font.hpp exists to protect, extended to the caret.
Sources/LavaUI/ShapedRun.swift:15
Constructors
init(text: String, glyphs: [ShapedGlyph])
Not documented.
Sources/LavaUI/ShapedRun.swift:25
Properties
var characterAdvances: [Float] { get }
One advance per Character, which is what SoftWrap consumes.
Glyphs are not characters: a ligature is one glyph spanning several, and a combining mark is a glyph with no advance of its own. Summing by cluster is what keeps the two aligned.
Sources/LavaUI/ShapedRun.swift:88
let glyphs: [ShapedGlyph]
Not documented.
Sources/LavaUI/ShapedRun.swift:17
let text: String
Not documented.
Sources/LavaUI/ShapedRun.swift:16
var width: Float { get }
Total advance — where the caret sits at end of line.
Sources/LavaUI/ShapedRun.swift:42
Methods
func caretX(for index: String.Index) -> Float
X of the caret for index, relative to the run origin.
Sources/LavaUI/ShapedRun.swift:49
func index(atX x: Float) -> String.Index
Nearest cursor position to x, snapped to a grapheme boundary.
Sources/LavaUI/ShapedRun.swift:66