Text
ClassRenders 2D text with specific style and layout.
- Available on all platforms
Index
Properties
- backgroundSettings
- blendMode
- capitalizationOverride
- colorMask
- customMaterial
- debugRenderLayoutRect
- depthTest
- dropshadowSettings
- editable
- enabled
- enableRichText
- extentsTarget
- font
- fontSource
- horizontalAlignment
- horizontalOverflow
- isBeingDestroyed
- isEnabledInHierarchy
- italic
- layoutRect
- letterSpacing
- lineSpacing
- meshShadowMode
- onEditingFinished
- onEditingStarted
- onEditingUpdated
- outlineSettings
- preferredStyle
- renderOrder
- sceneObject
- shadowColor
- shadowDensity
- showEditingPreview
- size
- sizeToFit
- stretchMode
- text
- textFill
- touchHandler
- twoSided
- uniqueIdentifier
- verticalAlignment
- verticalOverflow
- weight
Methods
Remarks
Supports Dynamic Text.
Example
//@input Component.Text textComponent
//@input Asset.Font customFont
//@input vec4 color {"widget":"color"}
script.textComponent.text = "Hello there";
script.textComponent.font = script.customFont;
script.textComponent.size = 30;
script.textComponent.verticalOverflow = VerticalOverflow.Truncate;
script.textComponent.textFill.color = script.color;
// @input Component.Text textComponent
// @input Component.ScreenTransform background
// Reparent the background object to be a child of the Text object
var textObj = script.textComponent.getSceneObject();
script.background.getSceneObject().setParent(textObj);
// Set the background object to be the extentsTarget of the Text object, so it matches the rendered area
script.textComponent.extentsTarget = script.background;
Extends
Properties
backgroundSettings
backgroundSettings:
BackgroundSettings
Settings for drawing a background behind the text.
blendMode
blendMode:
BlendMode
How the text should be blended during rendering.
Since
Lens Scripting Version 324
Default Value
BlendMode.PremultipliedAlphaAuto
capitalizationOverride
capitalizationOverride:
CapitalizationOverride
Overrides the capitalization of the text rendered.
Since
Lens Scripting Version 385
Default Value
CapitalizationOverride.None
Example
// @input Component.Text textComponent
script.textComponent.capitalizationOverride = CapitalizationOverride.AllLower;
colorMask
colorMask:
vec4b
Controls the masking of color channels with a vec4b representing each channel with a boolean.
Since
Lens Scripting Version 149
Default Value
(true, true, true, true)
customMaterial
customMaterial:
Material
A custom Material to render this Text with, authored from a Mesh3d shader graph that uses the Text Data node. The material must have a single Pass; if it is invalid (unsupported shader or more than one Pass) or null (the default), Text renders with the built-in text shader.
Since
Lens Scripting Version 377
Default Value
null
Example
//@input Component.Text text
//@input Asset.Material customTextMaterial
script.text.customMaterial = script.customTextMaterial;
debugRenderLayoutRect
debugRenderLayoutRect:
boolean
If enabled, draws the Text#layoutRect bounds as a wireframe for debugging text layout. Has no effect when a ScreenTransform is attached to the same SceneObject, since the ScreenTransform supersedes the layoutRect.
Since
Lens Scripting Version 364
Default Value
false
depthTest
depthTest:
boolean
If enabled, the text material will use Depth Testing. Useful when Text exists in 3D space.
Default Value
false
dropshadowSettings
dropshadowSettings:
DropshadowSettings
Settings for how dropshadow is used in text drawing.
editable
editable:
boolean
Makes the Text component editable. When this is enabled the Text can be clicked to open up the device keyboard and edit the contents.
Since
Lens Scripting Version 165
Default Value
false
enabled
enabled:
boolean
If disabled, the Component will stop enacting its behavior.
Default Value
true
Inherited from
enableRichText
enableRichText:
boolean
If enabled, inputted text will be interpreted as rich text. For more info, see Rich Text.
Since
Lens Scripting Version 356
Default Value
false
extentsTarget
extentsTarget:
ScreenTransform
When a ScreenTransform is present on this SceneObject,
and extentsTarget is a child of this SceneObject, extentsTarget will be repositioned to match the exact
area this MeshVisual is being rendered. Very useful for Image and Text components.
Default Value
null
Inherited from
font
font:
Font
Font asset used.
Setting this will override any existing Font, FontFamily, or FontCollection asset assigned as the font source of the text component. If there is a FontFamily or FontCollection asset currently assigned as the font source, reading this will return null.
Default Value
null
fontSource
fontSource:
Font|FontFamily|FontCollection
The font source for this text component. Can be a Font, FontFamily, or FontCollection asset.
Since
Lens Scripting Version 356
Default Value
null
horizontalAlignment
horizontalAlignment:
HorizontalAlignment
When a ScreenTransform is attached to the same SceneObject, this controls how the mesh will be positioned horizontally depending on stretchMode.
Default Value
HorizontalAlignment.Center
Inherited from
BaseMeshVisual.horizontalAlignment
horizontalOverflow
horizontalOverflow:
HorizontalOverflow
Controls how text should be handled when it goes past the horizontal boundaries defined by ScreenTransform or Text#layoutRect, with the former taking precedence.
Default Value
HorizontalOverflow.Overflow
isBeingDestroyed
readonlyisBeingDestroyed:boolean
Returns true if this Component is currently being destroyed. Becomes true as soon as
destruction begins via Component#destroy or destruction of its owning SceneObject,
before any OnDestroyEvent callbacks fire.
Since
Lens Scripting Version 364
Example
if (!script.isBeingDestroyed) {
// Component is still fully alive
}
Inherited from
BaseMeshVisual.isBeingDestroyed
isEnabledInHierarchy
readonlyisEnabledInHierarchy:boolean
Returns true if this Component, its SceneObject, and all of that SceneObjects parents are enabled.
Inherited from
BaseMeshVisual.isEnabledInHierarchy
italic
italic:
boolean
If enabled, the rendered text will try to use an italic font style.
When assigned as null, the italic axis from Text.preferredStyle is used instead. When explicitly assigned, Text.italic overrides any italic value in Text.preferredStyle.
Since
Lens Scripting Version 325
Default Value
null
layoutRect
layoutRect:
Rect
The rectangular bounds the text is laid out within. Controls text wrapping and alignment, and defines the area Text#horizontalOverflow, Text#verticalOverflow, and Text#sizeToFit are evaluated against.
Each bound is defined as an offset in world units from the SceneObject's position.
If a ScreenTransform is attached to the same SceneObject, it always supersedes this property — text is laid out within the ScreenTransform's rect instead, and changes to layoutRect have no effect.
Since
Lens Scripting Version 364
Default Value
Rect.create(-7.5, 7.5, -2.25, 2.25)
letterSpacing
letterSpacing:
number
Modifies the spacing between letters. A value of 0 uses the font's normal letter spacing. Negative values will remove space between letters, and positive values will add more space between letters.
Default Value
0
lineSpacing
lineSpacing:
number
Modifies the vertical spacing between lines, as a multiple of lines. 1 will be single spacing, 2 will be double spaced, and 0.5 would be half the normal line height.
Since
Lens Scripting Version 153
Default Value
1
meshShadowMode
meshShadowMode:
MeshShadowMode
None = 0, Caster = 1, Receiver = 2
Default Value
MeshShadowMode.None
Inherited from
onEditingFinished
readonlyonEditingFinished:event1<string,void>
This event will notify you when the user finishes editing the text.
onEditingStarted
readonlyonEditingStarted:event0<void>
This event will notify you when the input keyboard opens.
onEditingUpdated
readonlyonEditingUpdated:event1<string,void>
This event will notify you on every edit to the text while the user is typing.
outlineSettings
outlineSettings:
OutlineSettings
Settings for how text outline is used in text drawing.
preferredStyle
preferredStyle:
string
Controls style applied to the text. Accepts a FontStyles constant (e.g. FontStyles.Bold). If Text.fontSource is assigned to a variable font or a font collection with variable fonts, this also accepts a named instance name or custom variation style name that belongs to the variable font.
Matching is case-insensitive and ignores whitespace and hyphens, so "Bold Italic",
"bolditalic", and "bold-italic" all resolve to the same style.
If Text.weight or Text.italic are explicitly assigned, they will override any weight or italic axis value in preferredStyle.
Since
Lens Scripting Version 372
Default Value
FontStyles.Regular
renderOrder
renderOrder:
number
The order in which the visual should be rendered.
Since
Lens Scripting Version 323
Default Value
0
Inherited from
sceneObject
readonlysceneObject:SceneObject
The SceneObject this component is on.
Inherited from
shadowColor
shadowColor:
vec4
Affects the color of shadows being cast by this MeshVisual. The color of the cast shadow is a mix between shadowColor and the material's base texture color. The alpha value of shadowColor controls the mixing of these two colors, with 0 = shadowColor and 1 = shadowColor * textureColor.
Default Value
(1, 1, 1, 1)
Inherited from
shadowDensity
shadowDensity:
number
Density of shadows cast by this MeshVisual.
Default Value
1
Inherited from
showEditingPreview
showEditingPreview:
boolean
Use this property to control whether to show the input preview the keyboard. Note this preview also enables cursor movement.
Since
Lens Scripting Version 170
Default Value
true
size
size:
number
Font size used. Minimum of 2.0 and maximum of 800.0.
size sets the em square height of the rendered text.
In world space, the em square height in centimeters is size / 43.886,
so the default size of 48 produces an em square ~1.09 cm tall.
Under a Canvas in Pixels or Points mode, Text scales as though
the camera's orthographic size were the default 20 cm regardless of the
actual camera size. The em square is renderTargetHeightPoints * size / 877.71
points tall — about 39 points for the default size of 48 on a
render target 720 points tall. The pixel form is the same expression
with the render target height in pixels.
Default Value
48
sizeToFit
sizeToFit:
boolean
If enabled, the rendered text will always scale to fit the boundaries defined by ScreenTransform or Text#layoutRect, with the former taking precedence.
Default Value
false
stretchMode
stretchMode:
StretchMode
When a ScreenTransform is attached to the same SceneObject, this controls how the mesh will be stretched relative to the ScreenTransform's boundaries.
Default Value
StretchMode.Stretch
Inherited from
text
text:
string
Text string to be drawn.
Default Value
""
textFill
textFill:
TextFill
Settings for how the text is drawn, such as fill color or texture.
touchHandler
touchHandler:
InteractionComponent
Use this property to override the touch handling for when to open the device keyboard when the Text is editable.
Since
Lens Scripting Version 165
Default Value
null
twoSided
twoSided:
boolean
Whether the text should be visible in both front and back.
Since
Lens Scripting Version 274
Default Value
false
uniqueIdentifier
readonlyuniqueIdentifier:string
Since
Lens Scripting Version 176
Inherited from
BaseMeshVisual.uniqueIdentifier
verticalAlignment
verticalAlignment:
VerticalAlignment
When a ScreenTransform is attached to the same SceneObject, this controls how the mesh will be positioned vertically depending on stretchMode.
Default Value
VerticalAlignment.Center
Inherited from
BaseMeshVisual.verticalAlignment
verticalOverflow
verticalOverflow:
VerticalOverflow
Controls how text should be handled when it goes past the vertical boundaries defined by ScreenTransform or Text#layoutRect, with the former taking precedence.
Default Value
VerticalOverflow.Overflow
weight
weight:
number
Controls the font weight. Usually a multiple of 100 between 100 and 900 inclusively. Will use closest font weight available on the system.
When assigned as null, the weight axis from Text.preferredStyle is used instead. When explicitly assigned, Text.weight overrides any weight value in Text.preferredStyle.
Since
Lens Scripting Version 325
Default Value
null
Methods
destroy()
destroy():
void
Destroys the component.
Returns
void
Inherited from
getBoundingBox()
getBoundingBox(
start?,end?):Rect
Gets the bounding box encompassing the characters in the range from start to end. The range is inclusive of start and exclusive of end.
Parameters
| Parameter | Type |
|---|---|
start? | number |
end? | number |
Returns
Since
Lens Scripting Version 316
getCursorHeight()
getCursorHeight():
number
Returns the recommended height for a cursor visual, in the same coordinate space as getCursorPositions(). The height is derived from the font size and accounts for scaling (e.g. VerticalOverflow.Shrink or sizeToFit).
Returns
number
Since
Lens Scripting Version 361
getCursorPositions()
getCursorPositions():
CursorPosition[]
Returns a list of cursor positions for each character in the current text. Not supported when rich text is enabled.
Returns
Since
Lens Scripting Version 324
getHighlightRects()
getHighlightRects(
start?,end?):Rect[]
Returns a list of rectangles highlighting the characters in the range from start to end.
Each rectangle covers one contiguous visual run of text within the range, so a single line
with mixed text directions may produce multiple rectangles. The range is inclusive of start
and exclusive of end.
Parameters
| Parameter | Type |
|---|---|
start? | number |
end? | number |
Returns
Rect[]
Since
Lens Scripting Version 362
getRenderOrder()
getRenderOrder():
number
Returns the order of this Visual in the render queue.
Returns
number
Inherited from
getSceneObject()
getSceneObject():
SceneObject
Returns the SceneObject the component is attached to.
Returns
Inherited from
getTransform()
getTransform():
Transform
Returns the Transform this component is attached to.
Returns
Inherited from
getTypeName()
staticgetTypeName():TypeName<Text>
Returns the fully-qualified JavaScript type name for this class (for example, "Component.Camera"). This is a static accessor (no instance required) and returns the same value as the instance getTypeName().
Returns
TypeName<Text>
Overrides
getTypeName()
getTypeName():
string
Returns the name of this object's type.
Returns
string
Inherited from
isOfType()
isOfType(
type):boolean
Returns true if the object matches or derives from the passed in type.
Parameters
| Parameter | Type |
|---|---|
type | string |
Returns
boolean
Inherited from
isSame()
isSame(
other):boolean
Returns true if this object is the same as other. Useful for checking if two references point to the same thing.
Parameters
| Parameter | Type |
|---|---|
other | ScriptObject |
Returns
boolean
Inherited from
localAabbMax()
localAabbMax():
vec3
Range maximum of the local-space axis-aligned bounding box (AABB) of the visual.
Returns
Since
Lens Scripting Version 156
Inherited from
localAabbMin()
localAabbMin():
vec3
Range minimum of the local-space axis-aligned bounding box (AABB) of the visual.
Returns
Since
Lens Scripting Version 156
Inherited from
setRenderOrder()
setRenderOrder(
value):void
Sets the order of this Visual in the render queue.
Parameters
| Parameter | Type |
|---|---|
value | number |
Returns
void
Inherited from
snap()
snap(
camera):void
Projects screen positions from camera's view onto the mesh's UVs.
If the MeshVisual's material uses the same texture as the camera input, the MeshVisual will look identical to the part of the screen it covers.
Parameters
| Parameter | Type |
|---|---|
camera | Camera |
Returns
void
Inherited from
worldAabbMax()
worldAabbMax():
vec3
Range maximum of the world-space axis-aligned bounding box (AABB) of the visual.
Returns
Since
Lens Scripting Version 156
Inherited from
worldAabbMin()
worldAabbMin():
vec3
Range minimum of the world-space axis-aligned bounding box (AABB) of the visual.
Returns
Since
Lens Scripting Version 156
Inherited from
See also
Text guide.