mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-12 21:43:00 +00:00
Fix calendar text wrapping by using textbbox instead of textlength
This commit is contained in:
@@ -184,8 +184,9 @@ class CalendarManager:
|
|||||||
|
|
||||||
for word in words:
|
for word in words:
|
||||||
test_line = ' '.join(current_line + [word])
|
test_line = ' '.join(current_line + [word])
|
||||||
# Use textlength for accurate width calculation
|
# Use textbbox for accurate width calculation
|
||||||
text_width = self.display_manager.draw.textlength(test_line, font=font)
|
bbox = self.display_manager.draw.textbbox((0, 0), test_line, font=font)
|
||||||
|
text_width = bbox[2] - bbox[0]
|
||||||
|
|
||||||
if text_width <= max_width:
|
if text_width <= max_width:
|
||||||
current_line.append(word)
|
current_line.append(word)
|
||||||
@@ -197,7 +198,8 @@ class CalendarManager:
|
|||||||
lines.append(' '.join(current_line))
|
lines.append(' '.join(current_line))
|
||||||
current_line = [word]
|
current_line = [word]
|
||||||
# Recheck if the new line with just this word is too long
|
# Recheck if the new line with just this word is too long
|
||||||
if self.display_manager.draw.textlength(word, font=font) > max_width:
|
bbox = self.display_manager.draw.textbbox((0, 0), word, font=font)
|
||||||
|
if bbox[2] - bbox[0] > max_width:
|
||||||
# Handle very long words if necessary (e.g., truncate)
|
# Handle very long words if necessary (e.g., truncate)
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user