Center time better (#144)

* Center time better

* Use ampm spacing of 4 pixels
This commit is contained in:
Evan Salter
2025-12-09 09:58:57 -06:00
committed by GitHub
parent bb76f01c05
commit 694c7cec10

View File

@@ -28,6 +28,7 @@ class Clock:
self.timezone = self._get_timezone()
self.last_time = None
self.last_date = None
self.ampm_padding = 4
# Colors for different elements - using super bright colors
self.COLORS = {
'time': (255, 255, 255), # Pure white for time
@@ -90,17 +91,21 @@ class Clock:
display_width = self.display_manager.matrix.width
display_height = self.display_manager.matrix.height
# Center time based on full width of time + ampm
time_width = self.display_manager.font.getlength(f"{time_str}")
ampm_width = self.display_manager.font.getlength(f"{ampm}")
time_x = (display_width - (time_width + self.ampm_padding + ampm_width)) // 2
# Draw time (large, centered, near top)
self.display_manager.draw_text(
time_str,
x=time_x,
y=4, # Move up slightly to make room for two lines of date
color=self.COLORS['time'],
small_font=True
)
# Draw AM/PM (small, next to time)
time_width = self.display_manager.font.getlength(time_str)
ampm_x = (display_width + time_width) // 2 + 4
ampm_x = time_x + self.ampm_padding + time_width
self.display_manager.draw_text(
ampm,
x=ampm_x,