mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-10 21:03:01 +00:00
dialing of the day text spacing - revert back to too much spacing
This commit is contained in:
@@ -439,8 +439,8 @@ class OfTheDayManager:
|
|||||||
body_height = 8
|
body_height = 8
|
||||||
|
|
||||||
# --- Dynamic Spacing Calculation ---
|
# --- Dynamic Spacing Calculation ---
|
||||||
# Calculate how much space we need and distribute it more conservatively
|
# Calculate how much space we need and distribute it evenly
|
||||||
margin_top = 0 # Start at very top
|
margin_top = 6 # Shift everything down by 6 pixels
|
||||||
margin_bottom = 1
|
margin_bottom = 1
|
||||||
underline_space = 1 # Space for underline
|
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
|
# Pre-wrap the body text to determine how many lines we'll need
|
||||||
available_width = matrix_width - 4 # Leave some margin
|
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)
|
line_height=body_height, max_height=matrix_height)
|
||||||
# Filter out empty lines for spacing calculation
|
# Filter out empty lines for spacing calculation
|
||||||
actual_body_lines = [line for line in wrapped_lines if line.strip()]
|
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
|
total_content_height = title_content_height + underline_content_height + body_content_height
|
||||||
available_space = matrix_height - margin_top - margin_bottom
|
available_space = matrix_height - margin_top - margin_bottom
|
||||||
|
|
||||||
# Calculate very conservative dynamic spacing
|
# Calculate dynamic spacing
|
||||||
if total_content_height < available_space and num_body_lines > 0:
|
if total_content_height < available_space:
|
||||||
# We have extra space - distribute it very conservatively
|
# We have extra space - distribute it
|
||||||
extra_space = available_space - total_content_height
|
extra_space = available_space - total_content_height
|
||||||
# Much tighter caps to prevent issues
|
if num_body_lines > 0:
|
||||||
max_space_after_title = min(4, extra_space // 3) # Cap at 4 pixels, use 1/3 of space
|
# Distribute space: 30% after title, 70% between body lines
|
||||||
max_space_between_lines = min(2, extra_space // max(2, num_body_lines * 2)) # Cap at 2 pixels
|
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
|
||||||
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
|
|
||||||
else:
|
else:
|
||||||
# Very tight spacing for crowded content or no body text
|
# No body text - just center the title
|
||||||
space_after_title = 2
|
space_after_title = extra_space // 2
|
||||||
space_between_lines = 0
|
space_between_lines = 0
|
||||||
|
else:
|
||||||
|
# Tight spacing
|
||||||
|
space_after_title = 2
|
||||||
|
space_between_lines = 1
|
||||||
|
|
||||||
# --- Draw Title ---
|
# --- Draw Title ---
|
||||||
# For BDF fonts, we need to account for the ascender to position text properly
|
title_y = margin_top
|
||||||
# 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
|
|
||||||
|
|
||||||
# Calculate title width for centering
|
# Calculate title width for centering
|
||||||
try:
|
try:
|
||||||
@@ -503,7 +496,7 @@ class OfTheDayManager:
|
|||||||
self._draw_bdf_text(draw, title_font, title, title_x, title_y, color=self.title_color)
|
self._draw_bdf_text(draw, title_font, title, title_x, title_y, color=self.title_color)
|
||||||
|
|
||||||
# --- Draw Underline ---
|
# --- 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_start = title_x
|
||||||
underline_x_end = title_x + title_width
|
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)
|
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
|
body_start_y = underline_y + space_after_title
|
||||||
current_y = body_start_y
|
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):
|
for i, line in enumerate(actual_body_lines):
|
||||||
if line.strip(): # Only draw non-empty lines
|
if line.strip(): # Only draw non-empty lines
|
||||||
# Center each line of body text
|
# Center each line of body text
|
||||||
@@ -533,10 +518,9 @@ class OfTheDayManager:
|
|||||||
# Draw the line
|
# Draw the line
|
||||||
self._draw_bdf_text(draw, body_font, line, line_x, current_y, color=self.subtitle_color)
|
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
|
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 += body_height + space_between_lines
|
||||||
current_y += line_spacing
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
Reference in New Issue
Block a user