Refactor default.py to improve stats layout and positioning in profile card rendering. Adjust calculations for progress bar and text alignment to enhance overall readability and aesthetics, ensuring elements are consistently placed after the profile picture.
Some checks are pending
Run pre-commit / Run pre-commit (push) Waiting to run

This commit is contained in:
Valerie 2025-05-26 22:02:58 -04:00
parent bf4fbe7248
commit 173f3b2cc4

View file

@ -215,35 +215,34 @@ def generate_default_profile(
stats_layer = Image.new("RGBA", desired_card_size, (0, 0, 0, 0))
draw = ImageDraw.Draw(stats_layer)
# Stats positioning
stats_x = pfp_x + pfp_size[0] + 30 # Start stats after profile picture
stats_y = 40 # Top padding
# Stats positioning - everything starts AFTER the profile picture
left_edge = pfp_x + pfp_size[0] + 30 # Start everything after profile picture
# Draw stats with consistent spacing
title_font = ImageFont.truetype(str(font_path or imgtools.DEFAULT_FONT), 32)
value_font = ImageFont.truetype(str(font_path or imgtools.DEFAULT_FONT), 32)
# Balance and Rank stats
balance_y = stats_y
draw.text((stats_x + 400, balance_y), "BALANCE:", font=title_font, fill=(200, 200, 200))
draw.text((stats_x + 550, balance_y), f"{humanize_number(balance)} CREDITS", font=value_font, fill=stat_color or (255, 255, 255))
balance_y = 40
draw.text((left_edge, balance_y), "BALANCE:", font=title_font, fill=(200, 200, 200))
draw.text((left_edge + 150, balance_y), f"{humanize_number(balance)} CREDITS", font=value_font, fill=stat_color or (255, 255, 255))
rank_y = balance_y + 50
draw.text((stats_x + 400, rank_y), "RANK:", font=title_font, fill=(200, 200, 200))
draw.text((stats_x + 550, rank_y), f"#{humanize_number(position)}", font=value_font, fill=stat_color or (255, 255, 255))
draw.text((left_edge, rank_y), "RANK:", font=title_font, fill=(200, 200, 200))
draw.text((left_edge + 150, rank_y), f"#{humanize_number(position)}", font=value_font, fill=stat_color or (255, 255, 255))
# XP Text
xp_y = rank_y + 50
xp_text = f"XP: {humanize_number(current_xp)} / {humanize_number(next_xp)}"
draw.text((stats_x + 400, xp_y), xp_text, font=value_font, fill=(255, 255, 255))
draw.text((left_edge, xp_y), xp_text, font=value_font, fill=(255, 255, 255))
# Progress bar
# Progress bar - starts after profile picture
progress = (current_xp - previous_xp) / (next_xp - previous_xp) if next_xp > previous_xp else 0
progress = max(0, min(1, progress)) # Ensure progress is between 0 and 1
bar_width = desired_card_size[0] - 30 # Full width with padding
bar_width = desired_card_size[0] - left_edge - 15 # Width from after profile to right edge
bar_height = 40
bar_x = 15
bar_x = left_edge # Start after profile picture
bar_y = desired_card_size[1] - bar_height - 15 # Bottom padding
# Progress bar background
@ -258,7 +257,7 @@ def generate_default_profile(
percent_text = f"{int(progress * 100)}%"
percent_font = ImageFont.truetype(str(font_path or imgtools.DEFAULT_FONT), 24)
percent_w = draw.textlength(percent_text, font=percent_font)
percent_x = bar_x + 10 # Left align percentage
percent_x = bar_x + 10 # Offset from start of progress bar
percent_y = bar_y + (bar_height - 24) // 2 # Center in bar
# Draw percentage
@ -269,7 +268,7 @@ def generate_default_profile(
level_text = f"LEVEL {level}"
if prestige > 0:
level_text = f"P{prestige}{level_text}"
draw.text((15, 15), level_text, font=level_font, fill=user_color or (255, 255, 255))
draw.text((left_edge, 15), level_text, font=level_font, fill=user_color or (255, 255, 255))
# Composite the layers
if not render_gif or (not pfp_animated and not bg_animated):