Skip to content

Commit c28ee53

Browse files
committed
weather 0.28: Fix UV positioning, hide when 0
1 parent 7ace5bd commit c28ee53

File tree

2 files changed

+33
-29
lines changed

2 files changed

+33
-29
lines changed

apps/weather/ChangeLog

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@
2323
0.24: Redraw clock_info on update and provide color field for condition
2424
0.25: Added monochrome parameter to drawIcon in lib
2525
0.26: Expose update function (for use by iOS integration)
26-
0.27: Add UV index display
26+
0.27: Add UV index display
27+
0.28: Fix UV positioning, hide when 0

apps/weather/app.js

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,54 +9,56 @@ Bangle.loadWidgets();
99
var layout = new Layout({type:"v", bgCol: g.theme.bg, c: [
1010
{filly: 1},
1111
{type: "h", filly: 0, c: [
12-
{type: "v", width: g.getWidth()/2, c: [ // Vertical container for icon + UV
12+
{type: "v", width: g.getWidth()/2, c: [ // Vertical container for icon
1313
{type: "custom", fillx: 1, height: g.getHeight()/2 - 30, valign: -1, txt: "unknown", id: "icon",
14-
render: l => weather.drawIcon(l, l.x+l.w/2, l.y+l.h/2, l.w/2-10)},
15-
{type: "custom", fillx: 1, height: 20, id: "uvDisplay",
14+
render: l => weather.drawIcon(l, l.x+l.w/2, l.y+l.h/2, l.w/2-5)},
15+
]},
16+
{type: "v", fillx: 1, c: [
17+
{type: "h", pad: 2, c: [
18+
{type: "txt", font: "18%", id: "temp", label: "000"},
19+
{type: "txt", font: "12%", valign: -1, id: "tempUnit", label: "°C"},
20+
]},
21+
{filly: 1},
22+
{type: "txt", font: "6x8", pad: 2, halign: 1, label: /*LANG*/"Humidity"},
23+
{type: "txt", font: "9%", pad: 2, halign: 1, id: "hum", label: "000%"},
24+
{type: "txt", font: "6x8", pad: [2, 2, 2, 2], halign: -1, label: /*LANG*/"Wind"},
25+
{type: "h", pad: [0, 2, 2, 2], halign: -1, c: [
26+
{type: "txt", font: "9%", pad: 2, id: "wind", label: "00"},
27+
{type: "txt", font: "6x8", pad: 2, valign: -1, id: "windUnit", label: "km/h"},
28+
]},
29+
{type: "custom", fillx: 1, height: 15, id: "uvDisplay",
1630
render: l => {
17-
if (!current || current.uv === undefined) return;
31+
if (!current || current.uv === undefined || current.uv === 0) return;
1832
const uv = Math.min(parseInt(current.uv), 11); // Cap at 11
1933

2034
// UV color thresholds: [max_value, color] based on WHO standards
2135
const colors = [[2,"#0F0"], [5,"#FF0"], [7,"#F80"], [10,"#F00"], [11,"#F0F"]];
2236
const color = colors.find(c => uv <= c[0])[1];
37+
const blockH = 8, blockW = 3;
2338

24-
// Setup and measure label
39+
// Draw UV title and blocks on same line
2540
g.setFont("6x8").setFontAlign(-1, 0);
26-
const label = "UV: ";
41+
const label = "UV";
2742
const labelW = g.stringWidth(label);
2843

29-
// Calculate centered position (4px block + 1px spacing) * blocks - last spacing
30-
const totalW = labelW + uv * 5 - (uv > 0 ? 1 : 0);
31-
const x = l.x + (l.w - totalW) / 2;
32-
const y = l.y + l.h;
44+
const x = l.x + 2;
45+
const y = l.y + l.h / 2;
3346

34-
// Draw label
47+
// Draw title
3548
g.setColor(g.theme.fg).drawString(label, x, y);
3649

37-
// Draw UV blocks
50+
// Draw UV blocks after title
3851
g.setColor(color);
3952
for (let i = 0; i < uv; i++) {
40-
g.fillRect(x + labelW + i * 5, y - 3, x + labelW + i * 5 + 3, y + 3);
53+
const blockX = x + labelW + 4 + i * (blockW + 2);
54+
g.fillRect(blockX, y - blockH/2, blockX + blockW, y + blockW/2);
4155
}
56+
57+
// Reset graphics state to prevent interference
58+
g.reset();
4259
}
4360
},
4461
]},
45-
{type: "v", fillx: 1, c: [
46-
{type: "h", pad: 2, c: [
47-
{type: "txt", font: "18%", id: "temp", label: "000"},
48-
{type: "txt", font: "12%", valign: -1, id: "tempUnit", label: "°C"},
49-
]},
50-
{filly: 1},
51-
{type: "txt", font: "6x8", pad: 2, halign: 1, label: /*LANG*/"Humidity"},
52-
{type: "txt", font: "9%", pad: 2, halign: 1, id: "hum", label: "000%"},
53-
{filly: 1},
54-
{type: "txt", font: "6x8", pad: 2, halign: -1, label: /*LANG*/"Wind"},
55-
{type: "h", halign: -1, c: [
56-
{type: "txt", font: "9%", pad: 2, id: "wind", label: "00"},
57-
{type: "txt", font: "6x8", pad: 2, valign: -1, id: "windUnit", label: "km/h"},
58-
]},
59-
]},
6062
]},
6163
{filly: 1},
6264
{type: "txt", font: "9%", wrap: true, height: g.getHeight()*0.18, fillx: 1, id: "cond", label: /*LANG*/"Weather condition"},
@@ -91,6 +93,7 @@ function draw() {
9193
layout.loc.label = current.loc;
9294
layout.updateTime.label = `${formatDuration(Date.now() - current.time)} ago`; // How to autotranslate this and similar?
9395
layout.update();
96+
layout.forgetLazyState();
9497
layout.render();
9598
}
9699

0 commit comments

Comments
 (0)