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.

.effectOffset: Float32Array 

1.3.0+

Equivalent to getEffectOffset.

Note: Prefer to use getEffectOffset for performance.

.effectOffset 

1.3.0+

Equivalent to setEffectOffset.

.justification: VerticalAlignment 

Text component justification.

Deprecated: Please use verticalAlignment instead.

.justification 

Set text component justification.

Deprecated: Please use verticalAlignment instead.

.justified: boolean 

1.3.0+

Whether text is justified horizontally.

Aligns text horizontally to both margins by adding space between words.

Requires wrapMode to be Soft or Hard and non-0 wrapWidth.

The last line in a paragraph is never justified and respects alignment.

.justified 

1.3.0+

Set whether text is justified horizontally.

.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, in object space.

.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

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

.getEffectOffset() ⇒ Float32Array

1.3.0+

Get text component effect offset.

Returns: The out parameter.

ParamTypeDescription
outTDestination array, expected to have at least 2 elements.
Template ParamType Definition
Textends NumberArray

.setEffectOffset(offset: Readonly<NumberArray>) ⇒ void 

1.3.0+

Set text component effect offset.

The offset is given as X and Y factors for emHeight. E.g. a value of 2 in one axis offsets the effect by two font line heights. A positive Y value moves the effect upwards.

ParamTypeDescription
offsetReadonly<NumberArray>Array with new offset, expected to have at least 2 elements.