TextComponent

Native text component

Provides access to a native text component instance

.TypeName: string 

.alignment: Alignment 

Text component alignment.

.alignment 

Set text component alignment.

.characterSpacing: number 

Text component character spacing.

.characterSpacing 

Set text component character spacing.

.effect: TextEffect 

Text component effect.

.effect 

Set text component effect

.justification: VerticalAlignment 

Text component justification.

Deprecated: Please use verticalAlignment instead.

.justification 

Set text component justification.

Deprecated: Please use verticalAlignment instead.

.lineSpacing: number 

Text component line spacing.

.lineSpacing 

Set text component line spacing

.material: null | Material 

Material used to render the text.

.material 

Set material to render the text with.

.text: string 

Text component text.

.text 

Set text component text.

.verticalAlignment: VerticalAlignment 

1.2.0+

Text component vertical alignment.

.verticalAlignment 

1.2.0+

Set text component vertical alignment.

.wrapMode: TextWrapMode 

1.2.1+

Text component line wrap mode.

.wrapMode 

1.2.1+

Set text component line wrap mode.

.wrapWidth: number 

1.2.1+

Text component line wrap width.

.wrapWidth 

1.2.1+

Set text component line wrap width.

Only takes effect when wrapMode is something other than None.

.getBoundingBox<T>(out: T) ⇒ T 

.getBoundingBox() ⇒ Float32Array

Axis-aligned bounding box, in object space.

The bounding box is computed using the current component properties that influence the position and size of the text. The bounding box is affected by alignment, spacing, effect type and the font set in the material.

To calculate the size for a different text, use getBoundingBoxForText.

Useful for adjusting text position or scaling:

1const box = new Float32Array(4);
2text.getBoundingBox(box);
3const width = box[2] - box[0];
4// Make text 1m wide
5text.object.setScalingLocal([1/width, 1, 1]);

Returns: Bounding box - left, bottom, right, top.

ParamTypeDescription
outTPreallocated array to write into, to avoid garbage, otherwise will allocate a new Float32Array.
Template ParamType Definition
Textends NumberArray

.getBoundingBoxForText<T>(text: string, out: T) ⇒ T 

.getBoundingBoxForText(text: string) ⇒ Float32Array

Axis-aligned bounding box for a given text, in object space.

To calculate the size for the currently set text, use getBoundingBox.

Useful for calculating the text size before an update and potentially adjusting the text:

1let updatedName = 'some very long name';
2const box = new Float32Array(4);
3text.getBoundingBoxForText(updatedName, box);
4const width = box[2] - box[0];
5if(width > 2.0) {
6    updatedName = updatedName.slice(0, 5) + '...';
7}
8text.text = updatedName;

Returns: Bounding box - left, bottom, right, top.

ParamTypeDescription
textstringText string to calculate the bounding box for.
outTPreallocated array to write into, to avoid garbage, otherwise will allocate a new Float32Array.
Template ParamType Definition
Textends NumberArray