Struct Caret
Where a caret is drawn: the primary segment, and at a bidi boundary, where the position touches text of both directions, a secondary segment at the other text's edge.
public readonly record struct Caret : IEquatable<Caret>
- 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
Caret(CaretLine, CaretLine?)
Where a caret is drawn: the primary segment, and at a bidi boundary, where the position touches text of both directions, a secondary segment at the other text's edge.
public Caret(CaretLine Primary, CaretLine? Secondary)
Parameters
PrimaryCaretLineThe caret for the position's affinity.
SecondaryCaretLine?The caret at the other visual edge, or null.
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
Primary
The caret for the position's affinity.
public CaretLine Primary { get; init; }
Property Value
Secondary
The caret at the other visual edge, or null.
public CaretLine? Secondary { get; init; }