Catlike Coding
Unity Code Documentation
Public Member Functions | Public Attributes | Properties | List of all members
CatlikeCoding.TextBox.TextBox Class Reference

Text Box component. Uses child objects to render the text. More...

Inherits MonoBehaviour.

Public Member Functions

bool GetCharInfo (Vector3 point, out TextBoxCharInfo charInfo)
 Get information about the character at a world-space point, if it exists. More...
 
TextBoxCursorInfo GetCursorInfoForCharIndex (int index)
 Get cursor info for a character index. More...
 
TextBoxCursorInfo GetCursorInfoForLine (int lineIndex, float horizontalOffset)
 Get cursor information for an offset on a specific line. More...
 
TextBoxCursorInfo GetCursorInfoForPoint (Vector2 point)
 Get cursor info for a point. More...
 
TextBoxCursorInfo GetCursorInfoForUnstyledCharIndex (int unstyledIndex)
 Get cursor info for an unstyled character index, which ignores meta statements. More...
 
void GetInnermostMetaTag (Vector3 point, StringBuilder charContainer)
 Get the contents of the innermost meta tag that encloses a world-space point. More...
 
void GetInnermostMetaTag (int index, StringBuilder charContainer)
 Get the contents of the innermost meta tag that encloses a character index. More...
 
string GetInnermostMetaTag (Vector3 point)
 Get the contents of the innermost meta tag that encloses a world-space point. More...
 
string GetInnermostMetaTag (int index)
 Get the contents of the innermost meta tag that encloses a character index. More...
 
float GetLeftContour (float height)
 Get the left contour offset of the box at a specific height. More...
 
TextBoxLine GetLineInfo (int index)
 Get information about a line. More...
 
float GetRightContour (float height)
 Get the right contour offset of the box at a specific height. More...
 
TextRenderer GetTextRenderer (int index)
 Get one of the text renderers used by this box. More...
 
void GetVisibleCharSequence (Vector3 point, StringBuilder charContainer)
 Get the sequence of visible characters around a world-space point. Whitespace and meta characters stop the sequence. More...
 
void GetVisibleCharSequence (int index, StringBuilder charContainer)
 Get the sequence of visible characters around a character index. Whitespace and meta characters stop the sequence. More...
 
string GetVisibleCharSequence (Vector3 point)
 Get the sequence of visible characters around a world-space point. Whitespace and meta characters stop the sequence. More...
 
string GetVisibleCharSequence (int index)
 Get the sequence of visible characters around a character index. Whitespace and meta characters stop the sequence. More...
 
void RenderText ()
 Call this after making any changes to the box to update what's being rendered. The entire text box chain will be refreshed. More...
 
void ResetTextRenderers ()
 Force text renderers to be recreated during the next text update. Used in the editor. More...
 
void SetText (StringBuilder text)
 Set the text of the box using a StringBuilder. More...
 
void SetText (string text)
 Set the text of the box using a string. Try to use a StringBuilder when working with dynamic text. More...
 

Public Attributes

AlignmentMode alignment
 How text is aligned inside the box. More...
 
float boundsBottom
 Local bottom bounds of the box. Defined by anchor, width, and used height. Updated when text is rendered. More...
 
float boundsLeft
 Local left bounds of the box. Defined by anchor, width, and used height. Updated when text is rendered. More...
 
float boundsRight
 Local right bounds of the box. Defined by anchor, width, and used height. Updated when text is rendered. More...
 
float boundsTop
 Local top bounds of the box. Defined by anchor, width, and used height. Updated when text is rendered. More...
 
int fitPrecision = 2
 Scaling precision used when shrinking to fit, in orders of magnitude. More...
 
HorizontalAnchorMode horizontalAnchor
 How the box is horizontally positioned, relative to its origin. More...
 
Vector2[] leftContour
 A series of points to shape the left contour that constrains where text is shown inside the box. More...
 
float maxHeight = 10f
 Maximum height allowed for the box. Text that won't fit will overflow to the next box or will not be renderered. More...
 
TextBox overflowBox
 Box to send overflowing text to. You can build a chain of these, just don't make it circular. More...
 
float paddingBottom
 Amount of padding to use at the bottom inside of the box. More...
 
float paddingLeft
 Amount of padding to use at the left inside of the box. More...
 
float paddingRight
 Amount of padding to use at the right inside of the box. More...
 
float paddingTop
 Amount of padding to use at the top inside of the box. More...
 
Vector2[] rightContour
 A series of points to shape the right contour that constrains where text is shown inside the box. More...
 
bool shrinkToFit
 Whether to automatically reduce the text scale to fit the text inside the box. More...
 
TextStyleCollection styleCollection
 Style collection that defines how text is shown. Required to render text. More...
 
bool styled = true
 Whether styling is used. If not, the raw text is rendered. More...
 
float textScale = 1f
 Text scale. Use this to adjust the size of all the text in the box without having to use a separate style collection. More...
 
Color tint = Color.white
 Color used to tint the text. This is multiplied with the style color. More...
 
VerticalAnchorMode verticalAnchor
 How the box is vertically positioned, relative to its origin. More...
 
float width = 10f
 Width of the box. Should be positive. More...
 

Properties

string DefaultText [get]
 Get the default text. Use SetText to change the text that's actually rendered. More...
 
float EffectiveTextScale [get]
 Get the effective text scale, which can be different than the normal text scale if shrink-to-fit is enabled. More...
 
bool IsOverFlowBox [get]
 Get whether this text box is used as an overflow box by another box. This can only be known after the other box has been rendered at least once. More...
 
int LineCount [get]
 Get the number of text lines currently being displayed. More...
 
TextBoxEventHandler Rendered
 Occurs after the text box has been rendered. When subscribing to this event, you will be called back immediately if the text box is already in a useful state. More...
 
float TabSize [get, set]
 Get or set the tab size, constrained to a minimum of 0.001. More...
 
Bounds TextRendererBounds [get]
 Get the combined bounds of all text renderers. More...
 
int TextRendererCount [get]
 Get the amount of text renderers used by this box. More...
 

Detailed Description

Text Box component. Uses child objects to render the text.

Member Function Documentation

bool CatlikeCoding.TextBox.TextBox.GetCharInfo ( Vector3  point,
out TextBoxCharInfo  charInfo 
)

Get information about the character at a world-space point, if it exists.

A character occupies a rectangle defined by its left and right sides and its line's top and bottom. The point is projected onto the 2D box to check which character it hits.

Returns
Whether there's a character at that point.
Parameters
pointPoint in world space.
charInfoInformation about the character.
TextBoxCursorInfo CatlikeCoding.TextBox.TextBox.GetCursorInfoForCharIndex ( int  index)

Get cursor info for a character index.

Returns
Cursor info.
Parameters
indexCharacter index, will be clamed to the text displayed by the box.
TextBoxCursorInfo CatlikeCoding.TextBox.TextBox.GetCursorInfoForLine ( int  lineIndex,
float  horizontalOffset 
)

Get cursor information for an offset on a specific line.

Returns
Cursor info.
Parameters
lineIndexLine index, will be clamped to the available lines.
horizontalOffsetHorizontal offset along the line.
TextBoxCursorInfo CatlikeCoding.TextBox.TextBox.GetCursorInfoForPoint ( Vector2  point)

Get cursor info for a point.

Returns
Cursor info.
Parameters
pointPoint.
TextBoxCursorInfo CatlikeCoding.TextBox.TextBox.GetCursorInfoForUnstyledCharIndex ( int  unstyledIndex)

Get cursor info for an unstyled character index, which ignores meta statements.

Returns
Cursor info.
Parameters
unstyledIndexUnstyled character index, will be clamed to the text displayed by the box.
void CatlikeCoding.TextBox.TextBox.GetInnermostMetaTag ( Vector3  point,
StringBuilder  charContainer 
)

Get the contents of the innermost meta tag that encloses a world-space point.

Nothing is appended if the index isn't enclosed by a meta tag.

The tag's contents will be appended to an existing StringBuilder, so no new strings are allocated.

Parameters
pointPoint in world space.
charContainerContainer that the tag's contents will be appended to.
void CatlikeCoding.TextBox.TextBox.GetInnermostMetaTag ( int  index,
StringBuilder  charContainer 
)

Get the contents of the innermost meta tag that encloses a character index.

Nothing is appended if the index isn't enclosed by a meta tag.

The tag's contents will be appended to an existing StringBuilder, so no new strings are allocated.

Parameters
indexText index.
charContainerContainer that the tag's contents will be appended to.
string CatlikeCoding.TextBox.TextBox.GetInnermostMetaTag ( Vector3  point)

Get the contents of the innermost meta tag that encloses a world-space point.

Results in the empty string if the point isn't enclosed by a meta tag.

This method allocates new strings, so it generates work for the garbage collector.

Parameters
pointPoint in world space.
string CatlikeCoding.TextBox.TextBox.GetInnermostMetaTag ( int  index)

Get the contents of the innermost meta tag that encloses a character index.

Results in the empty string if the index isn't enclosed by a meta tag.

This method allocates new strings, so it generates work for the garbage collector.

Parameters
indexText index.
float CatlikeCoding.TextBox.TextBox.GetLeftContour ( float  height)

Get the left contour offset of the box at a specific height.

Parameters
heightA height. Zero at the top, negative at the bottom.
TextBoxLine CatlikeCoding.TextBox.TextBox.GetLineInfo ( int  index)

Get information about a line.

Parameters
indexLine index. Query LineCount to stay within bounds.
float CatlikeCoding.TextBox.TextBox.GetRightContour ( float  height)

Get the right contour offset of the box at a specific height.

Parameters
heightA height. Zero at the top, negative at the bottom.
TextRenderer CatlikeCoding.TextBox.TextBox.GetTextRenderer ( int  index)

Get one of the text renderers used by this box.

The renderes are ordered according to the style collection used by the box. If no style collection is defined, null will be returned.

Parameters
indexIndex of the desired renderer.
void CatlikeCoding.TextBox.TextBox.GetVisibleCharSequence ( Vector3  point,
StringBuilder  charContainer 
)

Get the sequence of visible characters around a world-space point. Whitespace and meta characters stop the sequence.

Nothing is appended if there isn't a visible character at the supplied point.

The sequence will be appended to an existing StringBuilder, so no new strings are allocated.

Parameters
pointPoint in world space.
charContainerContainer that the sequence will be appended to.
void CatlikeCoding.TextBox.TextBox.GetVisibleCharSequence ( int  index,
StringBuilder  charContainer 
)

Get the sequence of visible characters around a character index. Whitespace and meta characters stop the sequence.

Nothing is appended if the character at the supplied index isn't visible.

The sequence will be appended to an existing StringBuilder, so no new strings are allocated.

Parameters
indexIndex somewhere inside the sequence.
charContainerContainer that the sequence will be appended to.
string CatlikeCoding.TextBox.TextBox.GetVisibleCharSequence ( Vector3  point)

Get the sequence of visible characters around a world-space point. Whitespace and meta characters stop the sequence.

Results in the empty string if there isn't a visible character at the supplied point.

This method allocates new strings, so it generates work for the garbage collector.

Parameters
pointPoint in world space.
string CatlikeCoding.TextBox.TextBox.GetVisibleCharSequence ( int  index)

Get the sequence of visible characters around a character index. Whitespace and meta characters stop the sequence.

Results in the empty string if the character at the supplied index isn't visible.

This method allocates new strings, so it generates work for the garbage collector.

Parameters
indexIndex somewhere inside the sequence.
void CatlikeCoding.TextBox.TextBox.RenderText ( )

Call this after making any changes to the box to update what's being rendered. The entire text box chain will be refreshed.

void CatlikeCoding.TextBox.TextBox.ResetTextRenderers ( )

Force text renderers to be recreated during the next text update. Used in the editor.

void CatlikeCoding.TextBox.TextBox.SetText ( StringBuilder  text)

Set the text of the box using a StringBuilder.

Parameters
textSome text.
void CatlikeCoding.TextBox.TextBox.SetText ( string  text)

Set the text of the box using a string. Try to use a StringBuilder when working with dynamic text.

Parameters
textSome text.

Member Data Documentation

AlignmentMode CatlikeCoding.TextBox.TextBox.alignment

How text is aligned inside the box.

float CatlikeCoding.TextBox.TextBox.boundsBottom

Local bottom bounds of the box. Defined by anchor, width, and used height. Updated when text is rendered.

float CatlikeCoding.TextBox.TextBox.boundsLeft

Local left bounds of the box. Defined by anchor, width, and used height. Updated when text is rendered.

float CatlikeCoding.TextBox.TextBox.boundsRight

Local right bounds of the box. Defined by anchor, width, and used height. Updated when text is rendered.

float CatlikeCoding.TextBox.TextBox.boundsTop

Local top bounds of the box. Defined by anchor, width, and used height. Updated when text is rendered.

int CatlikeCoding.TextBox.TextBox.fitPrecision = 2

Scaling precision used when shrinking to fit, in orders of magnitude.

A precision of 1 means that the text scale is decreased by steps equal to 10% of its original value. A precision of 2 incrementally adds 1% steps, a precision of 3 also adds 0.1% steps, and so on.

Each increase in precision adds up to ten extra steps to the procedure, So keep it as low as possible.

HorizontalAnchorMode CatlikeCoding.TextBox.TextBox.horizontalAnchor

How the box is horizontally positioned, relative to its origin.

Vector2 [] CatlikeCoding.TextBox.TextBox.leftContour

A series of points to shape the left contour that constrains where text is shown inside the box.

float CatlikeCoding.TextBox.TextBox.maxHeight = 10f

Maximum height allowed for the box. Text that won't fit will overflow to the next box or will not be renderered.

TextBox CatlikeCoding.TextBox.TextBox.overflowBox

Box to send overflowing text to. You can build a chain of these, just don't make it circular.

float CatlikeCoding.TextBox.TextBox.paddingBottom

Amount of padding to use at the bottom inside of the box.

float CatlikeCoding.TextBox.TextBox.paddingLeft

Amount of padding to use at the left inside of the box.

float CatlikeCoding.TextBox.TextBox.paddingRight

Amount of padding to use at the right inside of the box.

float CatlikeCoding.TextBox.TextBox.paddingTop

Amount of padding to use at the top inside of the box.

Vector2 [] CatlikeCoding.TextBox.TextBox.rightContour

A series of points to shape the right contour that constrains where text is shown inside the box.

bool CatlikeCoding.TextBox.TextBox.shrinkToFit

Whether to automatically reduce the text scale to fit the text inside the box.

Only enable this when you really need it. And if you do, make sure you're working with reasonably short text.

TextStyleCollection CatlikeCoding.TextBox.TextBox.styleCollection

Style collection that defines how text is shown. Required to render text.

bool CatlikeCoding.TextBox.TextBox.styled = true

Whether styling is used. If not, the raw text is rendered.

float CatlikeCoding.TextBox.TextBox.textScale = 1f

Text scale. Use this to adjust the size of all the text in the box without having to use a separate style collection.

Color CatlikeCoding.TextBox.TextBox.tint = Color.white

Color used to tint the text. This is multiplied with the style color.

VerticalAnchorMode CatlikeCoding.TextBox.TextBox.verticalAnchor

How the box is vertically positioned, relative to its origin.

float CatlikeCoding.TextBox.TextBox.width = 10f

Width of the box. Should be positive.

Property Documentation

string CatlikeCoding.TextBox.TextBox.DefaultText
get

Get the default text. Use SetText to change the text that's actually rendered.

float CatlikeCoding.TextBox.TextBox.EffectiveTextScale
get

Get the effective text scale, which can be different than the normal text scale if shrink-to-fit is enabled.

bool CatlikeCoding.TextBox.TextBox.IsOverFlowBox
get

Get whether this text box is used as an overflow box by another box. This can only be known after the other box has been rendered at least once.

int CatlikeCoding.TextBox.TextBox.LineCount
get

Get the number of text lines currently being displayed.

TextBoxEventHandler CatlikeCoding.TextBox.TextBox.Rendered
addremove

Occurs after the text box has been rendered. When subscribing to this event, you will be called back immediately if the text box is already in a useful state.

float CatlikeCoding.TextBox.TextBox.TabSize
getset

Get or set the tab size, constrained to a minimum of 0.001.

Bounds CatlikeCoding.TextBox.TextBox.TextRendererBounds
get

Get the combined bounds of all text renderers.

Only renderers that have characters to render are included. If there are none, the bounds are zero.

This value is computed. Cache it when using it more than once.

int CatlikeCoding.TextBox.TextBox.TextRendererCount
get

Get the amount of text renderers used by this box.

The text renderer count.