# TextRuntime

## Introduction

The TextRuntime object is used to draw strings to the screen. It supports a variety of options for rendering text including alignment, fonts, coloring, and line wrapping.

A TextRuntime are often used in the following situations:

1. Adding diagnostics to your game to easily display information on screen
2. Adding visuals to a Forms control, such as adding another label to a Button
3. Modifying Visuals, such as a TextInstance in a ButtonVisual

TextRuntime corresponds to the Text type in the Gum UI tool, and shares all of the same properties. For more information see the [Text](/gum/gum-tool/gum-elements/text/text.md) page.

## Example - Creating a TextRuntime

To create a TextRuntime, instantiate it and add it to root as shown in the following code:

```csharp
// Initialize
var textInstance = new TextRuntime();
textInstance.Text = "Hello world";
textInstance.AddToRoot();
```

<figure><img src="/files/PBJFRRLzQe7qUgAlaSER" alt=""><figcaption><p>Text</p></figcaption></figure>

TextRuntimes can be added as children of controls. For example, the following code shows how to create a TextRuntime and add it to a Stackpanel named MainStackPanel.

```csharp
// Initialize
var textInstance = new TextRuntime();
textInstance.Text = "Hello world";
MainStackPanel.AddChild(textInstance);
```

## Example - Obtaining an Existing TextRuntime

TextRuntimes are used in Gum Forms controls for all Text display. For example, Button instanes use a TextRuntime named TextInstace, as shown in the following code block:

```csharp
// Initialize
var button = new Button();
var buttonVisual = (ButtonVisual)button.Visual;
var textRuntime = buttonVisual.TextInstance;
textRuntime.FontScale = 2;
// additional modifications can be made to textRuntime
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.flatredball.com/gum/code/standard-visuals/textruntime.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
