-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
Text.ts
71 lines (63 loc) · 2.3 KB
/
Text.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { AbstractText, ensureOptions } from './AbstractText';
import { CanvasTextMetrics } from './canvas/CanvasTextMetrics';
import { TextStyle } from './TextStyle';
import type { View } from '../../rendering/renderers/shared/view/View';
import type { TextOptions, TextString } from './AbstractText';
import type { TextStyleOptions } from './TextStyle';
/**
* A Text Object will create a line or multiple lines of text.
*
* To split a line you can use '\n' in your text string, or, on the `style` object,
* change its `wordWrap` property to true and and givae the `wordWrapWidth` property a value.
*
* The primary advantage of this class over BitmapText is that you have great control over the style of the text,
* which you can change at runtime.
*
* The primary disadvantages is that each piece of text has it's own texture, which can use more memory.
* When text changes, this texture has to be re-generated and re-uploaded to the GPU, taking up time.
* @example
* import { Text } from 'pixi.js';
*
* const text = new Text({
* text: 'Hello Pixi!',
* style: {
* fontFamily: 'Arial',
* fontSize: 24,
* fill: 0xff1010,
* align: 'center',
* }
* });
* @memberof scene
*/
export class Text
extends AbstractText<TextStyle, TextStyleOptions>
implements View
{
public readonly renderPipeId: string = 'text';
/**
* @param {text.TextOptions} options - The options of the text.
*/
constructor(options?: TextOptions);
/** @deprecated since 8.0.0 */
constructor(text?: TextString, options?: Partial<TextStyle>);
constructor(...args: [TextOptions?] | [TextString, Partial<TextStyle>])
{
const options = ensureOptions(args, 'Text');
super(options, TextStyle);
}
protected _updateBounds()
{
const bounds = this._bounds;
const padding = this._style.padding;
const anchor = this._anchor;
const canvasMeasurement = CanvasTextMetrics.measureText(
this._text,
this._style
);
const { width, height } = canvasMeasurement;
bounds.minX = (-anchor._x * width) - padding;
bounds.maxX = bounds.minX + width + (padding * 2);
bounds.minY = (-anchor._y * height) - padding;
bounds.maxY = bounds.minY + height + (padding * 2);
}
}