11// Tea Timer Application for Bangle.js 2 using sched library
22
33let 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 }
67let GREEN = g . theme . dark ?0x07E0 :0x03E0 ;
78
89let 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
3637function 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
130131function handleTouch ( x , y ) {
131- const centerY = g . getHeight ( ) / 2 ;
132132
133133 if ( y < centerY - 40 ) {
134134 // Increase button area
0 commit comments