TextHit Struct

The character of a TextLayout a point is on, or the nearest one: what TextLayout.HitTest finds.

public readonly struct TextHit : IEquatable<TextHit>

Remarks

A character is what a reader takes for one: a letter with its marks, an emoji sequence (a grapheme cluster). Its leading edge is where it starts in the direction of its text: its left in a left-to-right text, its right in a right-to-left one.

Implements

Properties

NameDescription
CaretIndexGets the position in the text a caret takes when the point is clicked: before the character, or after it when the point is nearer to its end. It is an index TextLayout.GetCaretRectangle accepts.
IsInsideGets a value indicating whether the point is on the character: false for a point above, below or beside the text, which gives the nearest character.
IsTrailingGets a value indicating whether the point is nearer to the end of the character than to its start, in the direction of its text.
LengthGets the number of UTF-16 code units of the character: 0 on a line that has no character.
LineIndexGets the index of the line the point is on, or of the nearest line, in TextLayout.Lines.
TextIndexGets the index in the text of the first UTF-16 code unit of the character.

CaretIndex

TextHit.cs

Gets the position in the text a caret takes when the point is clicked: before the character, or after it when the point is nearer to its end. It is an index TextLayout.GetCaretRectangle accepts.

public int CaretIndex { get; }

Property value

int

IsInside

TextHit.cs

Gets a value indicating whether the point is on the character: false for a point above, below or beside the text, which gives the nearest character.

public bool IsInside { get; }

Property value

bool

IsTrailing

TextHit.cs

Gets a value indicating whether the point is nearer to the end of the character than to its start, in the direction of its text.

public bool IsTrailing { get; }

Property value

bool

Gets the number of UTF-16 code units of the character: 0 on a line that has no character.

public int Length { get; }

Property value

int

LineIndex

TextHit.cs

Gets the index of the line the point is on, or of the nearest line, in TextLayout.Lines.

public int LineIndex { get; }

Property value

int

TextIndex

TextHit.cs

Gets the index in the text of the first UTF-16 code unit of the character.

public int TextIndex { get; }

Property value

int

Methods

NameDescription
Equals(TextHit)Indicates whether the current object is equal to another object of the same type.
Equals(object?)Indicates whether this instance and a specified object are equal.
GetHashCode()Returns the hash code for this instance.
ToString()Returns the line, the character and the side of the hit.

Equals overloads

Equals(TextHit)

TextHit.cs

Indicates whether the current object is equal to another object of the same type.

public bool Equals(TextHit other)
Parameters
other TextHit
An object to compare with this object.
Returns

bool true if the current object is equal to the other parameter; otherwise, false.

Equals(object?)

TextHit.cs

Indicates whether this instance and a specified object are equal.

public override bool Equals(object? obj)
Parameters
obj object?
The object to compare with the current instance.
Returns

bool true if obj and this instance are the same type and represent the same value; otherwise, false.

GetHashCode()

TextHit.cs

Returns the hash code for this instance.

public override int GetHashCode()

Returns

int A 32-bit signed integer that is the hash code for this instance.

ToString()

TextHit.cs

Returns the line, the character and the side of the hit.

public override string ToString()

Returns

string A culture-invariant string.

Operators

NameDescription
operator ==(TextHit, TextHit)Compares two hits for equality.
operator !=(TextHit, TextHit)Compares two hits for inequality.

operator ==(TextHit, TextHit)

TextHit.cs

Compares two hits for equality.

public static bool operator ==(TextHit left, TextHit right)

Parameters

left TextHit
The first hit.
right TextHit
The second hit.

Returns

bool true if every value is equal; otherwise false.

operator !=(TextHit, TextHit)

TextHit.cs

Compares two hits for inequality.

public static bool operator !=(TextHit left, TextHit right)

Parameters

left TextHit
The first hit.
right TextHit
The second hit.

Returns

bool true if a value differs; otherwise false.