Center title text with even spacing between words

This commit is contained in:
cmclark00 2025-04-01 23:59:02 -04:00
parent fbecf256a2
commit f10c0260c9

View file

@ -238,17 +238,21 @@ class TitleScreen @JvmOverloads constructor(
// Remove tetrominos that fell off the screen
tetrominos.removeAll(tetrominosToRemove)
// Draw title with "Mint" in mint color
// Draw title with "mint" in mint color
val titleY = height * 0.4f
val fullTitle = "pixel mint drop"
// Measure each word without spaces
val pixelWidth = titlePaint.measureText("pixel")
val mintWidth = titlePaint.measureText("mint")
val dropWidth = titlePaint.measureText("drop")
// Calculate total width
val totalWidth = pixelWidth + mintWidth + dropWidth
// Define even space between words
val wordSpacing = 40f // Consistent spacing between words
// Start position for "pixel"
// Calculate total width including spacing
val totalWidth = pixelWidth + mintWidth + dropWidth + (wordSpacing * 2)
// Start position for first word to center the entire title
val startX = width / 2f - totalWidth / 2
// Draw "pixel" in theme color
@ -257,13 +261,13 @@ class TitleScreen @JvmOverloads constructor(
// Save the original color
val originalColor = titlePaint.color
// Draw "mint" in mint color (#3EB489)
// Draw "mint" in mint color (#3EB489) with consistent spacing
titlePaint.color = Color.parseColor("#3EB489")
canvas.drawText("mint", startX + pixelWidth, titleY, titlePaint)
canvas.drawText("mint", startX + pixelWidth + wordSpacing, titleY, titlePaint)
// Restore the original color and draw "drop"
// Restore the original color and draw "drop" with consistent spacing
titlePaint.color = originalColor
canvas.drawText(" drop", startX + pixelWidth + mintWidth, titleY, titlePaint)
canvas.drawText("drop", startX + pixelWidth + mintWidth + (wordSpacing * 2), titleY, titlePaint)
// Draw high scores using pre-allocated manager
val highScores: List<HighScore> = highScoreManager.getHighScores()