Merge pull request #2895 from halemmerich/iconlauncher

iconlaunch - Better performance
master
Gordon Williams 2023-07-27 09:09:30 +01:00 committed by GitHub
commit 528815d3c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 58 additions and 34 deletions

View File

@ -22,3 +22,4 @@
(So that widgets are still hidden if launcher is fast-loaded) (So that widgets are still hidden if launcher is fast-loaded)
0.16: Use firmware provided E.showScroller method 0.16: Use firmware provided E.showScroller method
0.17: fix fullscreen with oneClickExit 0.17: fix fullscreen with oneClickExit
0.18: Better performance

View File

@ -9,7 +9,6 @@
timeOut:"Off" timeOut:"Off"
}, s.readJSON("iconlaunch.json", true) || {}); }, s.readJSON("iconlaunch.json", true) || {});
if (!settings.fullscreen) { if (!settings.fullscreen) {
Bangle.loadWidgets(); Bangle.loadWidgets();
Bangle.drawWidgets(); Bangle.drawWidgets();
@ -34,42 +33,66 @@
s.writeJSON("iconlaunch.cache.json", launchCache); s.writeJSON("iconlaunch.cache.json", launchCache);
} }
// cache items
const ICON_MISSING = s.read("iconlaunch.na.img");
let count = 0;
let selectedItem = -1; let selectedItem = -1;
const R = Bangle.appRect; const R = Bangle.appRect;
const iconSize = 48; const iconSize = 48;
const appsN = Math.floor(R.w / iconSize); const appsN = Math.floor(R.w / iconSize);
const whitespace = (R.w - appsN * iconSize) / (appsN + 1); const whitespace = Math.floor((R.w - appsN * iconSize) / (appsN + 1));
const iconYoffset = Math.floor(whitespace/4)-1;
const itemSize = iconSize + whitespace; const itemSize = iconSize + whitespace;
launchCache.items = {};
for (let c of launchCache.apps){
let i = Math.floor(count/appsN);
if (!launchCache.items[i])
launchCache.items[i] = {};
launchCache.items[i][(count%3)] = c;
count++;
}
let texted;
let drawItem = function(itemI, r) { let drawItem = function(itemI, r) {
"jit";
let x = whitespace;
let i = itemI * appsN - 1;
let selectedApp;
let c;
let selectedRect;
let item = launchCache.items[itemI];
if (texted == itemI){
g.clearRect(r.x, r.y, r.x + r.w - 1, r.y + r.h - 1); g.clearRect(r.x, r.y, r.x + r.w - 1, r.y + r.h - 1);
let x = 0; texted = undefined;
for (let i = itemI * appsN; i < appsN * (itemI + 1); i++) {
if (!launchCache.apps[i]) break;
x += whitespace;
if (!launchCache.apps[i].icon) {
g.setFontAlign(0, 0, 0).setFont("12x20:2").drawString("?", x + r.x + iconSize / 2, r.y + iconSize / 2);
} else {
if (!launchCache.apps[i].icondata) launchCache.apps[i].icondata = s.read(launchCache.apps[i].icon);
g.drawImage(launchCache.apps[i].icondata, x + r.x, r.y);
} }
for (c of item) {
i++;
let id = c.icondata || (c.iconData = (c.icon ? s.read(c.icon) : ICON_MISSING));
g.drawImage(id,x + r.x - 1, r.y + iconYoffset - 1, x + r.x + iconSize, r.y + iconYoffset + iconSize);
if (selectedItem == i) { if (selectedItem == i) {
g.drawRect( selectedApp = c;
selectedRect = [
x + r.x - 1, x + r.x - 1,
r.y - 1, r.y + iconYoffset - 1,
x + r.x + iconSize + 1, x + r.x + iconSize,
r.y + iconSize + 1 r.y + iconYoffset + iconSize
); ];
} }
x += iconSize; x += iconSize + whitespace;
}
if (selectedRect) {
g.drawRect.apply(null, selectedRect);
drawText(itemI, r.y, selectedApp);
texted=itemI;
} }
drawText(itemI, r.y);
}; };
let drawText = function(i, appY) { let drawText = function(i, appY, selectedApp) {
const selectedApp = launchCache.apps[selectedItem]; "jit";
const idy = (selectedItem - (selectedItem % 3)) / 3; const idy = (selectedItem - (selectedItem % 3)) / 3;
if (!selectedApp || i != idy) return; if (i != idy) return;
appY = appY + itemSize/2; appY = appY + itemSize/2;
g.setFontAlign(0, 0, 0); g.setFontAlign(0, 0, 0);
g.setFont("12x20"); g.setFont("12x20");

View File

@ -2,7 +2,7 @@
"id": "iconlaunch", "id": "iconlaunch",
"name": "Icon Launcher", "name": "Icon Launcher",
"shortName" : "Icon launcher", "shortName" : "Icon launcher",
"version": "0.17", "version": "0.18",
"icon": "app.png", "icon": "app.png",
"description": "A launcher inspired by smartphones, with an icon-only scrollable menu.", "description": "A launcher inspired by smartphones, with an icon-only scrollable menu.",
"tags": "tool,system,launcher", "tags": "tool,system,launcher",
@ -10,7 +10,8 @@
"supports": ["BANGLEJS2"], "supports": ["BANGLEJS2"],
"storage": [ "storage": [
{ "name": "iconlaunch.app.js", "url": "app.js" }, { "name": "iconlaunch.app.js", "url": "app.js" },
{ "name": "iconlaunch.settings.js", "url": "settings.js" } { "name": "iconlaunch.settings.js", "url": "settings.js" },
{ "name": "iconlaunch.na.img", "url": "na.img" }
], ],
"data": [{"name":"iconlaunch.json"},{"name":"iconlaunch.cache.json"}], "data": [{"name":"iconlaunch.json"},{"name":"iconlaunch.cache.json"}],
"screenshots": [{ "url": "screenshot1.png" }, { "url": "screenshot2.png" }], "screenshots": [{ "url": "screenshot1.png" }, { "url": "screenshot2.png" }],

BIN
apps/iconlaunch/na.img Normal file

Binary file not shown.

View File

@ -16,8 +16,7 @@
} }
const timeOutChoices = [/*LANG*/"Off", "10s", "15s", "20s", "30s"]; const timeOutChoices = [/*LANG*/"Off", "10s", "15s", "20s", "30s"];
const appMenu = { const appMenu = {
"": { "title": /*LANG*/"Launcher" }, "": { "title": /*LANG*/"Launcher", back: back },
/*LANG*/"< Back": back,
/*LANG*/"Show Clocks": { /*LANG*/"Show Clocks": {
value: settings.showClocks == true, value: settings.showClocks == true,
onchange: (m) => { onchange: (m) => {