TextBlock

open class TextBlock : Text

A text ui element to display text block on the glasses screen.

The TextBlock is an enhancement of Text, and supports additional features like multiline and padding

Notes:

  1. Performance-wise, the text within the text block is processed when needed. it is recommender to setup the TextBlock properties once, before querying it information, line getLinesCount, getWidth, getMeasuredContentWidth etc.

  2. It is recommended to set the width of the TextBlock. If the width is not set, a default width will be used to the wrapping

  3. The Height of the TextBlock is calculated dynamically according to its content

  4. You may override the text split pattern. See setSplitRegex

  5. Extended line modification can be done via registerLineModifierHandler

See also

Constructors

Link copied to clipboard
constructor()
constructor(id: String)
constructor(font: Font)
constructor(id: String, font: Font)

Types

Link copied to clipboard
Link copied to clipboard
data class LineModifier(var textColor: Int? = null, var backgroundColor: Int? = null, var textVisible: Boolean = true, var underline: Boolean = false, var strikethrough: Boolean = false, var fillMaxWidth: Boolean = false)

Functions

Link copied to clipboard
open override fun getHeight(): Float

Receive the ui element height

Link copied to clipboard

The function returns the lines count of the text block.

Link copied to clipboard

Returns the maximum allowed lines set by setMaxLines or -1 if not set

Link copied to clipboard
open override fun getMeasuredContentHeight(): Float

Return the measured height of the text (getText in pixels

Link copied to clipboard
open override fun getMeasuredContentWidth(): Float

Return the measured width of the text (getText in pixels

Link copied to clipboard
open override fun getText(): String

Get the ui element text

Link copied to clipboard
open override fun getWidth(): Float

Receive the ui element width

Link copied to clipboard
Link copied to clipboard
protected open override fun onDraw(canvas: CanvasBuffer)

The draw method is called to actually draw the ui element visual representation to the CanvasBuffer

Link copied to clipboard
fun registerLineModifierHandler(handler: (lineIndex: Int, modifier: TextBlock.LineModifier) -> Unit): TextBlock

Set the text block lines color chooser.

Link copied to clipboard
open override fun setDimensions(x: Float, y: Float, width: Float, height: Float): UIElement

Sets the ui element dimensions

Link copied to clipboard
Link copied to clipboard
open override fun setEllipsis(ellipsis: Boolean): TextBlock

Enable\Disable ellipsis. Works together with setMaxLines

Link copied to clipboard
open override fun setHeight(height: Float): UIElement

Sets the ui element height

Link copied to clipboard
fun setMaxLines(maxLines: Int): TextBlock

Set the maximum allowed lines. Long text that exceeds maxLines will be trimmed

Link copied to clipboard
fun setPadding(left: Float = 0.0f, top: Float = 0.0f, right: Float = 0.0f, bottom: Float = 0.0f): TextBlock

set padding for the text

Link copied to clipboard
open override fun setResource(font: Font): TextBlock

Set the font information

Link copied to clipboard
fun setSpacedBy(spacedBy: Float): TextBlock

Set the spacing between lines. Default 0.

Link copied to clipboard

Overrider the default text splitting regex.

Link copied to clipboard
open override fun setText(text: String): TextBlock

Set the text to be displayed

Link copied to clipboard
open override fun setWidth(width: Float): UIElement

Sets the ui element width

Link copied to clipboard
open override fun setWidthHeight(width: Float, height: Float): UIElement

Sets the ui element size