-
Notifications
You must be signed in to change notification settings - Fork 239
/
Copy pathmain.js
112 lines (102 loc) · 3.47 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
* 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";
import {VerticalExpandingKeyboard} from "keyboard";
import {KeyboardField} from "common/keyboard";
const PASSWORDMODE = false; //Set to true to replace input with asterisks, false for clear text.
const TRANSITION = true; //Set to true to transition keyboard in and out.
const HeaderSkin = Skin.template(Object.freeze({fill:"#0082ff"}));
const FieldSkin = Skin.template(Object.freeze({fill:"white"}));
const BackgroundSkin = Skin.template(Object.freeze({ fill:"white" }));
const KeyboardStyle = Style.template(Object.freeze({ font:"18px Roboto", color:"black" }));
const FieldStyle = Style.template(Object.freeze({ font:"20px Open Sans", color: "black", horizontal:"left", vertical:"middle" }));
const HeaderStyle = Style.template(Object.freeze({ font:"20px Open Sans", color: "white", horizontal:"left", vertical:"middle" }));
const ModdableLogoTexture = Texture.template(Object.freeze({ path:"moddable-logo-mask.png" }));
const ModdableLogoSkin = Skin.template(Object.freeze({ Texture:ModdableLogoTexture, x:0, y:0, width:88, height:34, color:"white" }));
const Header = Container.template($ => ({
contents: [
Content($, { left:76, top:0, bottom:0, Skin:ModdableLogoSkin }),
]
}));
const KeyboardContainer = Column.template($ => ({
left:0, right:0, top:0, bottom:0, active:true,
contents:[
Header($, {
anchor: "HEADER", left:0, right:0, height:40,
Style:HeaderStyle, Skin:HeaderSkin
}),
KeyboardField($, {
anchor:"FIELD", password:PASSWORDMODE, left:32, right:0, top:30, bottom:30,
Skin:FieldSkin, Style:FieldStyle, visible:false
}),
Container($, {
anchor: "KEYBOARD", left:0, right:0, bottom:0, height:185,
Skin:BackgroundSkin
}),
],
Behavior: class extends Behavior {
onCreate(column, data){
this.data = data;
this.addKeyboard();
}
onTouchEnded(column){
if (1 != this.data.KEYBOARD.length)
this.addKeyboard();
}
addKeyboard() {
this.data.KEYBOARD.add(VerticalExpandingKeyboard(this.data, {
style:new KeyboardStyle(), target:this.data.FIELD, doTransition:TRANSITION
}));
}
}
}));
class KeyboardAppBehavior extends Behavior {
onCreate(application, data) {
this.data = data;
}
onDisplaying(application) {
if (application.height != 320 || application.width != 240)
trace("WARNING: This application was designed to run on a 240x320 screen.\n");
}
onKeyboardRowsContracted(application) {
// keyboard rows contracted back to 1x view
}
onKeyboardRowsExpanded(application) {
// keyboard rows expanded
}
onKeyboardOK(application, string) {
trace(`String is: ${string}\n`);
this.data.FIELD.visible = false;
}
onKeyboardTransitionFinished(application, out) {
if (out) {
let keyboard = this.data.KEYBOARD;
keyboard.remove(keyboard.first);
}
else {
this.data.FIELD.visible = true;
}
}
}
Object.freeze(KeyboardAppBehavior.prototype);
const KeyboardApp = Application.template($ => ({
active:true, Skin:BackgroundSkin,
Behavior:KeyboardAppBehavior,
contents: [
KeyboardContainer($),
],
}));
export default function() {
new KeyboardApp({}, { commandListLength:2448, displayListLength:2600, touchCount:1 });
}