🌈 Create new beautiful Compose Gradients with our new wesite ->
Class

TextLayoutResult

Holds the result of a text layout computation.

Source set: Common
public class TextLayoutResult public constructor(
    /** The input parameters used for this layout. */
    public val layoutInput: TextLayoutInput,

    /** The computed [MultiParagraph] layout. */
    public val multiParagraph: MultiParagraph,

    /**
     * The width and height of this text layout.
     *
     * Unlike [multiParagraph] dimensions, this size respects the input constraints.
     */
    public val size: IntSize,
)

Holds the result of a text layout computation.

Properties

firstBaseline

Source set: Common
public val firstBaseline: Float = multiParagraph.firstBaseline

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

lastBaseline

Source set: Common
public val lastBaseline: Float = multiParagraph.lastBaseline

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

didOverflowHeight

Source set: Common
public val didOverflowHeight: Boolean

True if the text height exceeds the layout boundaries.

didOverflowWidth

Source set: Common
public val didOverflowWidth: Boolean

True if the text width exceeds the layout boundaries.

hasVisualOverflow

Source set: Common
public val hasVisualOverflow: Boolean

True if the text overflows vertically or horizontally.

placeholderRects

Source set: Common
public val placeholderRects: List<Rect?> = multiParagraph.placeholderRects

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

Source set: Common
public val lineCount: Int

Returns a number of lines of this text layout

Functions

getLineStart

Source set: Common
public fun getLineStart(lineIndex: Int): Int

Returns the start offset of the given line, inclusive.

The start offset represents a position in text before the first character in the given line. For example, getLineStart(1) will return 4 for the text below

┌────┐ │abcd│ │efg │ └────┘

Parameters

lineIndex the line number

Return

the start offset of the line

getLineEnd

Source set: Common
public fun getLineEnd(lineIndex: Int, visibleEnd: Boolean = false): Int

Returns the end offset of the given line.

The end offset represents a position in text after the last character in the given line. For example, getLineEnd(0) will return 4 for the text below

┌────┐ │abcd│ │efg │ └────┘

Characters being ellipsized are treated as invisible characters. So that if visibleEnd is false, it will return line end including the ellipsized characters and vice versa.

Parameters

lineIndex the line number
visibleEnd if true, the returned line end will not count trailing whitespaces or linefeed characters. Otherwise, this function will return the logical line end. By default it's false.

Return

an exclusive end offset of the line.

isLineEllipsized

Source set: Common
public fun isLineEllipsized(lineIndex: Int): Boolean

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

Parameters

lineIndex a 0 based line index

Return

true if the given line is ellipsized, otherwise false

getLineTop

Source set: Common
public fun getLineTop(lineIndex: Int): Float

Returns the top y coordinate of the given line.

Parameters

lineIndex the line number

Return

the line top y coordinate

getLineBaseline

Source set: Common
public 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

Source set: Common
public fun getLineBottom(lineIndex: Int): Float

Returns the bottom y coordinate of the given line.

Parameters

lineIndex the line number

Return

the line bottom y coordinate

getLineLeft

Source set: Common
public fun getLineLeft(lineIndex: Int): Float

Returns the left x coordinate of the given line.

Parameters

lineIndex the line number

Return

the line left x coordinate

getLineRight

Source set: Common
public fun getLineRight(lineIndex: Int): Float

Returns the right x coordinate of the given line.

Parameters

lineIndex the line number

Return

the line right x coordinate

getLineForOffset

Source set: Common
public 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 a character offset

Return

the 0 origin line number.

getLineForVerticalPosition

Source set: Common
public fun getLineForVerticalPosition(vertical: Float): Int

Returns line number closest to the given graphical vertical position.

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

Parameters

vertical the vertical position

Return

the 0 origin line number.

getHorizontalPosition

Source set: Common
public 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 a character offset
usePrimaryDirection 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.

getParagraphDirection

Source set: Common
public fun getParagraphDirection(offset: Int): ResolvedTextDirection

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

Parameters

offset a character offset

Return

the paragraph direction

getBidiRunDirection

Source set: Common
public fun getBidiRunDirection(offset: Int): ResolvedTextDirection

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

Parameters

offset a character offset

Return

the direction of the BiDi run of the given character offset.

getOffsetForPosition

Source set: Common
public fun getOffsetForPosition(position: Offset): Int

Returns the character offset closest to the given graphical position.

Parameters

position a graphical position in this text layout

Return

a character offset that is closest to the given graphical position.

getBoundingBox

Source set: Common
public fun getBoundingBox(offset: Int): Rect

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

Parameters

offset a character offset

Return

a bounding box for the character in pixels.

getWordBoundary

Source set: Common
public 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 <http://www.unicode.org/reports/tr29/#Word_Boundaries>.

getCursorRect

Source set: Common
public fun getCursorRect(offset: Int): Rect

Returns the rectangle of the cursor area

Parameters

offset An character offset of the cursor

Return

a rectangle of cursor region

getPathForRange

Source set: Common
public fun getPathForRange(start: Int, end: Int): Path

Returns path that enclose the given text range.

Parameters

start an inclusive start character offset
end an exclusive end character offset

Return

a drawing path

copy

Source set: Common
public fun copy(
        layoutInput: TextLayoutInput = this.layoutInput,
        size: IntSize = this.size,
    ): TextLayoutResult