SilkRichText
import { SilkRichText } from 'pixi-silk/text';
A SilkText with sprites, SilkGraphics or any container inside its lines. Write {name}
in the text and list the object under inlines. Each token takes a box that flows with the
text: it wraps, aligns and follows right-to-left order like a character, and the line grows when
the object is taller than the text. The object is scaled to the box and placed in it every frame,
so it follows text, style, anchor and size changes.
Example#
import { Sprite, Texture } from 'pixi.js';
import { SilkGraphics } from 'pixi-silk';
import { SilkRichText } from 'pixi-silk/text';
const status = new SilkRichText({
text: 'Synced {dot} 2 min ago, rated {star} 4.8',
fontSize: 24,
inlines: {
dot: { object: new Sprite(Texture.WHITE), height: 'cap', margin: 2 },
star: { object: () => new SilkGraphics().star(0, 0, 5, 10, 5).fill(0xffd60a), height: 'em' },
},
});
app.stage.addChild(status);
Extends#
Container
Constructors#
Constructor#
new SilkRichText(options?: SilkRichTextOptions): SilkRichText;
Parameters#
| Parameter | Type |
|---|---|
options | SilkRichTextOptions |
Returns#
SilkRichText
Overrides#
Container.constructor
Properties#
| Property | Modifier | Type | Description | Defined in |
|---|---|---|---|---|
textObject | readonly | SilkText | The text. Style it through this object, except for inlines, which this container owns. | packages/pixi-silk/src/text/rich.ts:226 |
Accessors#
anchor#
Get Signature#
get anchor(): ObservablePoint;
Point of the text box at the position, as on SilkText.anchor: (0, 0) top left, (0.5, 0.5) centre. The inline objects move with it.
Returns
ObservablePoint
inlines#
Get Signature#
get inlines(): Record<string, RichInline>;
The inline objects by name. Set a new object to change them. Objects that left are removed, not destroyed.
Returns
Record<string, RichInline>
Set Signature#
set inlines(v: Record<string, RichInline>): void;
Sets SilkRichText.inlines.
Parameters
| Parameter | Type |
|---|---|
v | Record<string, RichInline> |
Returns
void
text#
Get Signature#
get text(): string;
The text, with {name} tokens where inline objects go.
Returns
string
Set Signature#
set text(v: string | number): void;
Sets SilkRichText.text.
Parameters
| Parameter | Type |
|---|---|
v | string | number |
Returns
void
Methods#
destroy()#
destroy(options?: DestroyOptions): void;
Removes all internal references and listeners as well as removes children from the display list.
Do not use a Container after calling destroy.
Parameters#
| Parameter | Type | Description |
|---|---|---|
options? | DestroyOptions | Options parameter. A boolean will act as if all options have been set to that value |
Returns#
void
Example#
container.destroy();
container.destroy(true);
container.destroy({ children: true });
container.destroy({ children: true, texture: true, textureSource: true });
Overrides#
Container.destroy
sync()#
sync(): void;
Measures the objects, lays the text out around them and moves them into their boxes. Runs before every render, so call it only to read positions in the same frame as a change.
Returns#
void