Skip to content

Commit c6c5475

Browse files
committed
launch 0.25: Remove Vector Font size option (Vector fonts added as other font styles)
Add Height option to set menu item height independently of Font
1 parent fe14434 commit c6c5475

File tree

5 files changed

+64
-50
lines changed

5 files changed

+64
-50
lines changed

apps/launch/ChangeLog

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@
2525
0.23: Draw a placeholder screen right at the start to speed up apparent boot time
2626
0.24: Fix Launcher when a custom font from 2v26+ is specified (fix #3787)
2727
Fix fullscreen when fastloading the launcher. (TODO:fix back btn flicker)
28-
Fix showClocks setting not taking effect by now clearing cache when
29-
changing those settings.
28+
0.25: Fix showClocks setting not taking effect by now clearing cache when changing those settings.
29+
Remove Vector Font size option (Vector fonts added as other font styles)
30+
Add Height option to set menu item height independently of Font

apps/launch/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ The app is needed to display a menu with all the apps installed on your Bangle.
88
Settings
99
--------
1010

11-
- `Font` - The font used (`4x6`, `6x8`, `12x20`, `6x15` or `Vector`). Default `12x20`.
12-
- `Vector Font Size` - The size of the font if `Font` is set to `Vector`. Default `10`.
11+
- `Font` - The font to use when drawing menu items. Default `22`.
12+
- `Height` - The size of each menu item in the launched. Default `52` where icons are scaled 1:1.
1313
- `Show Clocks` - If set to `No` then clocks won't appear in the app list. Default `Yes`.
1414
- `Fullscreen` - If set to `Yes` then widgets won't be loaded. Default `No`.

apps/launch/app.js

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,35 @@
11
{ // must be inside our own scope here so that when we are unloaded everything disappears
22
let s = require("Storage");
33
// handle customised launcher
4-
let scaleval = 1, vectorval = 20, fonts = g.getFonts();
5-
let font = fonts.includes("12x20") ? "12x20" : "6x8:2";
6-
if (fonts.includes("22")) font="22"; // 2v26+
74
let settings = Object.assign({
85
showClocks: true,
9-
fullscreen: false
6+
fullscreen: false,
7+
height: 52
108
}, s.readJSON("launch.json", true) || {});
11-
if ("vectorsize" in settings)
12-
vectorval = parseInt(settings.vectorsize);
13-
if ("font" in settings){
14-
if(settings.font == "Vector"){
15-
scaleval = vectorval/20;
16-
font = "Vector"+(vectorval).toString();
17-
} else{
18-
font = settings.font;
19-
scaleval = g.setFont(font).stringMetrics("X").height / 20;
20-
}
9+
let font = settings.font;
10+
if (!font || font=="Vector"/*compat with old settings*/) {
11+
let fonts = g.getFonts();
12+
font = fonts.includes("12x20") ? "12x20" : "6x8:2";
13+
if (fonts.includes("22")) font="22"; // 2v26+
2114
}
22-
let height = 50*scaleval;
15+
let height = 0|Math.max(settings.height,12), pad = 2;
16+
let imgsize = height-pad*2, imgscale = imgsize/48;
2317

24-
// Now apps list is loaded - render
18+
// Load widgets if we need to
2519
if (!settings.fullscreen) {
2620
Bangle.loadWidgets();
2721
} else if (global.WIDGETS) {
2822
require("widget_utils").hide();
2923
}
30-
let R = Bangle.appRect;
31-
g.reset().clearRect(R).setColor("#888");
32-
for (var y=R.y;y<R.y2;y+=height) {
33-
g.drawRect(5*scaleval,y+5*scaleval,49*scaleval,y+49*scaleval) // image
34-
.drawRect(54*scaleval,y+20*scaleval,R.y2-16,y+34*scaleval); // text
24+
{ // Draw 'placeholder'
25+
let R = Bangle.appRect, mid = height/2, th = g.setFont(font).stringMetrics("X").height/2;
26+
g.reset().clearRect(R).setColor("#888");
27+
for (var y=R.y;y<R.y2;y+=height) {
28+
g.drawRect(pad*2,y+pad*2,imgsize-pad,y+imgsize-pad) // image
29+
.drawRect(imgsize+pad*2,y+mid-th,R.y2-R.w/3, y+mid+th); // text
30+
}
31+
g.flip();
3532
}
36-
g.flip();
3733

3834
// cache app list so launcher loads more quickly
3935
let launchCache = s.readJSON("launch.cache.json", true)||{};
@@ -62,10 +58,10 @@
6258
draw : (i, r) => {
6359
var app = apps[i];
6460
if (!app) return;
65-
g.clearRect((r.x),(r.y),(r.x+r.w-1), (r.y+r.h-1)).setFont(font).setFontAlign(-1,0).drawString(app.name,54*scaleval,r.y+(27*scaleval));
61+
g.clearRect(r).setFont(font).setFontAlign(-1,0).drawString(app.name,imgsize+pad*2,r.y+2+r.h/2);
6662
if (app.icon) {
6763
if (!app.img) app.img = s.read(app.icon); // load icon if it wasn't loaded
68-
try {g.drawImage(app.img,3*scaleval, r.y+(3*scaleval), {scale: scaleval});} catch(e){}
64+
try {g.drawImage(app.img, pad, r.y+pad, {scale: imgscale});} catch(e){}
6965
}
7066
},
7167
select : i => {
@@ -85,7 +81,7 @@
8581
if (lockTimeout) clearTimeout(lockTimeout);
8682
Bangle.removeListener("lock", lockHandler);
8783
// Restore widgets if they were hidden by fullscreen setting
88-
if (global.WIDGETS && settings.fullscreen) require("widget_utils").show();
84+
if (global.WIDGETS) require("widget_utils").show();
8985
}
9086
});
9187
g.flip(); // force a render before widgets have finished drawing
@@ -98,11 +94,12 @@
9894
lockTimeout = undefined;
9995
if (locked)
10096
lockTimeout = setTimeout(Bangle.showClock, 10000);
101-
}
97+
};
10298
Bangle.on("lock", lockHandler);
10399
};
100+
// Now apps list is loaded - render
104101
drawMenu();
105-
106-
if (!settings.fullscreen) // finally draw widgets
102+
// finally draw widgets
103+
if (!settings.fullscreen)
107104
Bangle.drawWidgets();
108-
}
105+
}

apps/launch/metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"id": "launch",
33
"name": "Launcher",
44
"shortName": "Launcher",
5-
"version": "0.24",
5+
"version": "0.25",
66
"description": "This is needed to display a menu allowing you to choose your own applications. You can replace this with a customised launcher.",
77
"readme": "README.md",
88
"icon": "app.png",

apps/launch/settings.js

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,58 @@
1-
// make sure to enclose the function in parentheses
21
(function(back) {
32
let settings = Object.assign({
43
showClocks: true,
5-
fullscreen: false
4+
fullscreen: false,
5+
height: 52
66
}, require("Storage").readJSON("launch.json", true) || {});
77

8-
let fonts = g.getFonts();
9-
function save(key, value) {
10-
settings[key] = value;
8+
let fonts = g.getFonts().filter(f=>f!="Vector");
9+
for (var f=10;f<20;f++) fonts.push("Vector"+f);
10+
let defaultfont = fonts.includes("12x20") ? "12x20" : "6x8:2";
11+
if (fonts.includes("22")) defaultfont="22"; // 2v26+
12+
13+
let heights = [28,40,52,64,76];
14+
15+
function save() {
1116
require("Storage").write("launch.json",settings);
1217
}
1318
function clearCache() {
14-
require("Storage").erase("launch.cache.json")
19+
require("Storage").erase("launch.cache.json");
1520
}
1621
const appMenu = {
1722
"": { "title": /*LANG*/"Launcher" },
1823
/*LANG*/"< Back": back,
1924
/*LANG*/"Font": {
20-
value: fonts.includes(settings.font)? fonts.indexOf(settings.font) : fonts.indexOf("12x20"),
25+
value: fonts.includes(settings.font)? fonts.indexOf(settings.font) : fonts.indexOf(defaultfont),
2126
min:0, max:fonts.length-1, step:1,wrap:true,
22-
onchange: (m) => {save("font", fonts[m])},
27+
onchange: (m) => {
28+
settings.font=fonts[m];
29+
save();
30+
},
2331
format: v => fonts[v]
2432
},
25-
/*LANG*/"Vector Font Size": {
26-
value: settings.vectorsize || 10,
27-
min:10, max: 20,step:1,wrap:true,
28-
onchange: (m) => {save("vectorsize", m)}
33+
/*LANG*/"Height": {
34+
value: heights.includes(settings.height) ? heights.indexOf(settings.height) : heights.indexOf(52),
35+
min:0, max: heights.length-1,step:1,wrap:true,
36+
format: v => heights[v]+"px",
37+
onchange: (m) => {
38+
settings.height=heights[m];
39+
save();
40+
}
2941
},
3042
/*LANG*/"Show Clocks": {
31-
value: settings.showClocks == true,
43+
value: !!settings.showClocks,
3244
onchange: (m) => {
33-
save("showClocks", m);
45+
settings.showClocks=m;
46+
save();
3447
clearCache();
3548
}
3649
},
3750
/*LANG*/"Fullscreen": {
38-
value: settings.fullscreen == true,
39-
onchange: (m) => { save("fullscreen", m) }
51+
value: !!settings.fullscreen,
52+
onchange: (m) => {
53+
settings.fullscreen=m;
54+
save();
55+
}
4056
}
4157
};
4258
E.showMenu(appMenu);

0 commit comments

Comments
 (0)