Paragraph
interface Paragraph
androidx.compose.ui.text.Paragraph |
A paragraph of text that is laid out.
Paragraphs can be displayed on a Canvas using the paint method.
Summary
Public methods | |
---|---|
abstract ResolvedTextDirection |
getBidiRunDirection(offset: Int) Get the text direction of the character at the given offset. |
abstract Rect |
getBoundingBox(offset: Int) Returns the bounding box as Rect of the character for given character offset. |
abstract Rect |
getCursorRect(offset: Int) Returns rectangle of the cursor area. |
abstract Float |
getHorizontalPosition(offset: Int, usePrimaryDirection: Boolean) Compute the horizontal position where a newly inserted character at offset would be. |
abstract Float |
getLineBottom(lineIndex: Int) Returns the bottom y coordinate of the given line. |
abstract Int |
getLineEnd(lineIndex: Int, visibleEnd: Boolean = false) Returns the end offset of the given line |
abstract Int |
getLineForOffset(offset: Int) Returns the line number on which the specified text offset appears. |
abstract Int |
getLineForVerticalPosition(vertical: Float) Returns line number closest to the given graphical vertical position. |
abstract Float |
getLineHeight(lineIndex: Int) Returns the height of the given line. |
abstract Float |
getLineLeft(lineIndex: Int) Returns the left x Coordinate of the given line. |
abstract Float |
getLineRight(lineIndex: Int) Returns the right x Coordinate of the given line. |
abstract Int |
getLineStart(lineIndex: Int) Returns the start offset of the given line, inclusive. |
abstract Float |
getLineTop(lineIndex: Int) Returns the bottom y coordinate of the given line. |
abstract Int |
getLineVisibleEnd(lineIndex: Int) Returns the end of visible offset of the given line. |
abstract Float |
getLineWidth(lineIndex: Int) Returns the width of the given line. |
abstract Int |
getOffsetForPosition(position: Offset) Returns the character offset closest to the given graphical position. |
abstract ResolvedTextDirection |
getParagraphDirection(offset: Int) Get the text direction of the paragraph containing the given offset. |
abstract Path |
getPathForRange(start: Int, end: Int) Returns path that enclose the given text range. |
abstract TextRange |
getWordBoundary(offset: Int) Returns the TextRange of the word at the given character offset. |
abstract Boolean |
isLineEllipsized(lineIndex: Int) Returns true if ellipsis happens on the given line, otherwise returns false |
abstract Unit |
paint(canvas: Canvas, color: Color = Color.Unspecified, shadow: Shadow? = null, textDecoration: TextDecoration? = null) Paint the paragraph to canvas, and also overrides some paint settings. |
Properties | |
---|---|
abstract Boolean |
True if there is more vertical content, but the text was truncated, either
because we reached |
abstract Float |
The distance from the top of the paragraph to the alphabetic baseline of the first line, in logical pixels. |
abstract Float |
The amount of vertical space this paragraph occupies. |
abstract Float |
The distance from the top of the paragraph to the alphabetic baseline of the last line, in logical pixels. |
abstract Int |
The total number of lines in the text. |
abstract Float |
Returns the smallest width beyond which increasing the width never decreases the height. |
abstract Float |
The width for text if all soft wrap opportunities were taken. |
abstract List<Rect?> |
The bounding boxes reserved for the input placeholders in this Paragraphs. |
abstract Float |
The amount of horizontal space this paragraph occupies. |
Public methods
getBidiRunDirection
abstract fun getBidiRunDirection(offset: Int): ResolvedTextDirection
Get the text direction of the character at the given offset.
getBoundingBox
abstract fun getBoundingBox(offset: Int): Rect
Returns the bounding box as Rect of the character for given character offset. Rect includes the top, bottom, left and right of a character.
getHorizontalPosition
abstract fun getHorizontalPosition(
offset: Int,
usePrimaryDirection: Boolean
): Float
Compute the horizontal position where a newly inserted character at offset would be.
If the inserted character at offset is within a LTR/RTL run, the returned position will be the left(right) edge of the character.
For example: Paragraph's direction is LTR. Text in logic order: L0 L1 L2 R3 R4 R5 Text in visual order: L0 L1 L2 R5 R4 R3 position of the offset(2): | position of the offset(4): |
However, when the offset is at the BiDi transition offset, there will be two possible visual positions, which depends on the direction of the inserted character.
For example: Paragraph's direction is LTR. Text in logic order: L0 L1 L2 R3 R4 R5 Text in visual order: L0 L1 L2 R5 R4 R3 position of the offset(3): | (The inserted character is LTR) | (The inserted character is RTL)
In this case, usePrimaryDirection will be used to resolve the ambiguity. If true, the inserted character's direction is assumed to be the same as Paragraph's direction. Otherwise, the inserted character's direction is assumed to be the opposite of the Paragraph's direction.
For example: Paragraph's direction is LTR. Text in logic order: L0 L1 L2 R3 R4 R5 Text in visual order: L0 L1 L2 R5 R4 R3 position of the offset(3): | (usePrimaryDirection is true) | (usePrimaryDirection is false)
This method is useful to compute cursor position.
Parameters | |
---|---|
offset: Int | the offset of the character, in the range of 0,length. |
usePrimaryDirection: Boolean | whether the paragraph direction is respected when offset points to a BiDi transition point. |
Return | |
---|---|
a float number representing the horizontal position in the unit of pixel. |
getLineBottom
abstract fun getLineBottom(lineIndex: Int): Float
Returns the bottom y coordinate of the given line.
getLineEnd
abstract 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
abstract 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.
getLineForVerticalPosition
abstract 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.
getLineHeight
abstract fun getLineHeight(lineIndex: Int): Float
Returns the height of the given line.
getLineLeft
abstract fun getLineLeft(lineIndex: Int): Float
Returns the left x Coordinate of the given line.
getLineRight
abstract fun getLineRight(lineIndex: Int): Float
Returns the right x Coordinate of the given line.