-
Notifications
You must be signed in to change notification settings - Fork 237
/
main.js
95 lines (87 loc) · 2.81 KB
/
main.js
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
/*
* Copyright (c) 2016-2020 Moddable Tech, Inc.
*
* This file is part of the Moddable SDK.
*
* This work is licensed under the
* Creative Commons Attribution 4.0 International License.
* To view a copy of this license, visit
* <http://creativecommons.org/licenses/by/4.0>.
* or send a letter to Creative Commons, PO Box 1866,
* Mountain View, CA 94042, USA.
*
*/
import {} from "piu/MC";
const blackSkin = new Skin({ fill:"black" });
const whiteSkin = new Skin({ fill:"white" });
const textStyle = new Style({ font:"myFont", left:10, right:10, top:15, bottom:15 });
const centerStyle = new Style({ horizontal:"center" });
const leftStyle = new Style({ horizontal:"left" });
const rightStyle = new Style({ horizontal:"right" });
const justifyStyle = new Style({ horizontal:"justify" });
const absoluteLeadingStyle = new Style({ horizontal:"left", leading:30 });
const relativeLeadingStyle = new Style({ horizontal:"left", leading:-80 });
const otherStyle = new Style({ font:"OpenSans-Semibold-28", color:["blue","red"] });
const redStyle = new Style({ color:["red","blue"] });
const styles = [ centerStyle, leftStyle, rightStyle, justifyStyle, absoluteLeadingStyle, relativeLeadingStyle ];
class LinkBehavior extends Behavior {
onCreate(link, $) {
this.$ = $;
}
onTouchBegan(link) {
link.state = 1;
}
onTouchEnded(link) {
link.state = 0;
trace(this.$ + "\n");
}
};
class TextBehavior extends Behavior {
onDisplaying(text) {
this.index = 0;
text.duration = 1000;
text.interval = 1000;
text.start();
}
onFinished(text) {
let index = this.index + 1;
if (index >= styles.length) index = 0;
this.index = index;
text.style = styles[index];
text.time = 0;
text.start();
}
};
let TestApplication = Application.template($ => ({
skin:blackSkin, style:textStyle,
contents: [
Text($, {
left:0, right:0, top:0, skin:whiteSkin, style:centerStyle, Behavior:TextBehavior, active:true,
blocks: [
{ spans: [
{ style:redStyle, spans: "Lorem ipsum", link:Link("tutu", { Behavior:LinkBehavior }) },
" dolor sit amet, consectetur adipiscing elit. ",
{ style:otherStyle, spans: "Nulla", link:Link("toto", { Behavior:LinkBehavior }) },
" faucibus sodales ligula eu accumsan."
]},
{ spans: [
"Aliquam consectetur\neleifend",
{ style:redStyle, link:Link("titi", { Behavior:LinkBehavior }), spans: [
" molestie. ",
{ style:otherStyle, spans: "Sed" },
" dui est, ",
"suscipit vitae"
]},
" consequat a, aliquam eget nisl."
]},
]
}),
],
Behavior: class extends Behavior {
onDisplaying(application) {
if (application.height != 240 || application.width != 320)
trace("WARNING: This application was designed to run on a 320x240 screen.\n");
}
}
}));
export default new TestApplication(null, { displayListLength:4608 });