Skip to content

Commit 8eb9ecd

Browse files
author
thyttan
committed
ateatimer: refactor away g.getWidth/getHeight calls
1 parent 5537669 commit 8eb9ecd

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

apps/ateatimer/app.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
// Tea Timer Application for Bangle.js 2 using sched library
22

33
let appRect = Bangle.appRect;
4-
let middleY = appRect.y+appRect.w/2;
5-
let middleRect = {x:appRect.x, y:middleY-20, w:appRect.w, h:40}
4+
let centerY = appRect.y+appRect.w/2;
5+
let centerX = appRect.x+appRect.h/2;
6+
let middleRect = {x:appRect.x, y:centerY-20, w:appRect.w, h:40}
67
let GREEN = g.theme.dark?0x07E0:0x03E0;
78

89
let timerDuration = (() => {
@@ -28,24 +29,24 @@ function drawTime() {
2829
const sign = timeRemaining < 0 ? "-" : "";
2930
const timeStr = `${sign}${minutes}:${seconds.toString().padStart(2, '0')}`;
3031

31-
g.drawString(timeStr, g.getWidth() / 2, g.getHeight() / 2);
32+
g.drawString(timeStr, centerX, centerY);
3233

3334
g.flip();
3435
}
3536

3637
function drawButtons() {
3738
// Draw Increase button (triangle pointing up)
3839
g.fillPoly([
39-
g.getWidth() / 2, g.getHeight() / 2 - 80, // Top vertex
40-
g.getWidth() / 2 - 20, g.getHeight() / 2 - 60, // Bottom-left vertex
41-
g.getWidth() / 2 + 20, g.getHeight() / 2 - 60 // Bottom-right vertex
40+
centerX, centerY - 80, // Top vertex
41+
centerX - 20, centerY - 60, // Bottom-left vertex
42+
centerX + 20, centerY - 60 // Bottom-right vertex
4243
]);
4344

4445
// Draw Decrease button (triangle pointing down)
4546
g.fillPoly([
46-
g.getWidth() / 2, g.getHeight() / 2 + 80, // Bottom vertex
47-
g.getWidth() / 2 - 20, g.getHeight() / 2 + 60, // Top-left vertex
48-
g.getWidth() / 2 + 20, g.getHeight() / 2 + 60 // Top-right vertex
47+
centerX, centerY + 80, // Bottom vertex
48+
centerX - 20, centerY + 60, // Top-left vertex
49+
centerX + 20, centerY + 60 // Top-right vertex
4950
]);
5051

5152
g.flip();
@@ -128,7 +129,6 @@ function adjustTime(amount) {
128129
}
129130

130131
function handleTouch(x, y) {
131-
const centerY = g.getHeight() / 2;
132132

133133
if (y < centerY - 40) {
134134
// Increase button area

0 commit comments

Comments
 (0)