androidx.compose.ui.text

TextLayoutResult

Class · from org.jetbrains.compose.ui:ui-text:1.12.2

No hand-written docs yet.

The data class which holds text layout result.

class TextLayoutResult(
    layoutInput: TextLayoutInput,
    multiParagraph: MultiParagraph,
    size: IntSize,
)

How to get one

Create it

Ready-made values and functions that return it

Properties

firstBaseline

val firstBaseline: Float

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

lastBaseline

val lastBaseline: Float

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

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.

hasVisualOverflow

val hasVisualOverflow: Boolean

Returns true if either vertical overflow or horizontal overflow happens.

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.

lineCount

val lineCount: Int

Returns a number of lines of this text layout

layoutInput

val layoutInput: TextLayoutInput

The parameters used for computing this text layout result.

multiParagraph

val multiParagraph: MultiParagraph

The multi paragraph object.

size

val size: IntSize

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

Functions

getLineStart

fun getLineStart(lineIndex: Int): Int

Returns the start offset of the given line, inclusive.

getLineEnd

fun getLineEnd(
    lineIndex: Int,
    visibleEnd: Boolean = false,
): Int

Returns the end offset of the given line.

isLineEllipsized

fun isLineEllipsized(lineIndex: Int): Boolean

Returns true if the given line is ellipsized, otherwise returns false.

getLineTop

fun getLineTop(lineIndex: Int): Float

Returns the top y coordinate of the given line.

getLineBaseline

fun getLineBaseline(lineIndex: Int): Float

Returns the distance in pixels from the top of the text layout to the alphabetic baseline of the line at index lineIndex.

getLineBottom

fun getLineBottom(lineIndex: Int): Float

Returns the bottom y coordinate of the given line.

getLineLeft

fun getLineLeft(lineIndex: Int): Float

Returns the left x coordinate of the given line.

getLineRight

fun getLineRight(lineIndex: Int): Float

Returns the right x coordinate of the given line.

getLineForOffset

fun getLineForOffset(offset: Int): Int

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

getLineForVerticalPosition

fun getLineForVerticalPosition(vertical: Float): Int

Returns line number closest to the given graphical vertical position.

getHorizontalPosition

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

Get the horizontal position for the specified text offset.

getParagraphDirection

fun getParagraphDirection(offset: Int): ResolvedTextDirection

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

getBidiRunDirection

fun getBidiRunDirection(offset: Int): ResolvedTextDirection

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

getOffsetForPosition

fun getOffsetForPosition(position: Offset): Int

Returns the character offset closest to the given graphical position.

getBoundingBox

fun getBoundingBox(offset: Int): Rect

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

getWordBoundary

fun getWordBoundary(offset: Int): TextRange

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

getCursorRect

fun getCursorRect(offset: Int): Rect

Returns the rectangle of the cursor area

getPathForRange

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

Returns path that enclose the given text range.

copy

fun copy(
    layoutInput: TextLayoutInput = this.layoutInput,
    size: IntSize = this.size,
): TextLayoutResult
Library docs

The data class which holds text layout result.