TextLayoutResult
data class TextLayoutResult
kotlin.Any | |
↳ | androidx.compose.ui.text.TextLayoutResult |
The data class which holds text layout result.
Summary
Public methods | |
---|---|
ResolvedTextDirection |
getBidiRunDirection(offset: Int) Get the text direction of the resolved BiDi run that the character at the given offset associated with. |
Rect |
getBoundingBox(offset: Int) 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, visibleEnd: Boolean = false) Returns the end offset of the given line |
Int |
getLineForOffset(offset: Int) Returns the line number on which the specified text offset appears. |
Int |
getLineForVerticalPosition(vertical: Float) Returns line number closest to the given graphical vertical position. |
Float |
getLineLeft(lineIndex: Int) Returns the left x coordinate of the given line. |
Float |
getLineRight(lineIndex: Int) Returns the right x coordinate of the given line. |
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 |
getLineVisibleEnd(lineIndex: Int) Returns the end of visible offset of the given line. |
Int |
getOffsetForPosition(position: Offset) Returns the character offset closest to the given graphical position. |
ResolvedTextDirection |
getParagraphDirection(offset: Int) 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 |
getWordBoundary(offset: Int) Returns the text range of the word at the given character offset. |
Boolean |
isLineEllipsized(lineIndex: Int) Returns true if ellipsis happens on the given line, otherwise returns false |
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. |
Int |
Returns a number of lines of this text layout |
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): ResolvedTextDirection
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. |
See Also
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,
visibleEnd: Boolean = false
): Int
Returns the end offset of the given line
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 verse.
Parameters | |
---|---|
lineIndex: Int | the line number |
visibleEnd: Boolean = false | 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. |
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. |
getLineForVerticalPosition
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: Float | the vertical position |
Return | |
---|---|
the 0 origin line number. |
getLineLeft
fun getLineLeft(lineIndex: Int): Float
Returns the left x coordinate of the given line.
Parameters | |
---|---|
lineIndex: Int | the line number |
Return | |
---|---|
the line left x coordinate |
getLineRight
fun getLineRight(lineIndex: Int): Float
Returns the right x coordinate of the given line.
Parameters | |
---|---|
lineIndex: Int | the line number |
Return | |
---|---|
the line right x coordinate |
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 |