Added comments and reorgranized

pull/2827/head
stweedo 2023-06-16 09:56:25 -05:00
parent a15c69f068
commit 004e5ae376
1 changed files with 24 additions and 13 deletions

View File

@ -1,19 +1,27 @@
(function() { (function() {
let w = g.getWidth(); // 1. Module dependencies and initial configurations
let h = g.getHeight();
let totalWidth, totalHeight;
let touchHandler;
let dragHandler;
let drawTimeout;
let enableSuffix = true;
let storage = require("Storage"); let storage = require("Storage");
let locale = require("locale"); let locale = require("locale");
let date = new Date(); let date = new Date();
let bgImage; let bgImage;
let boxesConfig = storage.readJSON('boxclk.json', 1) || {}; let boxesConfig = storage.readJSON('boxclk.json', 1) || {};
let boxes = {}; let boxes = {};
let boxPos = {};
let isDragging = {};
let wasDragging = {};
// 2. Graphical and visual configurations
let w = g.getWidth();
let h = g.getHeight();
let totalWidth, totalHeight;
let enableSuffix = true;
let drawTimeout;
// 3. Handlers
let touchHandler;
let dragHandler;
// 4. Font loading function
function loadCustomFont() { function loadCustomFont() {
Graphics.prototype.setFontBrunoAce = function() { Graphics.prototype.setFontBrunoAce = function() {
// Actual height 23 (24 - 2) // Actual height 23 (24 - 2)
@ -26,6 +34,7 @@
}; };
} }
// 5. Initial settings of boxes and their positions
for (let key in boxesConfig) { for (let key in boxesConfig) {
if (key === 'bg' && boxesConfig[key].img) { if (key === 'bg' && boxesConfig[key].img) {
bgImage = storage.read(boxesConfig[key].img); bgImage = storage.read(boxesConfig[key].img);
@ -34,10 +43,6 @@
} }
} }
let boxPos = {};
let isDragging = {};
let wasDragging = {};
Object.keys(boxes).forEach((boxKey) => { Object.keys(boxes).forEach((boxKey) => {
let boxConfig = boxes[boxKey]; let boxConfig = boxes[boxKey];
boxPos[boxKey] = { boxPos[boxKey] = {
@ -48,6 +53,7 @@
wasDragging[boxKey] = false; wasDragging[boxKey] = false;
}); });
// 6. Text and drawing functions
let g_drawString = g.drawString; let g_drawString = g.drawString;
g.drawString = function(box, str, x, y) { g.drawString = function(box, str, x, y) {
outlineText(box, str, x, y); outlineText(box, str, x, y);
@ -84,6 +90,7 @@
}; };
} }
// 7. Date and time related functions
function getDate() { function getDate() {
const date = new Date(); const date = new Date();
const dayOfMonth = date.getDate(); const dayOfMonth = date.getDate();
@ -107,6 +114,7 @@
return locale.dow(date, 0); return locale.dow(date, 0);
} }
// 8. Main draw function
function draw(boxes) { function draw(boxes) {
date = new Date(); date = new Date();
g.clear(); g.clear();
@ -146,6 +154,7 @@
} }
} }
// 9. Setup function to configure event handlers
function setup() { function setup() {
// Define the touchHandler function // Define the touchHandler function
touchHandler = function(zone, e) { touchHandler = function(zone, e) {
@ -210,6 +219,7 @@
draw(boxes); draw(boxes);
} }
// 10. Helper function for touch event
function touchInText(e, boxItem, boxKey) { function touchInText(e, boxItem, boxKey) {
calcBoxSize(boxItem); calcBoxSize(boxItem);
const pos = calcBoxPos(boxKey); const pos = calcBoxPos(boxKey);
@ -219,7 +229,8 @@
e.y <= pos.y2; e.y <= pos.y2;
} }
// 11. Main execution part
Bangle.loadWidgets(); Bangle.loadWidgets();
require("widget_utils").swipeOn(); require("widget_utils").swipeOn();
setup(); setup();
})(); })();