mirror of https://github.com/espruino/BangleApps
Update lib.js
Updated with feedback from @Ganblejs http://forum.espruino.com/comments/16512632/ Keyboard doesn't work again after going into the help screen, how does layout to re-establish callbacks on button presses?pull/1814/head
parent
4fe623caf9
commit
130e969883
|
@ -10,20 +10,20 @@ exports.input = function(options) {
|
|||
var letters = {
|
||||
"1":".,!?1","2":"ABC2","3":"DEF3",
|
||||
"4":"GHI4","5":"JKL5","6":"MNO6",
|
||||
"7":"PQRS7","8":"TUV8","9":"WXYZ9",
|
||||
"0":"_@:/0"
|
||||
"7":"PQRS7","8":"TUV80","9":"WXYZ9",
|
||||
//"0":"_@:/0"
|
||||
};
|
||||
var helpMessage = 'swipe:\nRight: Space\nLeft:Backspace\nUp/Down: Caps lock\n';
|
||||
|
||||
var charTimeout; // timeout after a key is pressed
|
||||
var charCurrent; // current character (index in letters)
|
||||
var charIndex; // index in letters[charCurrent]
|
||||
var caps = true;
|
||||
var layout;
|
||||
//var text = "";
|
||||
|
||||
function displayText() {
|
||||
layout.clear(layout.text);
|
||||
layout.text.label = text;
|
||||
layout.text.label = text.slice(-12);
|
||||
layout.render(layout.text);
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,6 @@ exports.input = function(options) {
|
|||
}
|
||||
|
||||
function newCharacter(ch) {
|
||||
text = text.replace("_", " ");
|
||||
displayText();
|
||||
charCurrent = ch;
|
||||
charIndex = 0;
|
||||
|
@ -72,39 +71,58 @@ exports.input = function(options) {
|
|||
charTimeout = setTimeout(function() {
|
||||
charTimeout = undefined;
|
||||
newCharacter();
|
||||
}, 750);
|
||||
}, 500);
|
||||
}
|
||||
|
||||
function onSwipe(dirLeftRight, dirUpDown) {
|
||||
if (dirUpDown) {
|
||||
setCaps();
|
||||
} else if (dirLeftRight == 1) {
|
||||
text += ' ';
|
||||
newCharacter();
|
||||
} else if (dirLeftRight == -1) {
|
||||
backspace();
|
||||
}
|
||||
}
|
||||
|
||||
function onHelp() {
|
||||
Bangle.removeListener("swipe", onSwipe);
|
||||
E.showPrompt(
|
||||
helpMessage, {title: "Help", buttons : {"Ok":true}}
|
||||
).then(function(v) {
|
||||
Bangle.on('swipe', onSwipe);
|
||||
layout.render();
|
||||
});
|
||||
}
|
||||
|
||||
return new Promise((resolve,reject) => {
|
||||
layout = new Layout( {
|
||||
type:"v", c: [
|
||||
{type:"txt", font:"10%", label:"", id:"text", filly:1, fillx:1},
|
||||
{type:"txt", font:"10%", label:text, id:"text", cb: l=>onHelp(), fillx:1},
|
||||
{type:"h", c: [
|
||||
{type:"btn", font:fontSize, label:letters[1], cb: l=>onKeyPad(1), id:'1', fillx:1 },
|
||||
{type:"btn", font:fontSize, label:letters[2], cb: l=>onKeyPad(2), id:'2', fillx:1 },
|
||||
{type:"btn", font:fontSize, label:letters[3], cb: l=>onKeyPad(3), id:'3', fillx:1 },
|
||||
{type:"btn", font:fontSize, label:letters[1], cb: l=>onKeyPad(1), id:'1', fillx:1, filly:1 },
|
||||
{type:"btn", font:fontSize, label:letters[2], cb: l=>onKeyPad(2), id:'2', fillx:1, filly:1 },
|
||||
{type:"btn", font:fontSize, label:letters[3], cb: l=>onKeyPad(3), id:'3', fillx:1, filly:1 },
|
||||
]},
|
||||
{type:"h", c: [
|
||||
{type:"btn", font:fontSize, label:letters[4], cb: l=>onKeyPad(4), id:'4', fillx:1 },
|
||||
{type:"btn", font:fontSize, label:letters[5], cb: l=>onKeyPad(5), id:'5', fillx:1 },
|
||||
{type:"btn", font:fontSize, label:letters[6], cb: l=>onKeyPad(6), id:'6', fillx:1 },
|
||||
{type:"h", filly:1, c: [
|
||||
{type:"btn", font:fontSize, label:letters[4], cb: l=>onKeyPad(4), id:'4', fillx:1, filly:1 },
|
||||
{type:"btn", font:fontSize, label:letters[5], cb: l=>onKeyPad(5), id:'5', fillx:1, filly:1 },
|
||||
{type:"btn", font:fontSize, label:letters[6], cb: l=>onKeyPad(6), id:'6', fillx:1, filly:1 },
|
||||
]},
|
||||
{type:"h", c: [
|
||||
{type:"btn", font:fontSize, label:letters[7], cb: l=>onKeyPad(7), id:'7', fillx:1 },
|
||||
{type:"btn", font:fontSize, label:letters[8], cb: l=>onKeyPad(8), id:'8', fillx:1 },
|
||||
{type:"btn", font:fontSize, label:letters[9], cb: l=>onKeyPad(9), id:'9', fillx:1 },
|
||||
]},
|
||||
{type:"h", c: [
|
||||
{type:"btn", font:fontSize, label:letters[0], cb: l=>onKeyPad(0), id:'0', fillx:1 },
|
||||
{type:"btn", font:fontSize, label:"^", cb: l=>setCaps(), id:'caps', fillx:1},
|
||||
{type:"btn", font:fontSize, label:"<", cb: l=>backspace(), fillx:1 },
|
||||
{type:"h", filly:1, c: [
|
||||
{type:"btn", font:fontSize, label:letters[7], cb: l=>onKeyPad(7), id:'7', fillx:1, filly:1 },
|
||||
{type:"btn", font:fontSize, label:letters[8], cb: l=>onKeyPad(8), id:'8', fillx:1, filly:1 },
|
||||
{type:"btn", font:fontSize, label:letters[9], cb: l=>onKeyPad(9), id:'9', fillx:1, filly:1 },
|
||||
]},
|
||||
]
|
||||
},{back: ()=>{
|
||||
Bangle.setUI();
|
||||
Bangle.removeListener("swipe", onSwipe);
|
||||
g.clearRect(Bangle.appRect);
|
||||
resolve(text);
|
||||
}});
|
||||
g.clearRect(Bangle.appRect);
|
||||
Bangle.on('swipe', onSwipe);
|
||||
layout.render();
|
||||
});
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue