mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-10 21:03:01 +00:00
more display changes
tuning absolute positioning of pixels and draw space
This commit is contained in:
@@ -25,7 +25,7 @@
|
|||||||
"runtime": {
|
"runtime": {
|
||||||
"gpio_slowdown": 2
|
"gpio_slowdown": 2
|
||||||
},
|
},
|
||||||
"rotation_interval": 30
|
"rotation_interval": 15
|
||||||
},
|
},
|
||||||
"clock": {
|
"clock": {
|
||||||
"format": "%H:%M:%S",
|
"format": "%H:%M:%S",
|
||||||
|
|||||||
@@ -23,8 +23,8 @@ class DisplayManager:
|
|||||||
self.config = config
|
self.config = config
|
||||||
logger.info("Initializing DisplayManager with config: %s", config)
|
logger.info("Initializing DisplayManager with config: %s", config)
|
||||||
self._setup_matrix() # This now sets self.matrix
|
self._setup_matrix() # This now sets self.matrix
|
||||||
# Use an even smaller font size for better fitting
|
# Use appropriate font size for 32px height
|
||||||
self.font = ImageFont.truetype("DejaVuSans.ttf", 12)
|
self.font = ImageFont.truetype("DejaVuSans.ttf", 14)
|
||||||
self.image = Image.new('RGB', (self.matrix.width, self.matrix.height))
|
self.image = Image.new('RGB', (self.matrix.width, self.matrix.height))
|
||||||
self.draw = ImageDraw.Draw(self.image)
|
self.draw = ImageDraw.Draw(self.image)
|
||||||
DisplayManager._initialized = True
|
DisplayManager._initialized = True
|
||||||
@@ -88,8 +88,8 @@ class DisplayManager:
|
|||||||
line_heights = []
|
line_heights = []
|
||||||
line_widths = []
|
line_widths = []
|
||||||
total_height = 0
|
total_height = 0
|
||||||
max_width = 0
|
|
||||||
padding = 2 # Add padding between lines
|
padding = 2 # Add padding between lines
|
||||||
|
edge_padding = 2 # Minimum padding from display edges
|
||||||
|
|
||||||
for line in lines:
|
for line in lines:
|
||||||
bbox = self.draw.textbbox((0, 0), line, font=self.font)
|
bbox = self.draw.textbbox((0, 0), line, font=self.font)
|
||||||
@@ -105,22 +105,28 @@ class DisplayManager:
|
|||||||
|
|
||||||
# Calculate starting Y position to center all lines vertically
|
# Calculate starting Y position to center all lines vertically
|
||||||
if y is None:
|
if y is None:
|
||||||
y = (self.matrix.height - total_height) // 2
|
y = max(edge_padding, (self.matrix.height - total_height) // 2)
|
||||||
|
|
||||||
# Draw each line
|
# Draw each line
|
||||||
current_y = y
|
current_y = y
|
||||||
for i, line in enumerate(lines):
|
for i, line in enumerate(lines):
|
||||||
if x is None:
|
if x is None:
|
||||||
# Center this line horizontally
|
# Center this line horizontally across full width (128 pixels)
|
||||||
line_x = (self.matrix.width - line_widths[i]) // 2
|
line_x = (self.matrix.width - line_widths[i]) // 2
|
||||||
else:
|
else:
|
||||||
line_x = x
|
line_x = x
|
||||||
|
|
||||||
|
# Ensure x coordinate stays within bounds
|
||||||
|
line_x = max(edge_padding, min(line_x, self.matrix.width - line_widths[i] - edge_padding))
|
||||||
|
|
||||||
|
# Ensure y coordinate stays within bounds
|
||||||
|
current_y = max(edge_padding, min(current_y, self.matrix.height - line_heights[i] - edge_padding))
|
||||||
|
|
||||||
logger.info(f"Drawing line '{line}' at position ({line_x}, {current_y})")
|
logger.info(f"Drawing line '{line}' at position ({line_x}, {current_y})")
|
||||||
self.draw.text((line_x, current_y), line, font=self.font, fill=color)
|
self.draw.text((line_x, current_y), line, font=self.font, fill=color)
|
||||||
current_y += line_heights[i] + padding
|
|
||||||
|
|
||||||
self.matrix.SetImage(self.image)
|
# Calculate next line position
|
||||||
|
current_y += line_heights[i] + padding
|
||||||
|
|
||||||
def cleanup(self):
|
def cleanup(self):
|
||||||
"""Clean up resources."""
|
"""Clean up resources."""
|
||||||
|
|||||||
Reference in New Issue
Block a user