From cafab55cb27069bfc79c375f772b911ffaf7a405 Mon Sep 17 00:00:00 2001 From: Chuck <33324927+ChuckBuilds@users.noreply.github.com> Date: Mon, 7 Apr 2025 21:01:29 -0500 Subject: [PATCH] more display changes tuning absolute positioning of pixels and draw space --- config/config.json | 2 +- src/display_manager.py | 22 ++++++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/config/config.json b/config/config.json index 9f73d095..10fe3b86 100644 --- a/config/config.json +++ b/config/config.json @@ -25,7 +25,7 @@ "runtime": { "gpio_slowdown": 2 }, - "rotation_interval": 30 + "rotation_interval": 15 }, "clock": { "format": "%H:%M:%S", diff --git a/src/display_manager.py b/src/display_manager.py index 5e3bd38a..6cb662c5 100644 --- a/src/display_manager.py +++ b/src/display_manager.py @@ -23,8 +23,8 @@ class DisplayManager: self.config = config logger.info("Initializing DisplayManager with config: %s", config) self._setup_matrix() # This now sets self.matrix - # Use an even smaller font size for better fitting - self.font = ImageFont.truetype("DejaVuSans.ttf", 12) + # Use appropriate font size for 32px height + self.font = ImageFont.truetype("DejaVuSans.ttf", 14) self.image = Image.new('RGB', (self.matrix.width, self.matrix.height)) self.draw = ImageDraw.Draw(self.image) DisplayManager._initialized = True @@ -88,8 +88,8 @@ class DisplayManager: line_heights = [] line_widths = [] total_height = 0 - max_width = 0 padding = 2 # Add padding between lines + edge_padding = 2 # Minimum padding from display edges for line in lines: 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 if y is None: - y = (self.matrix.height - total_height) // 2 + y = max(edge_padding, (self.matrix.height - total_height) // 2) # Draw each line current_y = y for i, line in enumerate(lines): 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 else: 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})") self.draw.text((line_x, current_y), line, font=self.font, fill=color) + + # Calculate next line position current_y += line_heights[i] + padding - - self.matrix.SetImage(self.image) def cleanup(self): """Clean up resources."""