mirror of
https://github.com/cmclark00/mintris.git
synced 2025-05-17 23:45:22 +01:00
Center title text with even spacing between words
This commit is contained in:
parent
fbecf256a2
commit
f10c0260c9
1 changed files with 16 additions and 12 deletions
|
@ -238,17 +238,21 @@ 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"
|
|
||||||
|
// Measure each word without spaces
|
||||||
val pixelWidth = titlePaint.measureText("pixel")
|
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
|
||||||
|
@ -257,13 +261,13 @@ class TitleScreen @JvmOverloads constructor(
|
||||||
// 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()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue