widpedom 0.19: Allow goal in large font mode
Stop goal drawing outside widget area
Fix issue with widget overwrite in large font mode
Memory usage enhancements
master
parent
7631587e43
commit
2fd4d4ded1
|
|
@ -1184,7 +1184,7 @@
|
|||
{ "id": "widpedom",
|
||||
"name": "Pedometer widget",
|
||||
"icon": "widget.png",
|
||||
"version":"0.18",
|
||||
"version":"0.19",
|
||||
"description": "Daily pedometer widget",
|
||||
"tags": "widget,b2",
|
||||
"type":"widget",
|
||||
|
|
|
|||
|
|
@ -15,3 +15,7 @@
|
|||
0.16: Settings option to show large digits in widget area
|
||||
0.17: Cope with 2v10+ firmware sometimes reporting >1 step
|
||||
0.18: Adjust widget width when displaying large text
|
||||
0.19: Allow goal in large font mode
|
||||
Stop goal drawing outside widget area
|
||||
Fix issue with widget overwrite in large font mode
|
||||
Memory usage enhancements
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@
|
|||
onchange: (g) => {
|
||||
s.goal = g
|
||||
s.progress = !!g
|
||||
save()
|
||||
save();
|
||||
},
|
||||
},
|
||||
'Show Progress': {
|
||||
|
|
@ -40,7 +40,7 @@
|
|||
format: () => (s.progress ? 'Yes' : 'No'),
|
||||
onchange: () => {
|
||||
s.progress = !s.progress
|
||||
save()
|
||||
save();
|
||||
},
|
||||
},
|
||||
'Large Digits': {
|
||||
|
|
@ -48,7 +48,7 @@
|
|||
format: () => (s.large ? 'Yes' : 'No'),
|
||||
onchange: () => {
|
||||
s.large = !s.large
|
||||
save()
|
||||
save();
|
||||
},
|
||||
},
|
||||
'Hide Widget': {
|
||||
|
|
@ -56,7 +56,7 @@
|
|||
format: () => (s.hide ? 'Yes' : 'No'),
|
||||
onchange: () => {
|
||||
s.hide = !s.hide
|
||||
save()
|
||||
save();
|
||||
},
|
||||
},
|
||||
'< Back': back,
|
||||
|
|
|
|||
|
|
@ -23,78 +23,6 @@
|
|||
return (key in settings) ? settings[key] : DEFAULTS[key];
|
||||
}
|
||||
|
||||
function drawProgress(stps) {
|
||||
if (setting('hide')) return;
|
||||
const width = 24, half = width/2;
|
||||
const goal = setting('goal'), left = Math.max(goal-stps,0);
|
||||
const c = left ? "#00f" : "#090"; // blue or dark green
|
||||
g.setColor(c).fillCircle(this.x + half, this.y + half, half);
|
||||
const TAU = Math.PI*2;
|
||||
if (left) {
|
||||
const f = left/goal; // fraction to blank out
|
||||
let p = [];
|
||||
p.push(half,half);
|
||||
p.push(half,0);
|
||||
if(f>1/8) p.push(0,0);
|
||||
if(f>2/8) p.push(0,half);
|
||||
if(f>3/8) p.push(0,width);
|
||||
if(f>4/8) p.push(half,width);
|
||||
if(f>5/8) p.push(width,width);
|
||||
if(f>6/8) p.push(width,half);
|
||||
if(f>7/8) p.push(width,0);
|
||||
p.push(half - Math.sin(f * TAU) * half);
|
||||
p.push(half - Math.cos(f * TAU) * half);
|
||||
for (let i = p.length; i; i -= 2) {
|
||||
p[i - 2] += this.x;
|
||||
p[i - 1] += this.y;
|
||||
}
|
||||
g.setColor(g.theme.bg).fillPoly(p);
|
||||
}
|
||||
}
|
||||
|
||||
// show the step count in the widget area in a readable sized font
|
||||
function draw_large(st) {
|
||||
this.width = 12 * st.length + 3;
|
||||
g.reset();
|
||||
g.clearRect(this.x, this.y, this.x + this.width, this.y + 16); // erase background
|
||||
g.setColor(g.theme.fg);
|
||||
g.setFont("6x8",2);
|
||||
g.setFontAlign(-1, -1);
|
||||
g.drawString(st, this.x + 4, this.y + 2);
|
||||
}
|
||||
|
||||
// draw your widget
|
||||
function draw() {
|
||||
if (setting('hide')) return;
|
||||
var width = 24;
|
||||
if (stp_today > 99999){
|
||||
stp_today = stp_today % 100000; // cap to five digits + comma = 6 characters
|
||||
}
|
||||
let stps = stp_today.toString();
|
||||
if (setting('large')) {
|
||||
draw_large.call(this, stps);
|
||||
return;
|
||||
}
|
||||
g.reset().clearRect(this.x, this.y, this.x + width, this.y + 23); // erase background
|
||||
if (setting('progress')){ drawProgress.call(this, stps); }
|
||||
g.setColor(g.theme.fg);
|
||||
if (stps.length > 3){
|
||||
stps = stps.slice(0,-3) + "," + stps.slice(-3);
|
||||
g.setFont("4x6", 1); // if big, shrink text to fix
|
||||
} else {
|
||||
g.setFont("6x8", 1);
|
||||
}
|
||||
g.setFontAlign(0, 0); // align to x: center, y: center
|
||||
g.drawString(stps, this.x+width/2, this.y+19);
|
||||
// on low bpp screens, draw 1 bit. Currently there is no getBPP so we just do it based on resolution
|
||||
g.drawImage(atob("CgoCLguH9f2/7+v6/79f56CtAAAD9fw/n8Hx9A=="),this.x+(width-10)/2,this.y+2);
|
||||
}
|
||||
|
||||
function reload() {
|
||||
loadSettings()
|
||||
draw()
|
||||
}
|
||||
|
||||
Bangle.on('step', stepCount => {
|
||||
var steps = stepCount-lastStepCount;
|
||||
if (lastStepCount===undefined || steps<0) steps=1;
|
||||
|
|
@ -115,11 +43,11 @@
|
|||
}
|
||||
lastUpdate = date
|
||||
//console.log("up: " + up + " stp: " + stp_today + " " + date.toString());
|
||||
if (Bangle.isLCDOn()) WIDGETS["wpedom"].draw();
|
||||
WIDGETS["wpedom"].redraw();
|
||||
});
|
||||
// redraw when the LCD turns on
|
||||
Bangle.on('lcdPower', function(on) {
|
||||
if (on) WIDGETS["wpedom"].draw();
|
||||
if (on) WIDGETS["wpedom"].redraw();
|
||||
});
|
||||
// When unloading, save state
|
||||
E.on('kill', () => {
|
||||
|
|
@ -134,10 +62,80 @@
|
|||
|
||||
// add your widget
|
||||
WIDGETS["wpedom"]={area:"tl",width:26,
|
||||
draw:draw,
|
||||
reload:reload,
|
||||
getSteps:()=>stp_today
|
||||
};
|
||||
redraw:function() { // work out the width, and queue a full redraw if needed
|
||||
let stps = stp_today.toString();
|
||||
let newWidth = 24;
|
||||
if (setting('hide'))
|
||||
newWidth = 0;
|
||||
else {
|
||||
if (setting('large')) {
|
||||
newWidth = 12 * stps.length + 3;
|
||||
if (setting('progress'))
|
||||
newWidth += 24;
|
||||
}
|
||||
}
|
||||
if (newWidth!=this.width) {
|
||||
// width has changed, re-layout all widgets
|
||||
this.width = newWidth;
|
||||
Bangle.drawWidgets();
|
||||
} else {
|
||||
// width not changed - just redraw
|
||||
WIDGETS["wpedom"].draw();
|
||||
}
|
||||
},
|
||||
draw:function() {
|
||||
if (setting('hide')) return;
|
||||
if (stp_today > 99999)
|
||||
stp_today = stp_today % 100000; // cap to five digits + comma = 6 characters
|
||||
let stps = stp_today.toString();
|
||||
g.reset().clearRect(this.x, this.y, this.x + this.width, this.y + 23); // erase background
|
||||
if (setting('progress')) {
|
||||
const width = 23, half = 11;
|
||||
const goal = setting('goal'), left = Math.max(goal-stps,0);
|
||||
// blue or dark green
|
||||
g.setColor(left ? "#08f" : "#080").fillCircle(this.x + half, this.y + half, half);
|
||||
if (left) {
|
||||
const TAU = Math.PI*2;
|
||||
const f = left/goal; // fraction to blank out
|
||||
let p = [];
|
||||
p.push(half,half);
|
||||
p.push(half,0);
|
||||
if(f>1/8) p.push(0,0);
|
||||
if(f>2/8) p.push(0,half);
|
||||
if(f>3/8) p.push(0,width);
|
||||
if(f>4/8) p.push(half,width);
|
||||
if(f>5/8) p.push(width,width);
|
||||
if(f>6/8) p.push(width,half);
|
||||
if(f>7/8) p.push(width,0);
|
||||
p.push(half - Math.sin(f * TAU) * half);
|
||||
p.push(half - Math.cos(f * TAU) * half);
|
||||
g.setColor(g.theme.bg).fillPoly(g.transformVertices(p,{x:this.x,y:this.y}));
|
||||
}
|
||||
g.reset();
|
||||
}
|
||||
if (setting('large')) {
|
||||
g.setFont("6x8",2);
|
||||
g.setFontAlign(-1, 0);
|
||||
g.drawString(stps, this.x + (setting('progress')?28:4), this.y + 12);
|
||||
} else {
|
||||
let w = 24;
|
||||
if (stps.length > 3){
|
||||
stps = stps.slice(0,-3) + "," + stps.slice(-3);
|
||||
g.setFont("4x6", 1); // if big, shrink text to fix
|
||||
} else {
|
||||
g.setFont("6x8", 1);
|
||||
}
|
||||
g.setFontAlign(0, 0); // align to x: center, y: center
|
||||
g.drawString(stps, this.x+w/2, this.y+19);
|
||||
g.drawImage(atob("CgoCLguH9f2/7+v6/79f56CtAAAD9fw/n8Hx9A=="),this.x+(w-10)/2,this.y+2);
|
||||
}
|
||||
},
|
||||
reload:function() {
|
||||
loadSettings();
|
||||
WIDGETS["wpedom"].redraw();
|
||||
},
|
||||
getSteps:()=>stp_today
|
||||
};
|
||||
// Load data at startup
|
||||
let pedomData = require("Storage").readJSON(PEDOMFILE,1);
|
||||
if (pedomData) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue