Class Text
A versatile text component that displays text content with customizable size and styling options.
Inheritance
Implements
Inherited Members
Namespace: Unity.AppUI.UI
Assembly: Unity.AppUI.dll
Syntax
[UxmlElement]
public sealed class Text : LocalizedTextElement, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IVisualElementScheduler, IBindable, INotifyValueChanged<string>, ITextEdition, ITextElementExperimentalFeatures, IExperimentalFeatures, ITextSelection, IContextOverrideElement, IAdditionalDataHolder
Remarks
The Text component is a fundamental UI element used to display text content in your application. It provides a range of size options and styling variants to help maintain consistency and hierarchy in your text presentation.
Text components come with eight predefined sizes (from XXS to XXXL) and support primary/secondary variants to establish visual hierarchy. The component is also localization-ready, inheriting from LocalizedTextElement.
The Text component supports both UXML attributes and runtime property modification, making it flexible for both declarative and programmatic UI development.
Examples
Here's an example of creating a typical text hierarchy using different sizes and variants: Creating a text hierarchy in UXML.
<UXML xmlns="UnityEngine.UIElements">
<Text text="Main Heading" size="XXL" />
<Text text="Subheading" size="XL" primary="false" />
<Text text="Body text goes here with a medium size." size="M" />
<Text text="Small caption text" size="XS" primary="false" />
</UXML>
For runtime text manipulation: Creating and managing text elements via code.
// Create text elements
var container = new VisualElement();
// Add a title
var title = new Text("Welcome!") ;
container.Add(title);
// Add a subtitle
var subtitle = new Text("Please read the following instructions") ;
container.Add(subtitle);
// Add body text
var body = new Text("Detailed instructions go here...") ;
container.Add(body);
Constructors
Text()
Default constructor.
Declaration
public Text()
Text(string)
Construct a Text UI element and use the provided text as display text.
Declaration
public Text(string text)
Parameters
| Type | Name | Description |
|---|---|---|
| string | text | The text that will be displayed. |
Fields
primaryUssClassName
The Text primary variant styling class.
Declaration
public const string primaryUssClassName = "appui-text--primary"
Field Value
| Type | Description |
|---|---|
| string |
sizeUssClassName
The Text size styling class.
Declaration
public const string sizeUssClassName = "appui-text--size-"
Field Value
| Type | Description |
|---|---|
| string |
ussClassName
The Text main styling class.
Declaration
public const string ussClassName = "appui-text"
Field Value
| Type | Description |
|---|---|
| string |
Properties
primary
The primary variant of the text.
Declaration
[CreateProperty]
[UxmlAttribute]
public bool primary { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
size
The size of the text.
Declaration
[CreateProperty]
[UxmlAttribute]
public TextSize size { get; set; }
Property Value
| Type | Description |
|---|---|
| TextSize |
Methods
GetSizeUssClassName(TextSize)
Declaration
public static string GetSizeUssClassName(TextSize enumValue)
Parameters
| Type | Name | Description |
|---|---|---|
| TextSize | enumValue |
Returns
| Type | Description |
|---|---|
| string |