Skip to content

1681-engine / ui / RichText

Class: RichText ​

Defined in: src/ui/rich/RichText.ts:23

Text with inline markup — colour, bold, italic, size and icons (see parseRichText) — wrapped to a width and aligned. A Widget, so it stacks and pins like a Label, and a plain Pixi container in the world too.

It does its work only when the text or the layout options change: no per-frame cost. Its runs and icons are kept and reused when the text changes, so a log line rewritten keeps its display objects. Under a pixel-perfect UI root (or with pixelPerfect) every run and icon lands on a whole pixel and icons scale by whole multiples.

Extends ​

Constructors ​

Constructor ​

ts
new RichText(markup, options): RichText;

Defined in: src/ui/rich/RichText.ts:33

Parameters ​

ParameterType
markupstring
optionsRichTextOptions

Returns ​

RichText

Overrides ​

Widget.constructor

Properties ​

boxH ​

ts
protected boxH: number = 0;

Defined in: src/ui/Widget.ts:23

Inherited from ​

Widget.boxH


boxW ​

ts
protected boxW: number = 0;

Defined in: src/ui/Widget.ts:22

Inherited from ​

Widget.boxW


focusable ​

ts
focusable: boolean = false;

Defined in: src/ui/Widget.ts:21

Whether the focus manager may land on it (buttons, sliders, toggles).

Inherited from ​

Widget.focusable

Accessors ​

boxHeight ​

Get Signature ​

ts
get boxHeight(): number;

Defined in: src/ui/Widget.ts:31

Returns ​

number

Inherited from ​

Widget.boxHeight


boxWidth ​

Get Signature ​

ts
get boxWidth(): number;

Defined in: src/ui/Widget.ts:27

Returns ​

number

Inherited from ​

Widget.boxWidth


enabled ​

Get Signature ​

ts
get enabled(): boolean;

Defined in: src/ui/Widget.ts:35

Returns ​

boolean

Set Signature ​

ts
set enabled(v): void;

Defined in: src/ui/Widget.ts:39

Parameters ​
ParameterType
vboolean
Returns ​

void

Inherited from ​

Widget.enabled


focused ​

Get Signature ​

ts
get focused(): boolean;

Defined in: src/ui/Widget.ts:47

Returns ​

boolean

Inherited from ​

Widget.focused


host ​

Get Signature ​

ts
get protected host(): UiHost | null;

Defined in: src/ui/Widget.ts:90

The root it sits under, looked up when needed: a widget may be built before it is added.

Returns ​

UiHost | null

Inherited from ​

Widget.host


layout ​

Get Signature ​

ts
get layout(): RichLayout;

Defined in: src/ui/rich/RichText.ts:58

Where every line, run and icon was placed, for hit-testing a word or drawing behind one.

Returns ​

RichLayout


markup ​

Get Signature ​

ts
get markup(): string;

Defined in: src/ui/rich/RichText.ts:53

The markup shown.

Returns ​

string

Methods ​

activate() ​

ts
activate(): void;

Defined in: src/ui/Widget.ts:82

Accept pressed while focused (Enter, the pad's A).

Returns ​

void

Inherited from ​

Widget.activate


canFocus() ​

ts
canFocus(): boolean;

Defined in: src/ui/Widget.ts:75

Focusable now: enabled, shown, and every parent shown.

Returns ​

boolean

Inherited from ​

Widget.canFocus


childResized() ​

ts
protected childResized(_child): void;

Defined in: src/ui/Widget.ts:108

A child widget's box changed size by itself (a Label given a longer text). A widget that places a child by its size (a Button centring its content) lays it out again here; the default does nothing, so a Stack still waits for its layout() and a change does not ripple up through every container.

Parameters ​

ParameterType
_childWidget

Returns ​

void

Inherited from ​

Widget.childResized


destroy() ​

ts
destroy(options?): void;

Defined in: src/ui/rich/RichText.ts:123

Removes all internal references and listeners as well as removes children from the display list. Do not use a Container after calling destroy.

Parameters ​

ParameterTypeDescription
options?DestroyOptionsOptions parameter. A boolean will act as if all options have been set to that value

Returns ​

void

Example ​

ts
container.destroy();
container.destroy(true);
container.destroy({ children: true });
container.destroy({ children: true, texture: true, textureSource: true });

Overrides ​

ts
Widget.destroy

makeInteractive() ​

ts
protected makeInteractive(): void;

Defined in: src/ui/Widget.ts:98

Hit-tested by Pixi, and every press on it is kept from the world. A widget whose drawing has gaps (a scroll view, an empty panel) also sets a hitArea over its box, so a press between its pieces is not the world's.

Returns ​

void

Inherited from ​

Widget.makeInteractive


ts
navigate(_dir): boolean;

Defined in: src/ui/Widget.ts:85

A direction pressed while focused; true when the widget used it (a slider stepping) so focus stays.

Parameters ​

ParameterType
_dirNavDirection

Returns ​

boolean

Inherited from ​

Widget.navigate


notifyResized() ​

ts
protected notifyResized(): void;

Defined in: src/ui/Widget.ts:111

Tells the parent widget this one's box changed size by itself.

Returns ​

void

Inherited from ​

Widget.notifyResized


place() ​

ts
place(x, y): this;

Defined in: src/ui/Widget.ts:68

Moves it, on whole pixels under a pixel-perfect root.

Parameters ​

ParameterType
xnumber
ynumber

Returns ​

this

Inherited from ​

Widget.place


redraw() ​

ts
protected redraw(): void;

Defined in: src/ui/rich/RichText.ts:128

Draws the current size and state.

Returns ​

void

Overrides ​

Widget.redraw


relayout() ​

ts
relayout(): void;

Defined in: src/ui/rich/RichText.ts:87

Lays out and draws again: after the font's colours or the icons' textures were swapped under it.

Returns ​

void


resize() ​

ts
resize(width, height): this;

Defined in: src/ui/Widget.ts:59

Resizes the layout box (whole pixels under a pixel-perfect root) and redraws.

Parameters ​

ParameterType
widthnumber
heightnumber

Returns ​

this

Inherited from ​

Widget.resize


setAlign() ​

ts
setAlign(align): this;

Defined in: src/ui/rich/RichText.ts:79

Parameters ​

ParameterType
alignRichAlign

Returns ​

this


setFocused() ​

ts
setFocused(v): void;

Defined in: src/ui/Widget.ts:52

Called by the focus manager.

Parameters ​

ParameterType
vboolean

Returns ​

void

Inherited from ​

Widget.setFocused


setText() ​

ts
setText(markup): this;

Defined in: src/ui/rich/RichText.ts:63

Changes the text; the same markup again costs nothing.

Parameters ​

ParameterType
markupstring

Returns ​

this


setWrapWidth() ​

ts
setWrapWidth(width): this;

Defined in: src/ui/rich/RichText.ts:71

Wraps to a new width (undefined: only at \n).

Parameters ​

ParameterType
widthnumber | undefined

Returns ​

this

Released under the MIT License.