TextComponent

Uses Canvas to render text. This class utilizes StaticLayout and supports the following:

  • multi-line text with automatic line breaking

  • text truncation

  • Spanned

  • text rotation

  • text backgrounds (any Component)

  • margins and padding

See also

Types

Link copied to clipboard
class Builder

The builder for TextComponent.

Properties

Link copied to clipboard

The text’s background. Use padding to set the padding between the text and the background.

Link copied to clipboard
var color: Int

The text’s color.

Link copied to clipboard

The type of text truncation to be used when the text’s width exceeds the amount of available space. By default, text is truncated at the end, and an ellipsis (…) is used.

Link copied to clipboard

The maximum number of lines for the text. For performance reasons, during the measurement phase, it is presumed that the actual number of lines is equal to this value.

Link copied to clipboard
open override var margins: MutableDimensions

The margins around the background. This is applied even if background is null.

Link copied to clipboard
open override var padding: MutableDimensions

The padding between the text and the background. This is applied even if background is null.

Link copied to clipboard

The text alignment.

Link copied to clipboard

The text alignment.

Link copied to clipboard

The font size (in sp).

Link copied to clipboard

The Typeface for the text.

Functions

Link copied to clipboard
fun drawText(context: DrawContext, text: CharSequence, textX: Float, textY: Float, horizontalPosition: HorizontalPosition = HorizontalPosition.Center, verticalPosition: VerticalPosition = VerticalPosition.Center, maxTextWidth: Int = DEF_LAYOUT_SIZE, maxTextHeight: Int = DEF_LAYOUT_SIZE, rotationDegrees: Float = 0.0f)

Uses Canvas to draw this TextComponent.

Link copied to clipboard
fun getHeight(context: MeasureContext, text: CharSequence? = null, width: Int = DEF_LAYOUT_SIZE, height: Int = DEF_LAYOUT_SIZE, rotationDegrees: Float = 0.0f, pad: Boolean = text == null): Float

Returns the height of this TextComponent for the given text and the available width and height. pad defines whether to extend text by such a number of blank lines that it has lineCount lines.

Link copied to clipboard
fun getTextBounds(context: MeasureContext, text: CharSequence? = null, width: Int = DEF_LAYOUT_SIZE, height: Int = DEF_LAYOUT_SIZE, outRect: RectF = tempMeasureBounds, includePaddingAndMargins: Boolean = true, rotationDegrees: Float = 0.0f, pad: Boolean = text == null): RectF

Returns the bounds (RectF) of this TextComponent for the given text and the available width and height. pad defines whether to extend text by such a number of blank lines that it has lineCount lines.

Link copied to clipboard
fun getWidth(context: MeasureContext, text: CharSequence? = null, width: Int = DEF_LAYOUT_SIZE, height: Int = DEF_LAYOUT_SIZE, rotationDegrees: Float = 0.0f, pad: Boolean = text == null): Float

Returns the width of this TextComponent for the given text and the available width and height. pad defines whether to extend text by such a number of blank lines that it has lineCount lines.