TextWidget

TextWidget

Displays a piece of static text. Should be placed over a background to refresh properly. When a TextWidget changes, it automatically refreshes its parent. If you want floating text, put it in an EmptyWidget.

Extends

Members

# text :string

The string to display.

Type:
  • string
Example:
myTextWidget.set({text: "Disply this string!"});

# point :number

The size of the text.

Type:
  • number
Default Value:
  • 24
Example:
myTextWidget.set({point: 12}); // Make the text smaller than the default

# style :string

The styling of the text. Options include "normal", "bold", and "italic".

Type:
  • string
Default Value:
  • "normal"
Example:
myTextWidget.set({style: "italic"});

# alignX :string

The horizontal alignment of the text. Options are "right", "center", and "left".

Type:
  • string
Default Value:
  • "center"
Example:
myTextWidget.set({alignX: "right"});

# alignY :string

The vertical alignment of the text. Options are "top", "middle", and "bottom".

Type:
  • string
Default Value:
  • "middle"
Example:
myTextWidget.set({againY: "bottom"});

# font :string

The name of an installed font ("arial") or a generic font type ("sans-serif")

Type:
  • string
Default Value:
  • "sans-serif"
Example:
myTextWidget.set({font: "serif"});

# fontURL :string

The url of an external font asset (.otf). The widget will automatically refresh itself when the font finishes loading.

Type:
  • string
Example:
import myFont from "./assets/weirdFont.otf";
const myTextWidget = new TextWidget({fontURL: myFont, text: "This will display in the weird font!"});

# wrap :boolean

The flag that controls word-wrap. If it's set to true, the text wraps to multiple lines, using the y dimension of the widget to control line length. Use lineSpacing to set the spacing of the lines and border to set the outer margins.

Type:
  • boolean
Default Value:
  • true
Example:
myTextWidget.set{wrap: true, lineSpacing: 24, border: [10,10,10,10]});

# lineSpacing :number

The spacing between wrapped lines. The default is 0, which means the text will be single spaced. If you want more space between lines, the lineSpacing value is the point size of the empty space inserted.

Type:
  • number
Default Value:
  • 0
Example:
myTextWidget.set{wrap: true, lineSpacing: 12, point: 12}); // Double-spaced

# parent :Widget

The widget's parent in the widget tree.

Type:
Inherited From:

# size :Array.<number>

A 2d array containing the widget's xy size.

Type:
  • Array.<number>
Inherited From:

# autoSize :Array.<number>

A 2d array specifying the xy size the widget relative to it's parent. Values can range from 0-1. If either the x or the y value is 0, that dimension will default to the value of size().

Type:
  • Array.<number>
Inherited From:
Default Value:
  • [0,0]
Example:
myWidget.set({autoSize: [1,1]}); // The widget will be the same size as its parent.

# anchor :Array.<number>

A 2d array specifying the relative xy position of the widget within its parent. Values can range from 0-1. The actual position of a widget relative to its parent is determined by a combination of anchor, pivot, local, and border.

Type:
  • Array.<number>
Inherited From:
Default Value:
  • [0,0]
Examples:
myWidget.set({anchor: [1,0]}); // Anchor the widget to the upper right corner of its parent.
myWidget.set({anchor: [0.5,1]}); // Anchor the widget to the center bottom of its parent.

# pivot :Array.<number>

A 2d array specifying the relative xy position in the widget that matches the parent's anchor. Values can range from 0-1. The actual position of a widget relative to its parent is determined by a combination of anchor, pivot, local, and border

Type:
  • Array.<number>
Inherited From:
Default Value:
  • [0,0]
Examples:
myWidget.set({anchor: [0.5,0.5], pivot: [0.5,0.5]}); // The center of the widget is exactly in the center of its parent.
myWidget.set({anchor: [1,0.25], pivot: [1,0]}); // The top left corner of the widget is 25% of the way down the parent's right side.

# local :Array.<number>

A 2d array specifying the xy pixel offset of the widget relative to its parent. The actual position of a widget relative to its parent is determined by a combination of anchor, pivot, local, and border.

Type:
  • Array.<number>
Inherited From:
Default Value:
  • [0,0]
Example:
myWidget.set({anchor: [0,1], pivot: [0,1], local: [20,-20]}); // Inset the widget 20 pixels from the lower-left corner of its parent.

# border :Array.<number>

A 4d array specifying pixel insets to be applied when calculating the edges of the widget relaitve to its parent. The values are [left,top,right,bottom] and are always positive. The actual position of a widget relative to its parent is determined by a combination of anchor, pivot, local, and border.

Type:
  • Array.<number>
Inherited From:
Default Value:
  • [0,0,0,0]
Example:
myWidget.set({autoSize: [1,1], border: [20,20,20,20]}); // The widget fills its parent with an inset of 20 pixels all around.

# visible :boolean

The visibility of the widget. Hidden widgets can't be interacted with. The visibility of a parent affects all its children.

Type:
  • boolean
Inherited From:
Default Value:
  • true
Example:
myWidget.set({visible: false}); // Hides the widget and its children.

# color :Array.<number>

A 3d array specifying the rgb color of a widget. Not all widgets use this property, but enough do that its worth putting in the base class.

Type:
  • Array.<number>
Inherited From:
Default Value:
  • [0,0,0]
Example:
myWidget.set({color: [0,1,0]}); // Sets the color to green.

# scale :Array.<number>

The widget's relative scale. A parent passes its scale on to its children. Usually you just want to leave the scale set to 1 and control the layout of your UI using the widget's other parameters. However, it can be useful if you want to create an interface that dynamically adapts to different window sizes.

Type:
  • Array.<number>
Inherited From:
Default Value:
  • 1
Example:
myWidget.set({color: [0,1,0]}); // Sets the color to green.

# width :number

Ignored unless the widget is placed inside a horizontal widget. This allows you to override the horizontal widget's automatic scaling.

Type:
  • number
Inherited From:

# height :number

Ignored unless the widget is placed inside a vertical widget. This allows you to override the vertical widget's automatic scaling.

Type:
  • number
Inherited From:

Methods

# set(optionsopt)

Sets one or more properties. Set is called by the widget's constructor to set the widget's properties on instantiation.

Parameters:
Name Type Attributes Description
options object <optional>

An options object that contains the properties to be set.

Inherited From:
Example
myWidget.set({visible: false});