Text
class Text extends Renderable
a generic system font object.
Constructor
new Text(x: number, y: number, settings: object) → {}
let font = new me.Text(0, 0, {font: "Arial", size: 8, fillStyle: this.color});
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
x | number |
position of the text object |
||
y | number |
position of the text object |
||
settings | object |
the text configuration |
||
settings.font | string |
a CSS family font name |
||
settings.size | number | string |
size, or size + suffix (px, em, pt) |
||
settings.fillStyle | Color | string |
<optional> |
"#000000" |
a CSS color value |
settings.strokeStyle | Color | string |
<optional> |
"#000000" |
a CSS color value |
settings.lineWidth | number |
<optional> |
0 |
line width, in pixels, when drawing stroke |
settings.textAlign | string |
<optional> |
"left" |
horizontal text alignment |
settings.textBaseline | string |
<optional> |
"top" |
the text baseline |
settings.lineHeight | number |
<optional> |
1.0 |
line spacing height |
settings.anchorPoint | Vector2d |
<optional> |
{x:0.0, y:0.0} |
anchor point to draw the text at |
settings.wordWrapWidth | number |
<optional> |
the maximum length in CSS pixel for a single segment of text |
|
settings.text | string | Array<string> |
<optional> |
"" |
a string, or an array of strings |
Summary
Properties from Text
Color |
|
number |
|
number |
|
number |
|
Color |
|
string |
|
string |
|
number |
|
Methods from Text
Text |
|
|
|
|
|
Text |
|
TextMetrics |
|
Text |
|
Text |
|
Properties inherited from Renderable
number |
|
boolean |
|
Container | Entity |
|
ObservableVector2d |
|
boolean |
|
string |
|
Body |
|
Matrix2d |
|
number |
|
boolean |
|
string |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
Rect | RoundRect | Polygon | Line | Ellipse |
|
string |
|
Function |
|
Application |
|
ObservableVector3d |
|
GLShader |
|
Color |
|
boolean |
|
Properties inherited from Rect
Methods inherited from Renderable
Methods inherited from Rect
Rect |
|
Rect |
|
boolean |
|
Rect |
|
boolean |
|
boolean |
|
boolean |
|
Rect |
|
Rect |
|
Polygon |
|
Rect |
|
Methods inherited from Polygon
Array<number> |
|
boolean |
|
Polygon |
|
Polygon |
|
|
|
Polygon |
|
Polygon |
|
Polygon |
|
Public Properties
lineHeight: number = 1.0
number
Set the line spacing height (when displaying multi-line strings).
Current font height will be multiplied with this value to set the line height.
lineWidth: number = 0
number
sets the current line width, in pixels, when drawing stroke
strokeStyle: Color = black
Color
defines the color used to draw the font stroke.
textAlign: string = "left"
string
Set the default text alignment (or justification),
possible values are "left", "right", and "center".
textBaseline: string = "top"
string
Set the text baseline (e.g. the Y-coordinate for the draw operation),
possible values are "top", "hanging, "middle, "alphabetic, "ideographic, "bottom"
wordWrapWidth: number = -1
number
the maximum length in CSS pixel for a single segment of text. (use -1 to disable word wrapping)
Public Methods
bold() → {Text}
make the font bold
Type | Description |
---|---|
Text |
this object for chaining |
draw(renderer: CanvasRenderer | WebGLRenderer, text: string, x: number, y: number) → {}
draw a text at the specified coord
Name | Type | Attributes | Description |
---|---|---|---|
renderer | CanvasRenderer | WebGLRenderer |
Reference to the destination renderer instance |
|
text | string |
<optional> |
|
x | number |
<optional> |
|
y | number |
<optional> |
drawStroke(renderer: CanvasRenderer | WebGLRenderer, text: string, x: number, y: number) → {}
draw a stroke text at the specified coord, as defined by the lineWidth
and fillStroke
properties.
Name | Type | Description |
---|---|---|
renderer | CanvasRenderer | WebGLRenderer |
Reference to the destination renderer instance |
text | string | |
x | number | |
y | number |
italic() → {Text}
make the font italic
Type | Description |
---|---|
Text |
this object for chaining |
measureText(renderer: CanvasRenderer | WebGLRenderer, text: string) → {TextMetrics}
measure the given text size in pixels
Name | Type | Attributes | Description |
---|---|---|---|
renderer | CanvasRenderer | WebGLRenderer |
reference to the active renderer |
|
text | string |
<optional> |
the text to be measured |
Type | Description |
---|---|
TextMetrics |
a TextMetrics object defining the dimensions of the given piece of text |
setFont(font: string, size: number | string) → {Text}
set the font family and size
font.setFont("Arial", 20);
font.setFont("Arial", "1.5em");
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
font | string |
a CSS font name |
||
size | number | string |
<optional> |
10 |
size in px, or size + suffix (px, em, pt) |
Type | Description |
---|---|
Text |
this object for chaining |
setText(value: number | string | Array<string>) → {Text}
change the text to be displayed
Name | Type | Default | Description |
---|---|---|---|
value | number | string | Array<string> | "" |
a string, or an array of strings |
Type | Description |
---|---|
Text |
this object for chaining |