From f10c0260c9a42b7a2900412cd08696d0f67eb064 Mon Sep 17 00:00:00 2001 From: cmclark00 Date: Tue, 1 Apr 2025 23:59:02 -0400 Subject: [PATCH] Center title text with even spacing between words --- .../com/pixelmintdrop/game/TitleScreen.kt | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/pixelmintdrop/game/TitleScreen.kt b/app/src/main/java/com/pixelmintdrop/game/TitleScreen.kt index 55000c5..22f55da 100644 --- a/app/src/main/java/com/pixelmintdrop/game/TitleScreen.kt +++ b/app/src/main/java/com/pixelmintdrop/game/TitleScreen.kt @@ -238,32 +238,36 @@ 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" - val pixelWidth = titlePaint.measureText("pixel ") + + // Measure each word without spaces + val pixelWidth = titlePaint.measureText("pixel") val mintWidth = titlePaint.measureText("mint") - val dropWidth = titlePaint.measureText(" drop") + 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 - canvas.drawText("pixel ", startX, titleY, titlePaint) + canvas.drawText("pixel", startX, titleY, titlePaint) // 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 = highScoreManager.getHighScores()