Text

EntityVisualceramic.Text (Class)

A visual to layout and display text. Works with UTF-8 strings.

Instance Members

glyphQuads: Array<GlyphQuad>

Array of glyph quads used to render the text. Each quad represents a single character glyph.


numLines: Int

The number of lines in the rendered text.


color: Color

The color of the text. Default is white.


content: String

The text content to display. Must not be null.


pointSize: Float

The font size in points. Default is 20.


lineHeight: Float

The line height multiplier. 1.0 means default line height, 2.0 means double line height, etc. Default is 1.0.


letterSpacing: Float

Additional spacing between letters in pixels. Default is 0.0.


The bitmap font used to render the text. If null, the default font will be used.


clipTextX: Float

X coordinate for text clipping. Set to -1 to disable clipping on this axis.


clipTextY: Float

Y coordinate for text clipping. Set to -1 to disable clipping on this axis.


clipTextWidth: Float

Width for text clipping. Set to -1 to disable clipping on this axis.


clipTextHeight: Float

Height for text clipping. Set to -1 to disable clipping on this axis.


preRenderedSize: Int

Pre-rendered size for MSDF fonts. Set to -1 to disable pre-rendering. When set to a positive value, the font will be pre-rendered at this size, which can be useful to improve performances and reduce draw calls in some situations.


align: Anonymous

Text alignment (LEFT, CENTER, or RIGHT). Default is LEFT.


fitWidth: Float

If set to true, text will be displayed with line breaks as needed so that it fits in the requested width.


maxLineDiff: Float

Maximum difference in line widths when using fitWidth. Set to -1 to disable line balancing. When set, the text will try to balance line widths to be more uniform.


clipText(x: Float, y: Float, width: Float, height: Float): Void

Set text clipping bounds.

Name Type Description
x Float The x coordinate of the clipping rectangle
y Float The y coordinate of the clipping rectangle
width Float The width of the clipping rectangle
height Float The height of the clipping rectangle

glyphCode(charCode: Int, pos: Int): Int

If provided, will be called for each glyph to display, giving the chance to override the character code to display. This can be used for example to display password-like fields, when used with EditText component:

var text = new Text();
text.glyphCode = (_, _) -> '*'.code;
text.content = 'Som2 pas!wOrd';
Name Type
charCode Int
pos Int
Returns
Int

destroy(): Void

computeContent(): Void

Compute and layout the text content. This method recalculates all glyph positions and updates the visual size.


lineForYPosition(y: Float): Int

Get the line number matching the given y position.

Name Type Description
y Float The y position relative to this Text visual
Returns Description
Int The line number (0-based)

posInLineForX(line: Int, x: Float): Int

Get the character index position relative to a line at the requested x value.

Name Type Description
line Int The line number (0-based)
x Float The x position relative to this Text visual
Returns Description
Int The character position within the line

indexForPosInLine(line: Int, posInLine: Int): Int

Get the global character index from the given line and position within that line.

Name Type Description
line Int The line number (0-based)
posInLine Int The position within the line
Returns Description
Int The global character index in the content string

xPositionAtIndex(index: Int): Float

Get an x position from the given character index.

Name Type Description
index Int The global character index in the content string
Returns Description
Float The x position relative to this Text visual

lineForIndex(index: Int): Int

Get the line number of the character at the given index.

Name Type Description
index Int The global character index in the content string
Returns Description
Int The line number (0-based)

posInLineForIndex(index: Int): Int

Get a character index position relative to its line from its global index position.

Name Type Description
index Int The global character index in the content string
Returns Description
Int The position within the line

new(): Void

Private Members

emitGlyphQuadsChange(): Void

Event fired when the glyph quads change.


handleTexturesDensityChange(_: Float, _: Float): Void
Name Type
_ Float
_ Float

scaleWidth(targetWidth: Float): Void

Scale the text width to match the target width. Only adjusts scaleX to match the requested width.

Name Type Description
targetWidth Float The desired width

scaleHeight(targetHeight: Float): Void

Scale the text height to match the target height. Only adjusts scaleY to match the requested height.

Name Type Description
targetHeight Float The desired height

computeGlyphQuads(fitWidth: Float, maxLineDiff: Float, ?fixedNumLines: Int = -1): Int

Compute glyph quads for rendering.

Name Type Default Description
fitWidth Float The width to fit text into (-1 for no fitting)
maxLineDiff Float The maximum difference in line widths for balancing
fixedNumLines Int -1 Fixed number of lines to use (-1 for automatic)
Returns Description
Int The number of lines in the laid out text

fontDestroyed(_: Entity): Void

Internal callback when the font is destroyed. Resets the font to the default font.

Name Type
_ Entity

toString(): String
Returns
String

Metadata

Name Parameters
:build tracker.macros.EventsMacro.build()
:autoBuild tracker.macros.EventsMacro.build()
:build ceramic.macros.EntityMacro.buildForCompletion()
:autoBuild ceramic.macros.EntityMacro.buildForCompletion()