make sure leaderboard is scrolling horizontally to show all teams

This commit is contained in:
Chuck
2025-09-10 21:56:29 -04:00
parent bbabad3135
commit 591555c3c7

View File

@@ -317,40 +317,38 @@ class LeaderboardManager:
try:
# Calculate total width needed
total_width = 0
team_height = 16 # Height for each team entry
league_header_height = 25 # Height for league logo and name
spacing = 20 # Spacing between leagues
spacing = 40 # Spacing between leagues
# Calculate width for each league section
for league_data in self.leaderboard_data:
league_config = league_data['league_config']
teams = league_data['teams']
# Width for league header (logo + name)
league_header_width = 120 # Base width for league header
# Width for league logo section
league_logo_width = 64 # Fixed width for league logo section
# Width for team entries (bold number + logo + name + record)
max_team_width = 0
# Calculate total width for all teams in horizontal layout
teams_width = 0
for i, team in enumerate(teams):
# Calculate width for bold number
number_text = f"{i+1}."
number_bbox = self.fonts['large'].getbbox(number_text)
number_bbox = self.fonts['medium'].getbbox(number_text)
number_width = number_bbox[2] - number_bbox[0]
# Calculate width for team text
team_text = f"{team['abbreviation']} {team['wins']}-{team['losses']}"
if 'ties' in team:
if 'ties' in team and team['ties'] > 0:
team_text += f"-{team['ties']}"
text_bbox = self.fonts['small'].getbbox(team_text)
text_width = text_bbox[2] - text_bbox[0]
# Total team width: bold number + spacing + logo + spacing + text
team_width = number_width + 5 + 16 + 5 + text_width + 10 # Extra padding
max_team_width = max(max_team_width, team_width)
# Total team width: bold number + spacing + logo + spacing + text + spacing
team_width = number_width + 2 + 12 + 2 + text_width + 8 # Spacing between teams
teams_width += team_width
# Total league width is the maximum of header and team widths
league_width = max(league_header_width, max_team_width)
# Total league width: logo width + teams width + spacing
league_width = league_logo_width + teams_width + 20
total_width += league_width + spacing
# Create the main image
@@ -365,45 +363,46 @@ class LeaderboardManager:
league_config = league_data['league_config']
teams = league_data['teams']
# Draw league header with logo first
# Draw league logo section (full height)
league_logo = self._get_league_logo(league_config['league_logo'])
if league_logo:
# Resize league logo to fit nicely
logo_height = int(height * 0.4)
# Resize league logo to full height
logo_height = height - 4 # Leave small margin
logo_width = int(logo_height * league_logo.width / league_logo.height)
# Center the logo horizontally in its section
logo_x = current_x + (64 - logo_width) // 2
logo_y = 2
league_logo = league_logo.resize((logo_width, logo_height), Image.Resampling.LANCZOS)
self.leaderboard_image.paste(league_logo, (logo_x, logo_y), league_logo if league_logo.mode == 'RGBA' else None)
# Paste league logo at the top
logo_y = 3
self.leaderboard_image.paste(league_logo, (current_x + 5, logo_y), league_logo if league_logo.mode == 'RGBA' else None)
# Draw league name below the logo, centered
# Draw league name at the bottom
league_name = league_key.upper().replace('_', ' ')
league_name_bbox = self.fonts['small'].getbbox(league_name)
league_name_width = league_name_bbox[2] - league_name_bbox[0]
league_name_x = current_x + 5 + (logo_width - league_name_width) // 2
draw.text((league_name_x, logo_y + logo_height + 1), league_name, font=self.fonts['small'], fill=(255, 255, 255))
# Move current_x past the logo for team entries
current_x += logo_width + 15
league_name_x = current_x + (64 - league_name_width) // 2
draw.text((league_name_x, height - 8), league_name, font=self.fonts['small'], fill=(255, 255, 255))
else:
# Fallback if no league logo - just show league name
league_name = league_key.upper().replace('_', ' ')
draw.text((current_x + 5, 5), league_name, font=self.fonts['medium'], fill=(255, 255, 255))
current_x += 100
league_name_bbox = self.fonts['medium'].getbbox(league_name)
league_name_width = league_name_bbox[2] - league_name_bbox[0]
league_name_x = current_x + (64 - league_name_width) // 2
draw.text((league_name_x, height // 2), league_name, font=self.fonts['medium'], fill=(255, 255, 255))
# Draw team standings with bold numbers
team_y = league_header_height
# Move to team section
current_x += 64 + 10 # League logo width + spacing
# Draw team standings horizontally in a single line
team_x = current_x
for i, team in enumerate(teams):
if team_y + team_height > height:
break
# Draw bold team number with better positioning
# Draw bold team number
number_text = f"{i+1}."
draw.text((current_x + 5, team_y), number_text, font=self.fonts['large'], fill=(255, 255, 0))
draw.text((team_x, 2), number_text, font=self.fonts['medium'], fill=(255, 255, 0))
# Get number width for positioning
number_bbox = self.fonts['large'].getbbox(number_text)
number_bbox = self.fonts['medium'].getbbox(number_text)
number_width = number_bbox[2] - number_bbox[0]
# Draw team logo
@@ -414,8 +413,8 @@ class LeaderboardManager:
team_logo = team_logo.resize((logo_size, logo_size), Image.Resampling.LANCZOS)
# Paste team logo after the bold number
logo_x = current_x + 5 + number_width + 3
logo_y_pos = team_y + 2
logo_x = team_x + number_width + 2
logo_y_pos = 2
self.leaderboard_image.paste(team_logo, (logo_x, logo_y_pos), team_logo if team_logo.mode == 'RGBA' else None)
# Draw team name and record after the logo
@@ -423,21 +422,32 @@ class LeaderboardManager:
if 'ties' in team and team['ties'] > 0:
team_text += f"-{team['ties']}"
text_x = logo_x + logo_size + 3
draw.text((text_x, team_y), team_text, font=self.fonts['small'], fill=(255, 255, 255))
text_x = logo_x + logo_size + 2
draw.text((text_x, 2), team_text, font=self.fonts['small'], fill=(255, 255, 255))
# Calculate total width used by this team
text_bbox = self.fonts['small'].getbbox(team_text)
text_width = text_bbox[2] - text_bbox[0]
team_width = number_width + 2 + logo_size + 2 + text_width + 8 # 8px spacing to next team
else:
# Fallback if no logo - draw team text after bold number
team_text = f"{team['abbreviation']} {team['wins']}-{team['losses']}"
if 'ties' in team and team['ties'] > 0:
team_text += f"-{team['ties']}"
text_x = current_x + 5 + number_width + 3
draw.text((text_x, team_y), team_text, font=self.fonts['small'], fill=(255, 255, 255))
text_x = team_x + number_width + 2
draw.text((text_x, 2), team_text, font=self.fonts['small'], fill=(255, 255, 255))
# Calculate total width used by this team
text_bbox = self.fonts['small'].getbbox(team_text)
text_width = text_bbox[2] - text_bbox[0]
team_width = number_width + 2 + text_width + 8 # 8px spacing to next team
team_y += team_height
# Move to next team position
team_x += team_width
# Move to next league section
current_x += 200 # Width for team section
current_x += teams_width + 20 # Teams width + spacing
current_x += spacing # Add spacing between leagues
# Calculate dynamic duration based on total width