Table of Contents

Struct TextPosition

Namespace
Egami.Fonts.Layout
Assembly
Egami.Fonts.dll

A caret position: a UTF-16 index at a grapheme cluster boundary and the side it belongs to.

public readonly record struct TextPosition : IEquatable<TextPosition>
Implements
Inherited Members

Examples

// A click: the nearest caret position, then where to draw the caret.
TextPosition position = layout.HitTest(new System.Numerics.Vector2(40, 30));
Caret caret = layout.GetCaret(position);
CaretLine bar = caret.Primary;                     // x, top and bottom; Secondary at a bidi boundary

// Arrow keys: logical moves, and line moves that keep the column.
TextPosition right = layout.MoveCaret(position, CaretMove.NextGrapheme);
TextPosition down = layout.MoveCaret(position, CaretMove.LineDown, preferredX: bar.X);

// A selection: rectangles to fill, one per visually contiguous piece on each line.
IReadOnlyList<TextBounds> highlight = layout.GetSelectionRects(position.Index, down.Index);
Egami.Fonts.Unicode.TextSegment word = layout.GetWordBoundary(position.Index); // double-click

Constructors

TextPosition(int, TextAffinity)

A caret position: a UTF-16 index at a grapheme cluster boundary and the side it belongs to.

public TextPosition(int Index, TextAffinity Affinity = TextAffinity.Downstream)

Parameters

Index int

The UTF-16 index, from 0 to the text's length.

Affinity TextAffinity

Which character the position goes with where the index has two places.

Examples

// A click: the nearest caret position, then where to draw the caret.
TextPosition position = layout.HitTest(new System.Numerics.Vector2(40, 30));
Caret caret = layout.GetCaret(position);
CaretLine bar = caret.Primary;                     // x, top and bottom; Secondary at a bidi boundary

// Arrow keys: logical moves, and line moves that keep the column.
TextPosition right = layout.MoveCaret(position, CaretMove.NextGrapheme);
TextPosition down = layout.MoveCaret(position, CaretMove.LineDown, preferredX: bar.X);

// A selection: rectangles to fill, one per visually contiguous piece on each line.
IReadOnlyList<TextBounds> highlight = layout.GetSelectionRects(position.Index, down.Index);
Egami.Fonts.Unicode.TextSegment word = layout.GetWordBoundary(position.Index); // double-click

Properties

Affinity

Which character the position goes with where the index has two places.

public TextAffinity Affinity { get; init; }

Property Value

TextAffinity

Index

The UTF-16 index, from 0 to the text's length.

public int Index { get; init; }

Property Value

int