Draw widgets if present. Code more reliable.
parent
ed58888091
commit
fd6c1e83ed
|
|
@ -1,11 +1,5 @@
|
||||||
//Keep banglejs screen on for 100 sec at 0.55 power level for development purposes
|
|
||||||
//Bangle.setLCDTimeout(30);
|
|
||||||
//Bangle.setLCDPower(1);
|
|
||||||
|
|
||||||
exports.input = function(options) {
|
exports.input = function(options) {
|
||||||
"ram";
|
"ram";
|
||||||
//Bangle.loadWidgets();
|
|
||||||
//Bangle.drawWidgets();
|
|
||||||
options = options||{};
|
options = options||{};
|
||||||
var text = options.text;
|
var text = options.text;
|
||||||
if ("string"!=typeof text) text="";
|
if ("string"!=typeof text) text="";
|
||||||
|
|
@ -29,13 +23,16 @@ exports.input = function(options) {
|
||||||
|
|
||||||
var rectHeight = 40;
|
var rectHeight = 40;
|
||||||
|
|
||||||
|
|
||||||
var delSpaceLast;
|
var delSpaceLast;
|
||||||
|
|
||||||
function drawAbcRow() {
|
function drawAbcRow() {
|
||||||
g.clear();
|
g.clear();
|
||||||
|
try { // Draw widgets if they are present in the current app.
|
||||||
|
if (WIDGETS) Bangle.drawWidgets();
|
||||||
|
} catch (_) {}
|
||||||
g.setFont(SMALLFONT);
|
g.setFont(SMALLFONT);
|
||||||
g.setColor(ABCCOLOR);
|
g.setColor(ABCCOLOR);
|
||||||
|
g.setFontAlign(-1, -1, 0);
|
||||||
g.drawString(ABC, ABCPADDING, (R.y+R.h)/2);
|
g.drawString(ABC, ABCPADDING, (R.y+R.h)/2);
|
||||||
g.fillRect(0, (R.y+R.h)-26, (R.x+R.w), (R.y+R.h));
|
g.fillRect(0, (R.y+R.h)-26, (R.x+R.w), (R.y+R.h));
|
||||||
}
|
}
|
||||||
|
|
@ -43,6 +40,7 @@ exports.input = function(options) {
|
||||||
function drawNumRow() {
|
function drawNumRow() {
|
||||||
g.setFont(SMALLFONT);
|
g.setFont(SMALLFONT);
|
||||||
g.setColor(NUMCOLOR);
|
g.setColor(NUMCOLOR);
|
||||||
|
g.setFontAlign(-1, -1, 0);
|
||||||
g.drawString(NUM, NUMPADDING, (R.y+R.h)/4);
|
g.drawString(NUM, NUMPADDING, (R.y+R.h)/4);
|
||||||
|
|
||||||
g.fillRect(NUMPADDING, (R.y+R.h)-rectHeight*4/3, (R.x+R.w)-NUMPADDING, (R.y+R.h)-rectHeight*2/3);
|
g.fillRect(NUMPADDING, (R.y+R.h)-rectHeight*4/3, (R.x+R.w)-NUMPADDING, (R.y+R.h)-rectHeight*2/3);
|
||||||
|
|
@ -58,6 +56,7 @@ exports.input = function(options) {
|
||||||
g.setColor(0.7,0,0);
|
g.setColor(0.7,0,0);
|
||||||
g.fillRect(rectLen+5,4+20,rectLen+10,13+20);
|
g.fillRect(rectLen+5,4+20,rectLen+10,13+20);
|
||||||
g.setColor(1,1,1);
|
g.setColor(1,1,1);
|
||||||
|
g.setFontAlign(-1, -1, 0);
|
||||||
g.drawString(text.length<=27? text.substr(-27, 27) : '<- '+text.substr(-24,24), 5, 5+20);
|
g.drawString(text.length<=27? text.substr(-27, 27) : '<- '+text.substr(-24,24), 5, 5+20);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -74,6 +73,7 @@ exports.input = function(options) {
|
||||||
// Small character in list
|
// Small character in list
|
||||||
g.setColor(rowColor);
|
g.setColor(rowColor);
|
||||||
g.setFont(SMALLFONT);
|
g.setFont(SMALLFONT);
|
||||||
|
g.setFontAlign(-1, -1, 0);
|
||||||
g.drawString(char, typePadding + HLPrev*6, (R.y+R.h)/heightDivisor);
|
g.drawString(char, typePadding + HLPrev*6, (R.y+R.h)/heightDivisor);
|
||||||
// Large character
|
// Large character
|
||||||
g.setColor(BGCOLOR);
|
g.setColor(BGCOLOR);
|
||||||
|
|
@ -86,6 +86,7 @@ exports.input = function(options) {
|
||||||
// mark in the list
|
// mark in the list
|
||||||
g.setColor(HLCOLOR);
|
g.setColor(HLCOLOR);
|
||||||
g.setFont(SMALLFONT);
|
g.setFont(SMALLFONT);
|
||||||
|
g.setFontAlign(-1, -1, 0);
|
||||||
if (char != 'del' && char != 'space') g.drawString(char, typePadding + HL*6, (R.y+R.h)/heightDivisor);
|
if (char != 'del' && char != 'space') g.drawString(char, typePadding + HL*6, (R.y+R.h)/heightDivisor);
|
||||||
// show new large character
|
// show new large character
|
||||||
g.setFont(BIGFONT);
|
g.setFont(BIGFONT);
|
||||||
|
|
@ -93,12 +94,18 @@ exports.input = function(options) {
|
||||||
g.setFont(SMALLFONT);
|
g.setFont(SMALLFONT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function initDraw() {
|
||||||
|
//var R = Bangle.appRect; // To make sure it's properly updated. Not sure if this is needed.
|
||||||
drawAbcRow();
|
drawAbcRow();
|
||||||
drawNumRow();
|
drawNumRow();
|
||||||
updateTopString();
|
updateTopString();
|
||||||
|
}
|
||||||
|
initDraw();
|
||||||
|
//setTimeout(initDraw, 0); // So Bangle.appRect reads the correct environment. It would draw off to the side sometimes otherwise.
|
||||||
|
|
||||||
function changeCase(abcHL) {
|
function changeCase(abcHL) {
|
||||||
g.setColor(BGCOLOR);
|
g.setColor(BGCOLOR);
|
||||||
|
g.setFontAlign(-1, -1, 0);
|
||||||
g.drawString(ABC, ABCPADDING, (R.y+R.h)/2);
|
g.drawString(ABC, ABCPADDING, (R.y+R.h)/2);
|
||||||
if (ABC.charAt(abcHL) == ABC.charAt(abcHL).toUpperCase()) ABC = ABC.toLowerCase();
|
if (ABC.charAt(abcHL) == ABC.charAt(abcHL).toUpperCase()) ABC = ABC.toLowerCase();
|
||||||
else ABC = ABC.toUpperCase();
|
else ABC = ABC.toUpperCase();
|
||||||
|
|
@ -148,14 +155,6 @@ exports.input = function(options) {
|
||||||
typePrev = 'abc';
|
typePrev = 'abc';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 12345678901234567890
|
// 12345678901234567890
|
||||||
// Choose number or puctuation by draging on green rectangle
|
// Choose number or puctuation by draging on green rectangle
|
||||||
else if ((event.y < ( (R.y+R.h) - 12 )) && (event.y > ( (R.y+R.h) - 52 ))) {
|
else if ((event.y < ( (R.y+R.h) - 12 )) && (event.y > ( (R.y+R.h) - 52 ))) {
|
||||||
|
|
@ -210,13 +209,6 @@ exports.input = function(options) {
|
||||||
typePrev = 'num';
|
typePrev = 'num';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Make a space or backspace by swiping right or left on screen above green rectangle
|
// Make a space or backspace by swiping right or left on screen above green rectangle
|
||||||
else if (event.y > 20+4) {
|
else if (event.y > 20+4) {
|
||||||
if (event.b == 0) {
|
if (event.b == 0) {
|
||||||
|
|
@ -252,14 +244,5 @@ exports.input = function(options) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
/* return new Promise((resolve,reject) => {
|
|
||||||
Bangle.setUI({mode:"custom", back:()=>{
|
|
||||||
Bangle.setUI();
|
|
||||||
g.clearRect(Bangle.appRect);
|
|
||||||
Bangle.setUI();
|
|
||||||
resolve(text);
|
|
||||||
}});
|
|
||||||
}); */
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue