Skip to main content

<pc-element>

The <pc-element> tag is used to define an element component. Element components are the building blocks of user interfaces and come in three types — group, image, and text — selected with the type attribute. Which attributes apply depends on the type.

Usage
note

Image elements can render a sprite (including 9-sliced sprites, via a sliced <pc-asset>) or a texture, and can act as a mask to clip their descendants. Only text elements require a font asset.

Attributes

AttributeTypeDefaultDescription
anchorVector4"0 0 0 1"Sets the element's anchor as left bottom right top relative to its parent. Each value ranges from 0 to 1. [0,0,0,0] anchors to the bottom-left; [1,1,1,1] anchors to the top-right. If left≠right or bottom≠top (a split anchor), the element resizes to cover that area, e.g. [0,0,1,1] fills the parent.
assetString-Font asset ID (must reference a font type asset). Required for text elements only
auto-fit-heightFlag-Reduce the font size (down to min-font-size) so text fits the element's height. Requires auto-height="false". Text elements only
auto-fit-widthFlag-Reduce the font size (down to min-font-size) so text fits the element's width. Requires auto-width="false". Text elements only
auto-heightBoolean"true"Whether to automatically adjust height to fit text content. Text elements only
auto-widthBoolean"true"Whether to automatically adjust width to fit text content. Text elements only
colorColor"1 1 1 1"Color as space-separated RGBA values, hex code, or named color
enabledBoolean"true"Enabled state of the component
enable-markupFlag-Enables markup processing for styled text. Supports tags like [color="#ff0000"]text[/color] for colored text.
font-sizeNumber"32"Font size in pixels
heightNumber"0"Height in pixels (0 for auto-sizing)
line-heightNumber"32"Line height in pixels
marginVector4-Insets the element from a split (stretched) anchor as left bottom right top. For point anchors, width/height govern size instead
maskFlag-Whether the element clips its descendants to its bounds. Image elements only
max-font-sizeNumber"32"Largest font size used when auto-fitting
min-font-sizeNumber"8"Smallest font size used when auto-fitting
opacityNumber"1"Opacity, from 0 (transparent) to 1 (opaque)
pivotVector2"0.5 0.5"Pivot point as "X Y" values
pixels-per-unitNumber-Pixels per unit used when rendering a sprite. Image elements only
sprite-assetString-Sprite <pc-asset> ID to render. Image elements only
sprite-frameNumber"0"Frame index of the sprite to render. Image elements only
textString-Text content to display
texture-assetString-Texture <pc-asset> ID to render. Image elements only
typeEnum"group"Element type: "group" | "image" | "text"
use-inputFlag-Whether the element receives pointer input. Required for <pc-button> and scroll-view interaction
widthNumber"0"Width in pixels (0 for auto-sizing)
wrap-linesFlag-Whether to wrap text lines

Example

<pc-entity>
<pc-element type="text" asset="arial" text="Hello, World!"></pc-element>
</pc-entity>

JavaScript Interface

You can programmatically create and manipulate <pc-element> elements using the ElementComponentElement API.