# Text

## Introduction

Text objects have a Text property which controls the displayed text. By default this value is set to "Hello".

## Changing Text

The Text property can be changed in the multi-line edit window.

![](https://2695663588-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fzQmxQ1VeUFHcoo2c%2Fuploads%2Fgit-blob-6b2a6ab6f47098d141a028c3d2078ae7de1cb1f0%2FGumIsAwesome.png?alt=media)

Text will wrap according to the Text object's Width.

![](https://2695663588-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fzQmxQ1VeUFHcoo2c%2Fuploads%2Fgit-blob-d3c4d14cdae3ba93bbd0a8b0cbf0e3e44ad967a9%2FLineWrappingTextGum.png?alt=media)

The enter key can be used to add new lines to text.

![](https://2695663588-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fzQmxQ1VeUFHcoo2c%2Fuploads%2Fgit-blob-6bcacadfc7ca27c1031bbf356fc585f0aa76e88b%2FNewlinesGum.png?alt=media)

## Text Wrapping

Text instances can optionally wrap their text based on width units. By default Text instances use a `Width Units` of `Relative to Children` which means the text does not wrap.

<figure><img src="https://2695663588-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fzQmxQ1VeUFHcoo2c%2Fuploads%2Fgit-blob-8da68e949e037b304d95b56189b3d94a18d90df7%2F22_13%2034%2003.png?alt=media" alt=""><figcaption><p>Width Units of Relative to Children</p></figcaption></figure>

This Width Units results in the Text automatically resizing itself in response to its Text variable, resulting in no wrapping.

<figure><img src="https://2695663588-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fzQmxQ1VeUFHcoo2c%2Fuploads%2Fgit-blob-d27d0706d44cf6cd0091023c094ce88a4073e861%2F22_13%2038%2051.gif?alt=media" alt=""><figcaption><p>Changing the Text results in making the Text instance wider and does not wrap</p></figcaption></figure>

Any other `Width Unit` can be used to make the text wrap. For example, setting `Width Units` to `Absolute` and changing `Width` results in wrapping.

<figure><img src="https://2695663588-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fzQmxQ1VeUFHcoo2c%2Fuploads%2Fgit-blob-c149a1880edf8b34d059d1fb6e3eff5f8b4b34d4%2F22_13%2041%2057.gif?alt=media" alt=""><figcaption><p>Absolute Width can make Text wrap</p></figcaption></figure>

For a deeper dive into Width Units, see the [Width Units page](https://docs.flatredball.com/gum/gum-tool/gum-elements/general-properties/width-units).

## Using BBCode for Inline Styling

Gum text supports inline styling using BBCode-like syntax. To add inline styling, surround text with variable assignment tags as shown in the following screenshot:

<figure><img src="https://2695663588-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fzQmxQ1VeUFHcoo2c%2Fuploads%2Fgit-blob-1c4cc7878f7cf9d17bc185db60cdc30ac7275cfb%2Fimage%20(2)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1).png?alt=media" alt=""><figcaption><p>Red color using BBCode syntax</p></figcaption></figure>

The following table shows the available variables that can be used for inline styling:

<table><thead><tr><th width="129">Tag</th><th width="357">Example</th><th>Result</th></tr></thead><tbody><tr><td>Color</td><td>This is [Color=orange]orange[/Color] text.</td><td><img src="https://2695663588-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fzQmxQ1VeUFHcoo2c%2Fuploads%2Fgit-blob-b5b2e043549cb17cc5799459518e33820e3181e1%2FThisIsOrangeText.png?alt=media" alt="" data-size="original"></td></tr><tr><td>Red Green Blue</td><td>This is [Red=0][Green=128][Blue=255]light blue[/Red][/Green][/Blue] text.</td><td><img src="https://2695663588-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fzQmxQ1VeUFHcoo2c%2Fuploads%2Fgit-blob-0bd0467ab4d8f32746bb1ea6aa226b17fd32dbb3%2Fimage%20(2)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1).png?alt=media" alt="" data-size="original"></td></tr><tr><td>FontScale</td><td>This is [FontScale=2]big[/FontScale] text.</td><td><img src="https://2695663588-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fzQmxQ1VeUFHcoo2c%2Fuploads%2Fgit-blob-91450471bb379f1f5ff36e82bd22a87a00dff8bb%2Fimage%20(3)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1).png?alt=media" alt="" data-size="original"></td></tr><tr><td>IsBold</td><td>This is [IsBold=true]bold[/IsBold] text.</td><td><img src="https://2695663588-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fzQmxQ1VeUFHcoo2c%2Fuploads%2Fgit-blob-7455862b97ed5610cc3a8d1c5ec92d7736f80f92%2Fimage%20(4)%20(1)%20(1)%20(1)%20(1)%20(1).png?alt=media" alt="" data-size="original"></td></tr><tr><td>IsItalic</td><td>This is [IsItalic=true]italic[/IsItalic] text.</td><td><img src="https://2695663588-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fzQmxQ1VeUFHcoo2c%2Fuploads%2Fgit-blob-7249f28f4b9d244796624a545a6ef7affa830680%2Fimage%20(6)%20(1)%20(1)%20(1).png?alt=media" alt="" data-size="original"></td></tr><tr><td>Font</td><td>This is [Font=Papyrus]Papyrus[/Font] text.</td><td><img src="https://2695663588-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fzQmxQ1VeUFHcoo2c%2Fuploads%2Fgit-blob-67d4e1b97e75889f168219be6fe0362762f78bc6%2Fimage%20(7)%20(1)%20(1)%20(1).png?alt=media" alt="" data-size="original"></td></tr><tr><td>FontSize</td><td>This is [FontSize=36]bigger[/FontSize] text.</td><td><img src="https://2695663588-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fzQmxQ1VeUFHcoo2c%2Fuploads%2Fgit-blob-b2b8fc65bebd440a474bc010cc4325e1c272d8b6%2FThisIsBiggerText.png?alt=media" alt="" data-size="original"></td></tr><tr><td>OutlineThickness</td><td>This is [OutlineThickness=2]outlined[/OutlineThickness] text.</td><td><img src="https://2695663588-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fzQmxQ1VeUFHcoo2c%2Fuploads%2Fgit-blob-540f634238bbf3b02250d310cd6bf7e5a5564278%2Fimage%20(8)%20(1)%20(1)%20(1).png?alt=media" alt="" data-size="original"></td></tr></tbody></table>

Note that changing Font and FontSize results in new Fonts created in the Font Cache.

BBCode can span multiple lines, whether the newlines happen due to line wrapping or through the addition of newlines in the text.

<figure><img src="https://2695663588-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fzQmxQ1VeUFHcoo2c%2Fuploads%2Fgit-blob-75935b3b14f71d1ef35be63d4e9992e11b327254%2FMultiLineStyledText.png?alt=media" alt=""><figcaption><p>Text object with inline styling and explicit line breaks</p></figcaption></figure>

Multiple tags can overlap each other allowing you to combine tags for a single piece of text. For example, the following sets text to both bold and orange:

```bbcode
This is [Color=Orange][IsBold=true]bold and orange[/Color][/IsBold] text.
```

<figure><img src="https://2695663588-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fzQmxQ1VeUFHcoo2c%2Fuploads%2Fgit-blob-b224a7a4bd7b5de0cbe73e9c8cbeda375d1f2b82%2FBoldAndOrangeText.png?alt=media" alt=""><figcaption><p>Styled text that is bold and orange.</p></figcaption></figure>

Styles can contain other styles as many levels deep as necessary.

```bbcode
This [Color=Orange]is orange, [IsBold=true]bold[/IsBold], and [IsItalic=true]italic[/IsItalic][/Color] text.    
```

<figure><img src="https://2695663588-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fzQmxQ1VeUFHcoo2c%2Fuploads%2Fgit-blob-58d8cf46292fa37bf31fe84844814e78fe45b46c%2Fimage%20(2)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1).png?alt=media" alt=""><figcaption></figcaption></figure>

### BBCode Color and Alpha

Color values can be specified using named colors or individual Red, Green, and Blue values.

Color values can be specified using any of the standard XNA color values, as listed here: <https://docs.monogame.net/api/Microsoft.Xna.Framework.Color.html>

{% hint style="info" %}
MonoGame adds `MonoGameOrange` which is not available in other XNA-likes such as KNI and FNA. Gum UI uses KNI for rendering, so this property is not available in the Gum UI tool, but is available at runtime if you are using MonoGame.
{% endhint %}

If you need precise color values, then you should use the individual Red, Green, and Blue values.

Keep in mind that if a color value is not specified, then the default for that Text instance is used.

For example, a Text's Red may have Red, Green, Blue values of 255, 0, 0 as shown in the following image:

<figure><img src="https://2695663588-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fzQmxQ1VeUFHcoo2c%2Fuploads%2Fgit-blob-06aa043f5ae577b3a516b3f6ecf6254fb567eb0c%2F17_06%2039%2050.png?alt=media" alt=""><figcaption><p>Text with explicitly set Red, Green, and Blue values</p></figcaption></figure>

If its Green value is set in BBCode, the green value from BBCode overrides the Green variable value, but the Red and Blue values from its variables persist. BBCode values are applied after all variables.

<figure><img src="https://2695663588-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fzQmxQ1VeUFHcoo2c%2Fuploads%2Fgit-blob-8f3a7175a377a6171d19a20fc183957736a1fdba%2F17_06%2041%2038.png?alt=media" alt=""><figcaption><p>Green value of 200 overriding the default value of 0</p></figcaption></figure>

Similarly, if a Color tag is used, then the BBCode color specified overrides all color variable values. This includes Red, Green, Blue, and Alpha. The following image is a yellow text with an Alpha value of 15, resulting in text that is almost completely transparent:

<figure><img src="https://2695663588-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fzQmxQ1VeUFHcoo2c%2Fuploads%2Fgit-blob-1875ef3fb50a5b094ba1b2c3cea361141457007c%2F17_06%2045%2000.png?alt=media" alt=""><figcaption><p>Yellow text with an alpha of 15</p></figcaption></figure>

By specifying a Color value in BBCode, the Alpha value is also overwritten, as shown in the following image:

<figure><img src="https://2695663588-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fzQmxQ1VeUFHcoo2c%2Fuploads%2Fgit-blob-11a8a4b04de8b17b7a0e2ec55a3209072bc13c1a%2F17_06%2046%2018.png?alt=media" alt=""><figcaption><p>Green overrides Alpha</p></figcaption></figure>

To preserve alpha, the individual Red, Green, and Blue values must be specified.

<figure><img src="https://2695663588-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fzQmxQ1VeUFHcoo2c%2Fuploads%2Fgit-blob-09644c7c6de705ca93effc81193d06ca682deffd%2F17_06%2048%2013.png?alt=media" alt=""><figcaption><p>Specifying only Red, Green, and Blue preserves the previously-set Alpha value</p></figcaption></figure>
