Skip to content

Commit 24a5bde

Browse files
author
thyttan
committed
Merge branch 'bigclkinfo' into app-loader
2 parents 4a1610e + c5c63c0 commit 24a5bde

File tree

3 files changed

+44
-16
lines changed

3 files changed

+44
-16
lines changed

apps/bigclkinfo/ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
0.01: New Clock!
2+
0.02: Add backgrounds library

apps/bigclkinfo/app.js

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,27 @@ if (isClock) {
77
Bangle.setUI("clock");
88
}
99

10+
// once at the start
11+
let background = require("clockbg");
12+
13+
// to fill the whole area
14+
background.fillRect(Bangle.appRect.x+3, Bangle.appRect.y+3, Bangle.appRect.x+Bangle.appRect.w-5, Bangle.appRect.y+Bangle.appRect.h-5);
15+
// if you ever need to reload to a new background (this could take ~100ms)
16+
//background.reload();
17+
18+
// Call this to unload (free memory - eg in .remove when fast loading)
19+
//background.unload();
20+
21+
// If .unload has been called and you might have fast-loaded back, call .load to ensure everything is loaded again!
22+
// It won't reload if it's already been loaded
23+
//background.load();
24+
1025
// Load the clock infos
1126
let clockInfoItems = require("clock_info").load();
27+
if (clockInfoItems[0].items[6]) { // TODO: Should maybe be more robust against changes to clock info, i.e. search for "clock" among items.
28+
let clockItem = clockInfoItems[0].items.pop();
29+
clockInfoItems[0].items.unshift(clockItem);
30+
}
1231
// Add the
1332
let clockInfoMenu = require("clock_info").addInteractive(clockInfoItems, {
1433
// Add the dimensions we're rendering to here - these are used to detect taps on the clock info area
@@ -20,21 +39,25 @@ let clockInfoMenu = require("clock_info").addInteractive(clockInfoItems, {
2039
// info: data returned from itm.get() containing text/img/etc
2140
// options: options passed into addInteractive
2241
// Clear the background
23-
g.reset().clearRect(options.x, options.y, options.x+options.w-1, options.y+options.h-1);
42+
background.fillRect(options.x, options.y, options.x+options.w-1, options.y+options.h-1);
2443
// indicate focus - we're using a border, but you could change color?
25-
if (options.focus) g.drawRect(options.x, options.y, options.x+options.w-1, options.y+options.h-1); // show if focused
44+
if (options.focus) g.fillRect(options.x, options.y, options.x+options.w-1, options.y+options.h-1); // show if focused
45+
background.fillRect(options.x+3, options.y+3, options.x+options.w-5, options.y+options.h-5);
2646
// we're drawing center-aligned here
2747
var midx = options.x+options.w/2;
28-
let scale = 5;
29-
if (info.img) g.drawImage(info.img, midx-12*scale,options.y+4, {scale:scale}); // draw the image
30-
g.setFont("6x8:2").setFontAlign(0,1).drawString(info.text, midx,options.y+160); // draw the text
48+
let scale = 4;
49+
if (info.img) require("clock_info").drawBorderedImage(info.img, midx-12*scale,options.y+10, {scale:scale}); // draw the image
50+
let foundFontText = g.findFont(info.text, {
51+
w : Bangle.appRect.w-9, // optional: width available (default = screen width)
52+
h : Bangle.appRect.h*2/5, // optional: height available (default = screen height)
53+
min : 10, // optional: min font height
54+
max : 60, // optional: max font height
55+
wrap : true, // optional: allow word wrap?
56+
trim : true // optional: trim to the specified height, add '...'
57+
}); // TODO: g.findFont returns max size 28px. Would be nice with bigger font if there's room.
58+
//print(foundFontText);
59+
g.setFont(foundFontText.font).setFontAlign(0,1).drawString(foundFontText.text, midx,options.y+165); // draw the text
3160
}
3261
});
33-
setTimeout(
34-
()=>{
35-
clockInfoMenu.menuA = 0;
36-
if (clockInfoItems[0].items[6]) clockInfoMenu.menuB = 6; // Assume clkinfoclk is at indices (0,6)
37-
clockInfoMenu.redraw()
38-
}, 5
39-
)
40-
E.prependListener("kill", ()=>{clockInfoMenu.menuA = 0; clockInfoMenu.menuB = 6;}) // reset to initial menu state to prepare for next launch.
62+
63+
E.prependListener("kill", ()=>{clockInfoMenu.menuA = 0; clockInfoMenu.menuB = 0;}) // reset to initial menu state to prepare for next launch.

apps/bigclkinfo/metadata.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
{ "id": "bigclkinfo",
22
"name": "Big Clock Info app",
33
"shortName":"Big Clkinfo",
4-
"version":"0.01",
4+
"version":"0.02",
55
"author": "thyttan",
66
"description": "One single big clock info. Full screen.",
77
"icon": "icon.png",
88
"type": "clock",
99
"tags": "clock,clkinfo,clk_info",
1010
"supports" : ["BANGLEJS2"],
1111
"readme": "README.md",
12-
"dependencies" : { "clock_info":"module",
13-
"clkinfoclk":"app" },
12+
"dependencies" : {
13+
"clock_info":"module",
14+
"clkinfoclk":"app",
15+
"clockbg":"module"
16+
},
17+
1418
"storage": [
1519
{"name":"bigclkinfo.app.js","url":"app.js"},
1620
{"name":"bigclkinfo.img","url":"app-icon.js","evaluate":true}

0 commit comments

Comments
 (0)