TextComponent

open class TextComponent(color: Int = Color.BLACK, typeface: Typeface = Typeface.DEFAULT, textSizeSp: Float = Defaults.TEXT_COMPONENT_TEXT_SIZE, textAlignment: Layout.Alignment = Layout.Alignment.ALIGN_NORMAL, lineCount: Int = TEXT_COMPONENT_LINE_COUNT, truncateAt: TextUtils.TruncateAt? = TextUtils.TruncateAt.END, margins: Dimensions = Dimensions.Empty, padding: Dimensions = Dimensions.Empty, val background: Component? = null, minWidth: TextComponent.MinWidth = MinWidth.fixed())

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

Constructors

Link copied to clipboard
constructor(color: Int = Color.BLACK, typeface: Typeface = Typeface.DEFAULT, textSizeSp: Float = Defaults.TEXT_COMPONENT_TEXT_SIZE, textAlignment: Layout.Alignment = Layout.Alignment.ALIGN_NORMAL, lineCount: Int = TEXT_COMPONENT_LINE_COUNT, truncateAt: TextUtils.TruncateAt? = TextUtils.TruncateAt.END, margins: Dimensions = Dimensions.Empty, padding: Dimensions = Dimensions.Empty, background: Component? = null, minWidth: TextComponent.MinWidth = MinWidth.fixed())

Types

Link copied to clipboard
fun interface MinWidth

Defines a TextComponent’s minimum width.

Properties

Link copied to clipboard
val background: Component? = null

drawn behind the text.

Functions

Link copied to clipboard
open fun copy(color: Int = this.color, typeface: Typeface = this.typeface, textSizeSp: Float = this.textSizeSp, textAlignment: Layout.Alignment = this.textAlignment, lineCount: Int = this.lineCount, truncateAt: TextUtils.TruncateAt? = this.truncateAt, margins: Dimensions = this.margins, padding: Dimensions = this.padding, background: Component? = this.background, minWidth: TextComponent.MinWidth = this.minWidth): TextComponent

Creates a new TextComponent based on this one.

Link copied to clipboard
fun draw(context: DrawingContext, text: CharSequence, x: Float, y: Float, horizontalPosition: HorizontalPosition = HorizontalPosition.Center, verticalPosition: VerticalPosition = VerticalPosition.Center, maxWidth: Int = DEF_LAYOUT_SIZE, maxHeight: Int = DEF_LAYOUT_SIZE, rotationDegrees: Float = 0.0f)

Uses Canvas to draw this TextComponent.

Link copied to clipboard
fun getBounds(context: MeasuringContext, text: CharSequence? = null, maxWidth: Int = DEF_LAYOUT_SIZE, maxHeight: 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 maximum dimensions. pad defines whether to extend text by such a number of blank lines that it has lineCount lines.

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

Returns the height of this TextComponent for the given text and maximum dimensions. 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: MeasuringContext, text: CharSequence? = null, maxWidth: Int = DEF_LAYOUT_SIZE, maxHeight: Int = DEF_LAYOUT_SIZE, rotationDegrees: Float = 0.0f, pad: Boolean = text == null): Float

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