# SUIText

## Index

### Properties Index

| Property Name                                                      |
| ------------------------------------------------------------------ |
| bool [**SupportRichText** ](#supportrichtext)`get` `set`           |
| bool [**ResizeTextForBestFit** ](#resizetextforbestfit)`get` `set` |
| int [**ResizeTextMinSize** ](#resizetextminsize)`get` `set`        |
| int [**ResizeTextMaxSize** ](#resizetextmaxsize)`get` `set`        |
| bool [**AlignByGeometry** ](#alignbygeometry)`get` `set`           |
| int [**FontSize** ](#fontsize)`get` `set`                          |
| float [**LineSpacing** ](#linespacing)`get` `set`                  |
| float [**PixelsPerUnit** ](#pixelsperunit)`get`                    |
| float [**MinWidth** ](#minwidth)`get`                              |
| float [**PreferredWidth** ](#preferredwidth)`get`                  |
| float [**FlexibleWidth** ](#flexiblewidth)`get`                    |
| float [**MinHeight** ](#minheight)`get`                            |
| float [**PreferredHeight** ](#preferredheight)`get`                |
| float [**FlexibleHeight** ](#flexibleheight)`get`                  |
| int [**LayoutPriority** ](#layoutpriority)`get`                    |
| bool [**Enabled** ](#enabled)`get` `set`                           |
| string [**Text** ](#text)`get` `set`                               |
| SColor [**Color** ](#color)`get` `set`                             |
| SGameObject [**GameObject** ](#gameobject)`get`                    |

## Properties

### SupportRichText

bool **SupportRichText** `get` `set`

*Whether this Text will support rich text.*&#x20;

{% tabs %}
{% tab title="Lua" %}

```lua
 Space.Host.ExecutingObject.UIText.SupportRichText = true 
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

```lua
--the below script will make a UIToggle disable/enable Rich Text support in the UIText
--[Add "toggle" and "text" references to the Scripting Runtime component]

thisGameObject = Space.Host.ExecutingObject

toggle = Space.Host.GetReference("toggle").UIToggle 
text = Space.Host.GetReference("text").UIText 
text.Text = "<b> Bold Test </b>"
OVC = function()
  if toggle.IsOn then
    text.SupportRichText = true
  else
    text.SupportRichText = false
  end
end

toggle.OnValueChanged(OVC)
```

{% endtab %}
{% endtabs %}

### ResizeTextForBestFit

bool **ResizeTextForBestFit** `get` `set`

*Should the text be allowed to auto resized.*

{% tabs %}
{% tab title="Lua" %}

```lua
 Space.Host.ExecutingObject.UIText.ResizeTextForBestFit = false 
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

```lua
--the below script will make a UIToggle disable/enable the Best Fit feature in the UIText
--[Add "toggle" and "text" references to the Scripting Runtime component]

thisGameObject = Space.Host.ExecutingObject

toggle = Space.Host.GetReference("toggle").UIToggle 
text = Space.Host.GetReference("text").UIText 
text.Text = "A very long text a very long text a very long text a very long text"
OVC = function()
  if toggle.IsOn then
    text.ResizeTextForBestFit = true
  else
    text.ResizeTextForBestFit = false
  end
end

toggle.OnValueChanged(OVC)
```

{% endtab %}
{% endtabs %}

### ResizeTextMinSize

int **ResizeTextMinSize** `get` `set`

*The minimum size the text is allowed to be.*

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.UIText.ResizeTextMinSize = 20
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

```lua
--the below script will make a slider change the UIText's Best Fit Min Size
--[Add "slider" and "text" references to the Scripting Runtime component]

thisGameObject = Space.Host.ExecutingObject

slider = Space.Host.GetReference("slider").UISlider
text = Space.Host.GetReference("text").UIText 
text.Text = "Best Fit Min Size"
text.ResizeTextForBestFit = true

OVC = function()
text.ResizeTextMinSize  = (slider.Value * 20) + 10 -- from 10 to 30
end

slider.OnValueChanged(OVC) 
```

{% endtab %}
{% endtabs %}

### ResizeTextMaxSize

int **ResizeTextMaxSize** `get` `set`

*The maximum size the text is allowed to be.*

{% tabs %}
{% tab title="Lua" %}

```lua
 Space.Host.ExecutingObject.UIText.ResizeTextMaxSize = 150
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

```lua
--the below script will make a slider change the UIText's Best Fit Max Size
--[Add "slider" and "text" references to the Scripting Runtime component]

thisGameObject = Space.Host.ExecutingObject

slider = Space.Host.GetReference("slider").UISlider
text = Space.Host.GetReference("text").UIText 
text.Text = "Best Fit Max Size"
text.ResizeTextForBestFit = true

OVC = function()
text.ResizeTextMaxSize  = (slider.Value * 50) + 20 -- from 50 to 70
end

slider.OnValueChanged(OVC) 
```

{% endtab %}
{% endtabs %}

### AlignByGeometry

bool **AlignByGeometry** `get` `set`

*Use the range of glyph geometry to perform horizontal alignment.*

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.UIText.AlignByGeometry = true
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

```lua
--the below script will make a UIToggle disable/enable the Align By Geometry feature in the UIText
--[Add "toggle" and "text" references to the Scripting Runtime component]

thisGameObject = Space.Host.ExecutingObject

toggle = Space.Host.GetReference("toggle").UIToggle 
text = Space.Host.GetReference("text").UIText 
text.Text = "Align By Geometry"
OVC = function()
  if toggle.IsOn then
    text.AlignByGeometry  = true
  else
    text.AlignByGeometry  = false
  end
end

toggle.OnValueChanged(OVC)
```

{% endtab %}
{% endtabs %}

### FontSize

int **FontSize** `get` `set`

*The size that the Font should render at.*

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.UIText.FontSize = 54
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

```lua
--the below script will make a slider change the UIText's Font Size
--[Add "slider" and "text" references to the Scripting Runtime component]

thisGameObject = Space.Host.ExecutingObject

slider = Space.Host.GetReference("slider").UISlider
text = Space.Host.GetReference("text").UIText 
text.Text = "Text Size Test"

OVC = function()
text.FontSize  = (slider.Value * 40) + 10 -- from 10 to 50
end

slider.OnValueChanged(OVC)
```

{% endtab %}
{% endtabs %}

### LineSpacing

float **LineSpacing** `get` `set`

*How much space will be in-between lines of text. This is a multiplier. The line spacing value set will be multiplied by the font's internal line spacing. A value of 1 will produce normal line spacing.*

{% tabs %}
{% tab title="Lua" %}

```lua
thisObject = Space.Host.ExecutingObject.UIText.LineSpacing = 2
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

```lua
--the below script will make a slider change the UIText's Line Spacing
--[Add "slider" and "text" references to the Scripting Runtime component]

thisGameObject = Space.Host.ExecutingObject

slider = Space.Host.GetReference("slider").UISlider
text = Space.Host.GetReference("text").UIText 
text.Text = "Line Spacing Line Spacing Line Spacing Line Spacing Line Spacing"

OVC = function()
text.LineSpacing  = (slider.Value * 2) -- from 0 to 2
end

slider.OnValueChanged(OVC) 
```

{% endtab %}
{% endtabs %}

### PixelsPerUnit

float **PixelsPerUnit** `get`

*Provides information about how fonts are scale to the screen.*

*For dynamic fonts, the value is equivalent to the scale factor of the canvas. For non-dynamic fonts, the value is calculated from the requested text size and the size from the font.*

{% tabs %}
{% tab title="Lua" %}

```lua
thisObject = Space.Host.ExecutingObject
 --get a reference to our object
thisObjectText = thisObject.UIText
 --get a reference to the UIText component in our object 

Space.Log(thisObjectText.PixelsPerUnit)
--Prints the PixelsPerUnit value of this UIText component to the console
```

{% endtab %}
{% endtabs %}

### MinWidth

float **MinWidth** `get`

*The minimum width this UIText may be allocated. (Used by the Layout system).*

{% tabs %}
{% tab title="Lua" %}

```lua
thisObject = Space.Host.ExecutingObject
 --get a reference to our object
thisObjectText = thisObject.UIText
 --get a reference to the UIText component in our object 
 
Space.Log(thisObjectText.MinWidth)
--Prints the MinWidth value of this UIText component to the console
```

{% endtab %}
{% endtabs %}

### PreferredWidth

float **PreferredWidth** `get`

*The preferred width this UIText should be allocated if there is sufficient space. (Used by the Layout system)*

{% tabs %}
{% tab title="Lua" %}

```lua
pWidth = Space.Host.ExecutingObject.UIText.PreferredWidth
```

{% endtab %}
{% endtabs %}

### FlexibleWidth

float **FlexibleWidth** `get`

*The extra relative width this UIText should be allocated if there is additional available space. (Used by the Layout system)*

{% tabs %}
{% tab title="Lua" %}

```lua
FlexibleWidth = Space.Host.ExecutingObject.UIText.FlexibleWidth 
```

{% endtab %}
{% endtabs %}

### MinHeight

float **MinHeight** `get`

*The minimum height this UIText may be allocated.(Used by the Layout system).*

{% tabs %}
{% tab title="Lua" %}

```lua
minHeight = Space.Host.ExecutingObject.UIText.MinHeight
```

{% endtab %}
{% endtabs %}

### PreferredHeight

float **PreferredHeight** `get`

*The preferred height this UIText should be allocated if there is sufficient space. (Used by the Layout system)*

{% tabs %}
{% tab title="Lua" %}

```lua
pHeight = Space.Host.ExecutingObject.UIText.PreferredHeight
```

{% endtab %}
{% endtabs %}

### FlexibleHeight

float **FlexibleHeight** `get`

*The extra relative height this UIText should be allocated if there is additional available space. (Used by the Layout system.)*

{% tabs %}
{% tab title="Lua" %}

```lua
FlexibleHeight = Space.Host.ExecutingObject.UIText.FlexibleHeight
```

{% endtab %}
{% endtabs %}

### LayoutPriority

int **LayoutPriority** `get`

*The layout priority of this UIText component.(Used by the Layout system.)*

{% tabs %}
{% tab title="Lua" %}

```lua
layoutPriority = Space.Host.ExecutingObject.UIText.LayoutPriority
```

{% endtab %}
{% endtabs %}

### Enabled

bool **Enabled** `get` `set`

*Whether the UIText component is Enabled or not will decide if it is visually updating or not.*

{% tabs %}
{% tab title="Lua" %}

```lua
 Space.Host.ExecutingObject.UIText.Enabled = true
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

```lua
--this below script will make clicking this object disable/enable a UIText component

thisGameObject = Space.Host.ExecutingObject

text = Space.Host.GetReference("text").UIText
 
OnClick = function()

  if text.Enabled then
    text.Enabled = false
  else
    text.Enabled = true
  end
  
end

thisGameObject.AddClickable()
thisGameObject.Clickable.Tooltip = "click to hide/show text"
thisGameObject.Clickable.OnClick(OnClick)
```

{% endtab %}
{% endtabs %}

### Text

string **Text** `get` `set`

*The string value this Text displays.*

{% tabs %}
{% tab title="Lua" %}

```lua
 Space.Host.ExecutingObject.UIText.Text = "Hello World!" 
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

```lua
--the below script will make a UIText element with this script
--constantly update itself to show the local time
--(Example: UI Text element that shows local clock)
--[This object needs to be a UI Text object. In Unity, Heirarchy -> Create -> UI -> Text]
--<Note: UI Text element could also be in world space if it's canvas is a world space canvas>

thisGameObject = Space.Host.ExecutingObject

OnUpdate = function()
thisGameObject.UIText.Text = Space.LocalTime
end

thisGameObject.SubscribeToEvents()
thisGameObject.OnUpdate(OnUpdate)
```

{% endtab %}
{% endtabs %}

### Color

[SColor](https://docs.breakroom.tech/scripting/client-scripting-api-reference/types/scolor) **Color** `get` `set`

*Base color of the Graphic.*

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.UIText.Color = Color.Red
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

```lua
--This script dynamically changes the text's color of a GameObject with UIText component.
--For example in a text sign over your shop that you want to make more visually stand out
--or perhaps text decoration during a celebration or a text element in your User Interface or HUD.

thisObject = Space.Host.ExecutingObject
 --get a reference to our object
thisObjectText = thisObject.UIText
 --get a reference to the SUIText component in our object 
colors = {Color.Red, Color.Black, Color.White, Color.Blue, Color.Green, Color.Yellow}
 --here we are holding 6 predefined colors in a Lua Table which we will go through


function ColorChanger()

    while true do
    --infinite loop
    
        for i=1,#colors do
        --For Loop to cycle through all the table items
        thisObjectText.color = colors[i] 
        --this will set the color based on which item in the table we are now at
        coroutine.yield(0.1)
        --this will pause for a tenth of a second before we change to the next color
        end

    end
end


Space.Host.StartCoroutine(ColorChanger) 
--this coroutine will now call our ColorChanger() function which is infinitely changing our text colors between a select range. 
```

{% endtab %}
{% endtabs %}

### GameObject

[SGameObject](https://docs.breakroom.tech/scripting/client-scripting-api-reference/types/sgameobject) **GameObject** `get`

*Property Description*

{% tabs %}
{% tab title="Lua" %}

```lua
theGameObject = Space.Host.ExecutingObject.UIText.Text
```

{% endtab %}
{% endtabs %}
