Skip to content

Commit

Permalink
Fix not centered text clock (pull request #343)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaanelloed authored Nov 16, 2024
1 parent c97ad39 commit ee90034
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ protected void onDraw(Canvas canvas)
while((rect_date.width() > (view_width - 2 * padding)) && (date_text_size_factor > 0))
{
// Progressively lower the size of the date text size
date_text_size_factor -= 0.01 ;
date_text_size_factor -= 0.01f ;
textClock.setTextSize(time_text_size * date_text_size_factor) ;
textClock.getTextBounds(date_text, 0, date_text.length(), rect_date) ;
}
Expand All @@ -265,7 +265,7 @@ protected void onDraw(Canvas canvas)
// Draw the time text
textClock.setFakeBoldText(false) ;
textClock.setTextSize(time_text_size) ;
canvas.drawText(time_text, offset_x, offset_y, textClock) ;
canvas.drawText(time_text, offset_x - rect_time.left, offset_y, textClock) ;
rect_time.offset(Math.round(offset_x), Math.round(offset_y)) ;

// Define the horizontal offset of the date text
Expand All @@ -276,7 +276,7 @@ protected void onDraw(Canvas canvas)
// Draw the date text
textClock.setFakeBoldText(true) ;
textClock.setTextSize(time_text_size * date_text_size_factor) ;
canvas.drawText(date_text, offset_x, offset_y + 0.5f * padding + rect_date.height(), textClock) ;
canvas.drawText(date_text, offset_x - rect_date.left, offset_y + 0.5f * padding + rect_date.height(), textClock) ;
rect_date.offset(Math.round(offset_x), Math.round(offset_y + 0.5f * padding + rect_date.height())) ;
}
else if(clock_format.startsWith("date"))
Expand All @@ -294,7 +294,7 @@ else if(clock_format.startsWith("date"))
while((rect_date.width() > (view_width - 2 * padding)) && (date_text_size_factor > 0))
{
// Progressively lower the size of the date text size
date_text_size_factor -= 0.01 ;
date_text_size_factor -= 0.01f ;
textClock.setTextSize(time_text_size * date_text_size_factor) ;
textClock.getTextBounds(date_text, 0, date_text.length(), rect_date) ;
}
Expand All @@ -312,7 +312,7 @@ else if(clock_format.startsWith("date"))
// Draw the date text
textClock.setFakeBoldText(true) ;
textClock.setTextSize(time_text_size * date_text_size_factor) ;
canvas.drawText(date_text, offset_x, offset_y, textClock) ;
canvas.drawText(date_text, offset_x - rect_date.left, offset_y, textClock) ;
rect_date.offset(Math.round(offset_x), Math.round(offset_y)) ;
}
else
Expand Down Expand Up @@ -342,7 +342,7 @@ else if(clock_format.startsWith("date"))
else offset_x = view_width / 2f - rect_time.width() / 2f ;

// Draw the time text
canvas.drawText(time_text, offset_x, offset_y, textClock) ;
canvas.drawText(time_text, offset_x - rect_time.left, offset_y, textClock) ;
rect_time.offset(Math.round(offset_x), Math.round(offset_y)) ;
}
}
Expand Down

0 comments on commit ee90034

Please sign in to comment.