From c18ab3f91fb2a605b4b3240178f120a7c33e7dcf Mon Sep 17 00:00:00 2001 From: Chuck <33324927+ChuckBuilds@users.noreply.github.com> Date: Tue, 16 Sep 2025 12:18:56 -0400 Subject: [PATCH] dialing of the day text spacing - revert back to too much spacing --- src/of_the_day_manager.py | 56 ++++++++++++++------------------------- 1 file changed, 20 insertions(+), 36 deletions(-) diff --git a/src/of_the_day_manager.py b/src/of_the_day_manager.py index ca372efd..5c0a3306 100644 --- a/src/of_the_day_manager.py +++ b/src/of_the_day_manager.py @@ -439,8 +439,8 @@ class OfTheDayManager: body_height = 8 # --- Dynamic Spacing Calculation --- - # Calculate how much space we need and distribute it more conservatively - margin_top = 0 # Start at very top + # Calculate how much space we need and distribute it evenly + margin_top = 6 # Shift everything down by 6 pixels margin_bottom = 1 underline_space = 1 # Space for underline @@ -451,7 +451,7 @@ class OfTheDayManager: # Pre-wrap the body text to determine how many lines we'll need available_width = matrix_width - 4 # Leave some margin - wrapped_lines = self._wrap_text(current_text, available_width, body_font, max_lines=6, + wrapped_lines = self._wrap_text(current_text, available_width, body_font, max_lines=10, line_height=body_height, max_height=matrix_height) # Filter out empty lines for spacing calculation actual_body_lines = [line for line in wrapped_lines if line.strip()] @@ -465,32 +465,25 @@ class OfTheDayManager: total_content_height = title_content_height + underline_content_height + body_content_height available_space = matrix_height - margin_top - margin_bottom - # Calculate very conservative dynamic spacing - if total_content_height < available_space and num_body_lines > 0: - # We have extra space - distribute it very conservatively + # Calculate dynamic spacing + if total_content_height < available_space: + # We have extra space - distribute it extra_space = available_space - total_content_height - # Much tighter caps to prevent issues - max_space_after_title = min(4, extra_space // 3) # Cap at 4 pixels, use 1/3 of space - max_space_between_lines = min(2, extra_space // max(2, num_body_lines * 2)) # Cap at 2 pixels - - space_after_title = max(2, max_space_after_title) # Minimum 2 pixels after title - space_between_lines = max(0, max_space_between_lines) # Can be 0 between lines + if num_body_lines > 0: + # Distribute space: 30% after title, 70% between body lines + space_after_title = max(2, int(extra_space * 0.3)) + space_between_lines = max(1, int(extra_space * 0.7 / max(1, num_body_lines - 1))) if num_body_lines > 1 else 0 + else: + # No body text - just center the title + space_after_title = extra_space // 2 + space_between_lines = 0 else: - # Very tight spacing for crowded content or no body text + # Tight spacing space_after_title = 2 - space_between_lines = 0 + space_between_lines = 1 # --- Draw Title --- - # For BDF fonts, we need to account for the ascender to position text properly - # Start the title with enough space for the ascender - if isinstance(title_font, freetype.Face): - try: - ascender_px = title_font.size.ascender >> 6 - title_y = max(ascender_px, 2) # Ensure title has space for ascender but don't go below y=2 - except Exception: - title_y = 2 - else: - title_y = 2 # For PIL fonts, start at y=2 + title_y = margin_top # Calculate title width for centering try: @@ -503,7 +496,7 @@ class OfTheDayManager: self._draw_bdf_text(draw, title_font, title, title_x, title_y, color=self.title_color) # --- Draw Underline --- - underline_y = title_y + title_height + 1 # Small gap after title + underline_y = title_y + title_height + 2 # Space after title underline_x_start = title_x underline_x_end = title_x + title_width draw.line([(underline_x_start, underline_y), (underline_x_end, underline_y)], fill=self.title_color, width=1) @@ -513,14 +506,6 @@ class OfTheDayManager: body_start_y = underline_y + space_after_title current_y = body_start_y - # For BDF fonts, account for ascender in first line positioning - if isinstance(body_font, freetype.Face): - try: - body_ascender = body_font.size.ascender >> 6 - current_y = max(current_y, body_start_y + body_ascender) - except Exception: - pass - for i, line in enumerate(actual_body_lines): if line.strip(): # Only draw non-empty lines # Center each line of body text @@ -533,10 +518,9 @@ class OfTheDayManager: # Draw the line self._draw_bdf_text(draw, body_font, line, line_x, current_y, color=self.subtitle_color) - # Move to next line position - ensure minimum spacing + # Move to next line position if i < len(actual_body_lines) - 1: # Not the last line - line_spacing = max(body_height + space_between_lines, body_height + 2) # Minimum 2px between lines - current_y += line_spacing + current_y += body_height + space_between_lines return True except Exception as e: