Most visited

Recently visited

Text

public class Text
extends Geometry

java.lang.Object
   ↳ com.viro.core.Geometry
     ↳ com.viro.core.Text


Text is a Geometry that renders strings of text. The properties of the Text determine the style of the rendered string, and the bounds of the Text (width and height) determine the area within which the text is rendered. The bounds are centered at (0,0) in the local coordinate system of the Text. The HorizontalAlignment and VerticalAlignment of the Text determine how the Text is positioned within these bounds.

Summary

Nested classes

enum Text.ClipMode

Controls whether text clips when it exceeds its bounds. 

enum Text.HorizontalAlignment

Controls the horizontal alignment of Text within its bounds. 

enum Text.LineBreakMode

Controls the way in which text wraps when it exceeds its bound's width. 

class Text.TextBuilder

Builder for creating Text objects. 

enum Text.VerticalAlignment

Controls the vertical alignment of Text within its bounds. 

Public constructors

Text(ViroContext viroContext, String text, float width, float height)

Create a new Text with the given set of minimum parameters: the text to display, and the width and height of the bounds within which to display it.

Text(ViroContext viroContext, String text, String fontFamilyName, int size, long color, float width, float height, Text.HorizontalAlignment horizontalAlignment, Text.VerticalAlignment verticalAlignment, Text.LineBreakMode lineBreakMode, Text.ClipMode clipMode, int maxLines)

Create a new fully specified Text.

Public methods

static Text.TextBuilder builder()

Builder for creating Text objects.

void dispose()

Release native resources associated with this Text.

Text.ClipMode getClipMode()

Get the Text.ClipMode used by this Text.

long getColor()
String getFontFamilyName()

Get the name of the font family used by this Text.

int getFontSize()

Get the font size used when rendering this Text.

float getHeight()

Get the height of the bounds to which this Text is constrained.

Text.HorizontalAlignment getHorizontalAlignment()

Get the Text.HorizontalAlignment used when rendering this text.

Text.LineBreakMode getLineBreakMode()

Get the Text.LineBreakMode used by this Text.

int getMaxLines()

Get the maximum number of lines allowed for this Text.

String getText()

Get the text string displayed by this Text.

Text.VerticalAlignment getVerticalAlignment()

Get the Text.VerticalAlignment used when rendering this Text.

float getWidth()

Get the width of the bounds to which this Text is constrained.

void setClipMode(Text.ClipMode clipMode)

Set the Text.ClipMode to use for this Text.

void setColor(long color)
void setFontFamilyName(String fontFamily)

Set the name of the font family to use to render this Text.

void setFontSize(int fontSize)

Set the point size of the font to use when rendering this Text.

void setHeight(float height)

Set the height of the bounds used by this Text.

void setHorizontalAlignment(Text.HorizontalAlignment horizontalAlignment)

Set the Text.HorizontalAlignment to use when rendering this text.

void setLineBreakMode(Text.LineBreakMode lineBreakMode)

Set the Text.LineBreakMode to use for this Text.

void setMaxLines(int maxLines)

Set the maximum number of lines for this Text.

void setText(String textString)

Set the text string to display with this Text.

void setVerticalAlignment(Text.VerticalAlignment verticalAlignment)

Set the Text.VerticalAlignment to use when rendering this text.

void setWidth(float width)

Set the width of the bounds used by this Text.

Public constructors

Text

Text (ViroContext viroContext, 
                String text, 
                float width, 
                float height)

Create a new Text with the given set of minimum parameters: the text to display, and the width and height of the bounds within which to display it. The text will be constrained to the provided bounds, and defaults to wrapping words.

Parameters
viroContext ViroContext: The ViroContext is required to render Text.

text String: The text string to display.

width float: The width of the bounds within which to display the text.

height float: The height of the bounds within which to display the text.

Text

Text (ViroContext viroContext, 
                String text, 
                String fontFamilyName, 
                int size, 
                long color, 
                float width, 
                float height, 
                Text.HorizontalAlignment horizontalAlignment, 
                Text.VerticalAlignment verticalAlignment, 
                Text.LineBreakMode lineBreakMode, 
                Text.ClipMode clipMode, 
                int maxLines)

Create a new fully specified Text. The the given string will be displayed given typeface, constrained to the bounds defined by the provided width and height, and aligned according to the given alignment parameters and linebreak mode.

The clip mode determines whether the text is clipped to the given bounds.

The maxLines parameter, if set, caps the number of lines; when zero, there is no limit to the number of lines generated.

Parameters
viroContext ViroContext: The ViroContext is required to render Text.

text String: The text string to display.

fontFamilyName String: The name of the font's family name (e.g. 'Roboto' or 'Roboto-Italic').

size int: The point size of the font.

color long: The color of the text.

width float: The width of the bounds within which to display the text.

height float: The height of the bounds within which to display the text.

horizontalAlignment Text.HorizontalAlignment: The horizontal alignment of the text.

verticalAlignment Text.VerticalAlignment: The vertical alignment of the text.

lineBreakMode Text.LineBreakMode: The line-break mode to use when the text breaches the maximum width of the bounds.

clipMode Text.ClipMode: The clipping mode, which determines behavior when the text breaches the maximum width of the bounds (when word-wrapping is disabled), and the behavior when the text breaches the maximum height of the bounds.

maxLines int: If non-zero, will cap the number of lines. If set to zero, there is no limit to the number of lines generated.

Public methods

builder

Text.TextBuilder builder ()

Builder for creating Text objects.

Returns
Text.TextBuilder

dispose

void dispose ()

Release native resources associated with this Text.

getClipMode

Text.ClipMode getClipMode ()

Get the Text.ClipMode used by this Text.

Returns
Text.ClipMode The Text.ClipMode used by this text.

getColor

long getColor ()

Returns
long

getFontFamilyName

String getFontFamilyName ()

Get the name of the font family used by this Text. For example, 'Roboto' or 'Roboto-Italic'. The font family, in conjunction with the font size, determines the typeface used when rendering the text.

Returns
String The name of the font family.

getFontSize

int getFontSize ()

Get the font size used when rendering this Text.

Returns
int The font size of the Text.

getHeight

float getHeight ()

Get the height of the bounds to which this Text is constrained.

Returns
float The height of the Text's bounds.

getHorizontalAlignment

Text.HorizontalAlignment getHorizontalAlignment ()

Get the Text.HorizontalAlignment used when rendering this text.

Returns
Text.HorizontalAlignment The Text.HorizontalAlignment used by this Text.

getLineBreakMode

Text.LineBreakMode getLineBreakMode ()

Get the Text.LineBreakMode used by this Text.

Returns
Text.LineBreakMode The Text.LineBreakMode used by this Text.

getMaxLines

int getMaxLines ()

Get the maximum number of lines allowed for this Text. Zero implies unlimited lines.

Returns
int The maximum number of lines allowed for this text.

getText

String getText ()

Get the text string displayed by this Text.

Returns
String The text string.

getVerticalAlignment

Text.VerticalAlignment getVerticalAlignment ()

Get the Text.VerticalAlignment used when rendering this Text.

Returns
Text.VerticalAlignment The Text.VerticalAlignment used by this Text.

getWidth

float getWidth ()

Get the width of the bounds to which this Text is constrained.

Returns
float The width of the Text's bounds.

setClipMode

void setClipMode (Text.ClipMode clipMode)

Set the Text.ClipMode to use for this Text. If set to CLIP_TO_BOUNDS, the text will be clipped if it breaches the bounds vertically or horizontally. If set to NONE, the text may exceed its bounds.

Parameters
clipMode Text.ClipMode: The Text.ClipMode to use for the Text.

setColor

void setColor (long color)

Parameters
color long

setFontFamilyName

void setFontFamilyName (String fontFamily)

Set the name of the font family to use to render this Text. For example, 'Roboto' or 'Roboto-Italic'. The font family, in conjunction with the font size, determines the typeface used when rendering the text.

Parameters
fontFamily String: The name of the font family.

setFontSize

void setFontSize (int fontSize)

Set the point size of the font to use when rendering this Text. The font size, in conjunction with the font family, determines the typeface used when rendering the text.

Parameters
fontSize int: The font size.

setHeight

void setHeight (float height)

Set the height of the bounds used by this Text. The Text is constrained by its bounds, which are specified by this property and setWidth(float). If the Text is long enough that it exceeds this height, it is clipped as determined by the Text.ClipMode.

Parameters
height float: The height of the bounds used by this Text.

setHorizontalAlignment

void setHorizontalAlignment (Text.HorizontalAlignment horizontalAlignment)

Set the Text.HorizontalAlignment to use when rendering this text. The VerticalAlignment determines how the text is laid out horizontally relative to its bounds.

Parameters
horizontalAlignment Text.HorizontalAlignment: The Text.HorizontalAlignment to use for this text.

setLineBreakMode

void setLineBreakMode (Text.LineBreakMode lineBreakMode)

Set the Text.LineBreakMode to use for this Text. Text can be wrapped by words, wrapped by characters, or it can be justified. Justification wraps words to minimize the 'jaggedness' of the edges of the Text.

Parameters
lineBreakMode Text.LineBreakMode: The Text.LineBreakMode to use for this Text.

setMaxLines

void setMaxLines (int maxLines)

Set the maximum number of lines for this Text. If non-zero, this caps the number of lines. If set to zero, there is no limit to the number of lines generated.

Parameters
maxLines int: The maximum of lines to render.

setText

void setText (String textString)

Set the text string to display with this Text.

Parameters
textString String: The text string.

setVerticalAlignment

void setVerticalAlignment (Text.VerticalAlignment verticalAlignment)

Set the Text.VerticalAlignment to use when rendering this text. The VerticalAlignment determines how the text is laid out vertically relative to its bounds.

Parameters
verticalAlignment Text.VerticalAlignment: The Text.VerticalAlignment to use for this text.

setWidth

void setWidth (float width)

Set the width of the bounds used by this Text. The Text is constrained by its bounds, which are specified by this property and setHeight(float). If the Text is long enough that it exceeds this width, it is wrapped to the next line as determined by Text.LineBreakMode. If the LineBreakMode is set to NONE, then the Text is clipped as per Text.ClipMode.

Parameters
width float: The width of the bounds used by this Text.

Hooray!