touchtimer: initial creation

pull/1183/head
crazysaem 2021-12-22 22:28:51 +00:00
parent d9d5926416
commit a382c6bd4f
6 changed files with 113 additions and 0 deletions

View File

@ -5062,5 +5062,21 @@
{"name":"ltherm.app.js","url":"app.js"}, {"name":"ltherm.app.js","url":"app.js"},
{"name":"ltherm.img","url":"icon.js","evaluate":true} {"name":"ltherm.img","url":"icon.js","evaluate":true}
] ]
},
{
"id": "touchtimer",
"name": "Touch Timer",
"shortName": "Touch Timer",
"version": "0.01",
"description": "Quickly and easily create a timer touch-only.",
"icon": "app.png",
"tags": "tools",
"supports": ["BANGLEJS2"],
"readme": "README.md",
"storage": [
{ "name": "touchtimer.app.js", "url": "app.js" },
{ "name": "touchtimer.boot.js", "url": "boot.js" },
{ "name": "touchtimer.img", "url": "app-icon.js", "evaluate": true }
]
} }
] ]

View File

@ -0,0 +1 @@
0.01: Initial creation of the touch timer app

View File

@ -0,0 +1,3 @@
# Touch Timer
Quickly and easily create a timer touch-only.

View File

@ -0,0 +1 @@
require("heatshrink").decompress(atob("mEwwkE/4A3mUQIAMRkYWQkBaFiQWQgMjn8zGYUDCxkxFA3zD4MfCxXygECMAURiReCDAM/IpUBFIJ2CAAIeB+ZJKBYI8BCwMBiABBDARSBC5EwFwMwEwUwh5FCEIJhJiEfGIIXC+IQBSwQeBNYR1Gn4xB+MDDYITBiEzFoIOCC4vwEAIxBAwQzBAoQtCBgaNEh4iEAwMwRQXxHgRnBLwsvFQJdCFoIGBl55DH4QAEEIK/BC4KjBC4RECiED+RnBXooxCn4uBKwPwgIiB+fxgQQCRwgeBLwRbBkAXBh5yCBwoACEAoVBC4fwJ4I+DC5EjJQQXDBYP/kJWDC4qmBBYYXFfIQXKiQvUL6AXGR5LzBR4YXIBAS/BC4UCeAQOFC4rvDN4LvCFYMgd4IXJmEABgMxC4bWBiADDC45EBZIRHBMYINCBQQXIIgIkB//wgIFDmBKBC5QNB+UDboU/kEzgCRBC5QTBNwUxLoZRDC5J5EmAqBkEAiYMCC5XzFIMRkECAgILDC5YYDAAUBIoQXNDAMhiMRkYJEC5oAKC7qKBACDfCK4IWRPwjqBkczAB0yGAcQGgYAOmByCfAYAP+MBC4QWR//yC4ciACMhC4YATC4T9BACUSLiQAdA="))

92
apps/touchtimer/app.js Normal file
View File

@ -0,0 +1,92 @@
var DEBUG = true;
var main = () => {
var button0 = new Button({ x1: 0, y1: 35, x2: 58, y1: 70 }, 0);
button0.draw();
button0.onClick((value) => {
log("button with value clicked");
log(value);
});
};
// lib functions
var log = (message) => {
if (DEBUG) {
console.log(JSON.stringify(message));
}
};
var touchHandlers = [];
Bangle.on("touch", (_button, xy) => {
touchHandlers.forEach((touchHandler) => {
touchHandler(xy);
});
});
var BUTTON_BORDER_WITH = 2;
class Button {
constructor(position, value) {
this.position = position;
this.value = value;
this.onClickCallbacks = [];
touchHandlers.push((xy) => {
var x = xy.x;
var y = xy.y;
if (
x >= this.position.x1 &&
x <= this.position.x2 &&
y >= this.position.y1 &&
y <= this.position.y2
) {
this.onClickCallbacks.forEach((onClickCallback) =>
onClickCallback(this.value)
);
}
});
}
draw() {
g.clear();
g.setColor(g.theme.fg);
g.fillRect(
this.position.x1,
this.position.y1,
this.position.x2,
this.position.y2
);
g.setColor(g.theme.bg);
g.fillRect(
this.position.x1 + BUTTON_BORDER_WITH,
this.position.y1 + BUTTON_BORDER_WITH,
this.position.x2 - BUTTON_BORDER_WITH,
this.position.y2 - BUTTON_BORDER_WITH
);
g.setColor(g.theme.fg);
g.setFontAlign(0, 0);
g.setFont("Vector", 40);
g.drawString(
this.value,
this.position.x2 - this.position.x1,
this.position.y2 - this.position.y1
);
}
onClick(callback) {
this.onClickCallbacks.push(callback);
}
}
// start main function
main();

BIN
apps/touchtimer/app.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB