-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
115 lines (110 loc) · 2.76 KB
/
index.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import { CanvasTextExtension, Text, TEXT } from '@jeng/text';
import { CanvasEngine } from '@jeng/canvas-engine';
import { Container, CONTAINER } from '@jeng/core';
// create engine
const engine = new CanvasEngine();
// add text extension
CanvasTextExtension.init(engine);
// set fullscreen mode
engine.screen.fullscreen = true;
// start update loop
engine.ticker.play();
// add engine view to page
document.body.appendChild(engine.platform.view);
const longText = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus imperdiet ultricies nibh, at mattis sem volutpat et. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.';
const multilineText = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.\nPhasellus imperdiet ultricies nibh, at mattis sem volutpat et.';
// positioning texts
function positionTexts(texts: Array<Text>) {
const x = 20;
let y = 20;
texts.forEach((text) => {
text.x = x;
text.y = y;
y += 10 + (text.height ?? 0);
});
return texts;
}
// create simple app
const app: Container = {
type: CONTAINER,
children: positionTexts([
{
type: TEXT,
text: [
{
text: 'Big text. ', size: 25, color: 0xff0000, verticalAlign: 'bottom',
},
{ text: 'Middle text. ', verticalAlign: 'bottom' },
{
text: 'Little text.', size: 10, verticalAlign: 'bottom', color: 0x0000ff,
},
'\n\nLorem ipsum dolor sit amet, consectetur adipiscing elit.',
],
format: {
size: 15,
color: 0x229933,
leading: 5,
},
wordWrap: true,
border: 0x223399,
width: 300,
height: 100,
} as Text,
{
type: TEXT,
text: [
{ text: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. LEFT\n\n', align: 'left' },
{ text: 'Phasellus imperdiet ultricies nibh, at mattis sem volutpat et. CENTER\n\n', align: 'center', font: 'times new roman' },
{ text: 'Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. RIGHT', align: 'right' },
],
format: {
size: 13,
color: 0x223399,
letterSpacing: 1,
verticalAlign: 'middle',
},
wordWrap: true,
border: 0x993322,
width: 300,
height: 150,
} as Text,
{
type: TEXT,
text: longText,
format: {
size: 11,
color: 0x993322,
align: 'right',
verticalAlign: 'bottom',
},
wordWrap: true,
border: 0x229933,
width: 300,
height: 70,
} as Text,
{
type: TEXT,
text: longText,
format: {
size: 13,
color: 0,
verticalAlign: 'middle',
},
border: 0x229933,
background: 0xffddbb,
width: 300,
height: 100,
} as Text,
{
type: TEXT,
text: `AUTO SIZE\n${multilineText}`,
format: {
size: 15,
color: 0x0000ff,
},
border: 0x0000ff,
} as Text,
]),
};
// add app graph to engine
engine.root = app;