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,32 +238,36 @@ class TitleScreen @JvmOverloads constructor(
// Remove tetrominos that fell off the screen // Remove tetrominos that fell off the screen
tetrominos.removeAll(tetrominosToRemove) tetrominos.removeAll(tetrominosToRemove)
// Draw title with "Mint" in mint color // Draw title with "mint" in mint color
val titleY = height * 0.4f val titleY = height * 0.4f
val fullTitle = "pixel mint drop"
val pixelWidth = titlePaint.measureText("pixel ") // Measure each word without spaces
val pixelWidth = titlePaint.measureText("pixel")
val mintWidth = titlePaint.measureText("mint") val mintWidth = titlePaint.measureText("mint")
val dropWidth = titlePaint.measureText(" drop") val dropWidth = titlePaint.measureText("drop")
// Calculate total width // Define even space between words
val totalWidth = pixelWidth + mintWidth + dropWidth 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 val startX = width / 2f - totalWidth / 2
// Draw "pixel" in theme color // Draw "pixel" in theme color
canvas.drawText("pixel ", startX, titleY, titlePaint) canvas.drawText("pixel", startX, titleY, titlePaint)
// Save the original color // Save the original color
val originalColor = titlePaint.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") 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 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 // Draw high scores using pre-allocated manager
val highScores: List<HighScore> = highScoreManager.getHighScores() val highScores: List<HighScore> = highScoreManager.getHighScores()