Record Class TextFacet

java.lang.Object
java.lang.Record
limn.accessibility.TextFacet
Record Components:
text - the whole text, already masked where it is masked; never null
caretOffset - where the caret sits
caretAffinity - which side of caretOffset the caret is on
selectionStart - where the selection begins, equal to selectionEnd when there is none
selectionEnd - where it ends
lineCount - how many lines the text has, counting a trailing empty one
caretRect - the caret's rectangle in the window's coordinates, the space the node's own box is published in, transforms above it applied (the box that holds the turned caret); null when the node has no caret to draw

public record TextFacet(String text, int caretOffset, ShapedText.Affinity caretAffinity, int selectionStart, int selectionEnd, int lineCount, @Nullable Rect caretRect) extends Record
A node that holds text a user can read, and usually edit: a text field, a text area, a search field, a password field.

Every offset here is a UTF-16 code unit. The unit is stated once, in this sentence, because the three platforms disagree — one counts UTF-16, one counts characters — and a model that left it implicit produces silently wrong carets in emoji and in the CJK extensions. UTF-16 is chosen because it is what the toolkit's own editing model counts in and what one of the three platforms wants unchanged; the bridge that needs characters converts at that one boundary and nowhere else.

A caret is not an index. An offset on a direction boundary is two points on the line, so the caret carries its affinity as well as its offset. A bridge drops the affinity only where its platform has nowhere to put it.

A masked field publishes the mask. A password field that is not revealed puts one mask character per caret stop here and never its own text, and its caret and selection offsets are offsets into that string: the secret's own offsets would run past the end of a mask that is shorter by an astral character.

  • Constructor Details

    • TextFacet

      public TextFacet(String text, int caretOffset, ShapedText.Affinity caretAffinity, int selectionStart, int selectionEnd, int lineCount, @Nullable Rect caretRect)
      Creates an instance of a TextFacet record class.
      Parameters:
      text - the value for the text record component
      caretOffset - the value for the caretOffset record component
      caretAffinity - the value for the caretAffinity record component
      selectionStart - the value for the selectionStart record component
      selectionEnd - the value for the selectionEnd record component
      lineCount - the value for the lineCount record component
      caretRect - the value for the caretRect record component
  • Method Details

    • hasSelection

      public boolean hasSelection()
      Returns:
      whether any text is selected
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • text

      public String text()
      Returns the value of the text record component.
      Returns:
      the value of the text record component
    • caretOffset

      public int caretOffset()
      Returns the value of the caretOffset record component.
      Returns:
      the value of the caretOffset record component
    • caretAffinity

      public ShapedText.Affinity caretAffinity()
      Returns the value of the caretAffinity record component.
      Returns:
      the value of the caretAffinity record component
    • selectionStart

      public int selectionStart()
      Returns the value of the selectionStart record component.
      Returns:
      the value of the selectionStart record component
    • selectionEnd

      public int selectionEnd()
      Returns the value of the selectionEnd record component.
      Returns:
      the value of the selectionEnd record component
    • lineCount

      public int lineCount()
      Returns the value of the lineCount record component.
      Returns:
      the value of the lineCount record component
    • caretRect

      public @Nullable Rect caretRect()
      Returns the value of the caretRect record component.
      Returns:
      the value of the caretRect record component