Google is committed to advancing racial equity for Black communities. See how.

TextLayoutResult

data class TextLayoutResult
kotlin.Any
   ↳ androidx.ui.text.TextLayoutResult

The data class which holds text layout result.

Summary

Public methods
TextDirection

Get the text direction of the resolved BiDi run that the character at the given offset associated with.

Rect

Returns the bounding box of the character for given character offset.

Rect
getCursorRect(offset: Int)

Returns the rectangle of the cursor area

Float
getHorizontalPosition(offset: Int, usePrimaryDirection: Boolean)

Get the horizontal position for the specified text offset.

Float
getLineBottom(lineIndex: Int)

Returns the bottom y coordinate of the given line.

Int
getLineEnd(lineIndex: Int)

Returns the end offset of the given line, exclusive.

Int

Returns the line number on which the specified text offset appears.

Int
getLineStart(lineIndex: Int)

Returns the end offset of the given line, inclusive.

Float
getLineTop(lineIndex: Int)

Returns the top y coordinate of the given line.

Int

Returns the character offset closest to the given graphical position.

TextDirection

Get the text direction of the paragraph containing the given offset.

Path
getPathForRange(start: Int, end: Int)

Returns path that enclose the given text range.

TextRange

Returns the text range of the word at the given character offset.

Properties
Boolean

Returns true if the text is too tall and couldn't fit with given height.

Boolean

Returns true if the text is too wide and couldn't fit with given width.

Float

The distance from the top to the alphabetic baseline of the first line.

Boolean

Returns true if either vertical overflow or horizontal overflow happens.

Float

The distance from the top to the alphabetic baseline of the last line.

TextLayoutInput

The parameters used for computing this text layout result.

List<Rect?>

Returns a list of bounding boxes that is reserved for TextLayoutInput.placeholders.

IntSize

The amount of space required to paint this text in Int.

Public methods

getBidiRunDirection

fun getBidiRunDirection(offset: Int): TextDirection

Get the text direction of the resolved BiDi run that the character at the given offset associated with.

Parameters
offset: Int a character offset
Return
the direction of the BiDi run of the given character offset.

getBoundingBox

fun getBoundingBox(offset: Int): Rect

Returns the bounding box of the character for given character offset.

Parameters
offset: Int a character offset
Return
a bounding box for the character in pixels.

getCursorRect

fun getCursorRect(offset: Int): Rect

Returns the rectangle of the cursor area

Parameters
offset: Int An character offset of the cursor
Return
a rectangle of cursor region

getHorizontalPosition

fun getHorizontalPosition(
    offset: Int,
    usePrimaryDirection: Boolean
): Float

Get the horizontal position for the specified text offset.

Returns the relative distance from the text starting offset. For example, if the paragraph direction is Left-to-Right, this function returns positive value as a distance from the left-most edge. If the paragraph direction is Right-to-Left, this function returns negative value as a distance from the right-most edge.

usePrimaryDirection argument is taken into account only when the offset is in the BiDi directional transition point. usePrimaryDirection is true means use the primary direction run's coordinate, and use the secondary direction's run's coordinate if false.

Parameters
offset: Int a character offset
usePrimaryDirection: Boolean true for using the primary run's coordinate if the given offset is in the BiDi directional transition point.
Return
the relative distance from the text starting edge.

getLineBottom

fun getLineBottom(lineIndex: Int): Float

Returns the bottom y coordinate of the given line.

Parameters
lineIndex: Int the line number
Return
the line bottom y coordinate

getLineEnd

fun getLineEnd(lineIndex: Int): Int

Returns the end offset of the given line, exclusive.

Parameters
lineIndex: Int the line number
Return
the end offset of the line.

getLineForOffset

fun getLineForOffset(offset: Int): Int

Returns the line number on which the specified text offset appears.

If you ask for a position before 0, you get 0; if you ask for a position beyond the end of the text, you get the last line.

Parameters
offset: Int a character offset
Return
the 0 origin line number.

getLineStart

fun getLineStart(lineIndex: Int): Int

Returns the end offset of the given line, inclusive.

Parameters
lineIndex: Int the line number
Return
the start offset of the line

getLineTop

fun getLineTop(lineIndex: Int): Float

Returns the top y coordinate of the given line.

Parameters
lineIndex: Int the line number
Return
the line top y coordinate

getOffsetForPosition

fun getOffsetForPosition(position: Offset): Int

Returns the character offset closest to the given graphical position.

Parameters
position: Offset a graphical position in this text layout
Return
a character offset that is closest to the given graphical position.

getParagraphDirection

fun getParagraphDirection(offset: Int): TextDirection

Get the text direction of the paragraph containing the given offset.

Parameters
offset: Int a character offset
Return
the paragraph direction

getPathForRange

fun getPathForRange(
    start: Int,
    end: Int
): Path

Returns path that enclose the given text range.

Parameters
start: Int an inclusive start character offset
end: Int an exclusive end character offset
Return
a drawing path

getWordBoundary

fun getWordBoundary(offset: Int): TextRange

Returns the text range of the word at the given character offset.

Characters not part of a word, such as spaces, symbols, and punctuation, have word breaks on both sides. In such cases, this method will return a text range that contains the given character offset.

Word boundaries are defined more precisely in Unicode Standard Annex #29 <_>.

Properties

didOverflowHeight

val didOverflowHeight: Boolean

Returns true if the text is too tall and couldn't fit with given height.

didOverflowWidth

val didOverflowWidth: Boolean

Returns true if the text is too wide and couldn't fit with given width.

firstBaseline

val firstBaseline: Float

The distance from the top to the alphabetic baseline of the first line.

hasVisualOverflow

val hasVisualOverflow: Boolean

Returns true if either vertical overflow or horizontal overflow happens.

lastBaseline

val lastBaseline: Float

The distance from the top to the alphabetic baseline of the last line.

layoutInput

val layoutInput: TextLayoutInput

The parameters used for computing this text layout result.

placeholderRects

val placeholderRects: List<Rect?>

Returns a list of bounding boxes that is reserved for TextLayoutInput.placeholders. Each Rect in this list corresponds to the Placeholder passed to TextLayoutInput.placeholders and it will have the height and width specified in the Placeholder. It's guaranteed that TextLayoutInput.placeholders and TextLayoutResult.placeholderRects will have same length and order.

size

val size: IntSize

The amount of space required to paint this text in Int.