mirror of https://github.com/espruino/BangleApps
Shrink label to fit
parent
3adb3f1c2b
commit
d9cb12bdf1
|
@ -118,9 +118,10 @@ function drawToken(id, r) {
|
||||||
var y1 = r.y;
|
var y1 = r.y;
|
||||||
var x2 = r.x + r.w - 1;
|
var x2 = r.x + r.w - 1;
|
||||||
var y2 = r.y + r.h - 1;
|
var y2 = r.y + r.h - 1;
|
||||||
var adj, sz;
|
var adj, lbl, sz;
|
||||||
g.setClipRect(Math.max(x1, Bangle.appRect.x ), Math.max(y1, Bangle.appRect.y ),
|
g.setClipRect(Math.max(x1, Bangle.appRect.x ), Math.max(y1, Bangle.appRect.y ),
|
||||||
Math.min(x2, Bangle.appRect.x2), Math.min(y2, Bangle.appRect.y2));
|
Math.min(x2, Bangle.appRect.x2), Math.min(y2, Bangle.appRect.y2));
|
||||||
|
lbl = tokens[id].label.substr(0, 10);
|
||||||
if (id == state.curtoken) {
|
if (id == state.curtoken) {
|
||||||
// current token
|
// current token
|
||||||
g.setColor(g.theme.fgH);
|
g.setColor(g.theme.fgH);
|
||||||
|
@ -132,13 +133,16 @@ function drawToken(id, r) {
|
||||||
} else {
|
} else {
|
||||||
g.setColor(g.theme.fg);
|
g.setColor(g.theme.fg);
|
||||||
g.setBgColor(g.theme.bg);
|
g.setBgColor(g.theme.bg);
|
||||||
g.setFont("Vector", tokendigitsheight);
|
sz = tokendigitsheight;
|
||||||
|
do {
|
||||||
|
g.setFont("Vector", sz--);
|
||||||
|
} while (g.stringWidth(lbl) > r.w);
|
||||||
// center in box
|
// center in box
|
||||||
g.setFontAlign(0, 0, 0);
|
g.setFontAlign(0, 0, 0);
|
||||||
adj = (y1 + y2) / 2;
|
adj = (y1 + y2) / 2;
|
||||||
}
|
}
|
||||||
g.clearRect(x1, y1, x2, y2);
|
g.clearRect(x1, y1, x2, y2);
|
||||||
g.drawString(tokens[id].label.substr(0, 10), (x1 + x2) / 2, adj, false);
|
g.drawString(lbl, (x1 + x2) / 2, adj, false);
|
||||||
if (id == state.curtoken) {
|
if (id == state.curtoken) {
|
||||||
if (tokens[id].period > 0) {
|
if (tokens[id].period > 0) {
|
||||||
// timed - draw progress bar
|
// timed - draw progress bar
|
||||||
|
|
Loading…
Reference in New Issue