TextBlock class

A TextBlock is a GraphObject that displays a #text string in a given #font.

The size and appearance of the text is specified by #font, which takes a well-formed CSS string as its value. The order of the CSS properties given is important for cross-browser compatibility, and should be given in this order:

"font-style font-variant font-weight font-size font-family"

For example, "Italic small-caps bold 32px Georgia, Serif" is a valid font string using every CSS font property. Note that not all browsers may support every property.

Text is drawn using the #stroke brush, which may be any CSS color string or a Brush.

Some created TextBlocks:

// A TextBlock with text and stroke properties set:
new go.TextBlock({ text: "Hello World", stroke: "gray" })
// Alternatively:
new go.TextBlock("Hello World", { stroke: "gray" })

TextBlocks typically receive a natural size based on their text and font strings, but often a width is given in order to cause the text to wrap at a certain place. In order for wrapping to occur, the #wrap property must not be TextBlock.None.

TextBlocks can be edited by users using the TextEditingTool. The HTMLInfo that a given TextBlock uses as its text editor can be customized by setting the #textEditor property. For an example of custom text editing tool use, see the Custom TextEditingTool Sample.

For examples of TextBlock possibilities and functionality, see the Introduction page on TextBlocks.

Implemented types
Available Extensions
Annotations
  • @JS()
  • @staticInterop

Constructors

TextBlock.$1()
factory
TextBlock.$2([dynamic init])
factory
TextBlock.$3([String? text, dynamic init])
factory

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Properties

formatNone EnumValue
Used as a value for TextBlock#formatting: the TextBlock will not trim any whitespace at the start or end of each line of text. This can be useful if your text is preformatted.
getter/setter pair
formatTrim EnumValue
Used as the default value for TextBlock#formatting: the TextBlock will automatically trim any whitespace at the start or end of each line of text.
getter/setter pair
none EnumValue
Used as a value for TextBlock#wrap, the TextBlock will not wrap its text.
getter/setter pair
overflowClip EnumValue
Used as the default value for TextBlock#overflow: if the width is too small to display all text, the TextBlock will clip.
getter/setter pair
overflowEllipsis EnumValue
Used as a value for TextBlock#overflow: if the width is too small to display all text, the TextBlock will display an ellipsis.
getter/setter pair
wrapBreakAll EnumValue
Used a a value for TextBlock#wrap, the TextBlock will attempt to wrap at each character, allowing breaks within "words."
getter/setter pair
wrapDesiredSize EnumValue
Used as the default value for TextBlock#wrap, the TextBlock will wrap text and the width of the TextBlock will be the desiredSize's width, if any.
getter/setter pair
wrapFit EnumValue
Used as a value for TextBlock#wrap, the TextBlock will wrap text, making the width of the TextBlock equal to the width of the longest line.
getter/setter pair

Static Methods

getBaseline() → (num Function(TextBlock, num)?)
Gets the function that, given the TextBlock and numerical text height, computes the position to draw the baseline of a line of text in all TextBlocks. By default this is null and default behavior returns (textHeight * 0.75).
getEllipsis() String
(undocumented) This static function gets the current ellipsis character or string for TextBlocks that have TextBlock#overflow set to TextBlock.Ellipsis.
getUnderline() → (num Function(TextBlock, num)?)
Gets the function that, given the TextBlock and numerical text height, computes the position to draw the underline of a line of text in all TextBlocks. By default this is null and default behavior returns (textHeight * 0.75).
isValidFont(String font) bool
(undocumented) This static predicate returns true if the given font is a valid font.
setBaseline([num value(TextBlock, num)?]) → void
Sets the function that, given the TextBlock and numerical text height, computes the position to draw the baseline of a line of text in all TextBlocks.
setEllipsis(String val) → void
(undocumented) This static function sets the ellipsis character or string for all TextBlocks that have TextBlock#overflow set to TextBlock.Ellipsis.
setUnderline([num value(TextBlock, num)?]) → void
Sets the function that, given the TextBlock and numerical text height, computes the position to draw the underline of a line of text in all TextBlocks.