mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-10 13:02:59 +00:00
Center time better (#144)
* Center time better * Use ampm spacing of 4 pixels
This commit is contained in:
@@ -28,6 +28,7 @@ class Clock:
|
|||||||
self.timezone = self._get_timezone()
|
self.timezone = self._get_timezone()
|
||||||
self.last_time = None
|
self.last_time = None
|
||||||
self.last_date = None
|
self.last_date = None
|
||||||
|
self.ampm_padding = 4
|
||||||
# Colors for different elements - using super bright colors
|
# Colors for different elements - using super bright colors
|
||||||
self.COLORS = {
|
self.COLORS = {
|
||||||
'time': (255, 255, 255), # Pure white for time
|
'time': (255, 255, 255), # Pure white for time
|
||||||
@@ -90,17 +91,21 @@ class Clock:
|
|||||||
display_width = self.display_manager.matrix.width
|
display_width = self.display_manager.matrix.width
|
||||||
display_height = self.display_manager.matrix.height
|
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)
|
# Draw time (large, centered, near top)
|
||||||
self.display_manager.draw_text(
|
self.display_manager.draw_text(
|
||||||
time_str,
|
time_str,
|
||||||
|
x=time_x,
|
||||||
y=4, # Move up slightly to make room for two lines of date
|
y=4, # Move up slightly to make room for two lines of date
|
||||||
color=self.COLORS['time'],
|
color=self.COLORS['time'],
|
||||||
small_font=True
|
small_font=True
|
||||||
)
|
)
|
||||||
|
|
||||||
# Draw AM/PM (small, next to time)
|
# Draw AM/PM (small, next to time)
|
||||||
time_width = self.display_manager.font.getlength(time_str)
|
ampm_x = time_x + self.ampm_padding + time_width
|
||||||
ampm_x = (display_width + time_width) // 2 + 4
|
|
||||||
self.display_manager.draw_text(
|
self.display_manager.draw_text(
|
||||||
ampm,
|
ampm,
|
||||||
x=ampm_x,
|
x=ampm_x,
|
||||||
|
|||||||
Reference in New Issue
Block a user