Modern Apps git

← Modern-Apps.git

voxels: untangle overlapping HUD pieces; hotbar swallows stray taps (#ux-audit)

Commit
b72c651bca5f2f6fd1279837ce842b6db5f4a3fd
Author
Vayun Mathur <[email protected]>
When
2026-11-13 01:48 UTC (23 days ago)
Parents
88cec4b
Symptom:
- With debug info on in an online world, the "N online" chip and the
  debug readout were drawn on top of each other (top-right).
- During a boss fight an achievement toast covered the boss bar.
- Status-effect chips grew up from the bottom-left corner into the
  move stick.
- A tap that landed between two hotbar slots (or on the bar's
  padding) fell through and placed a block in the world.
- The hotbar briefly showed a fake starter kit (grass, dirt, stone...)
  before the engine published the real inventory, even for a save
  with completely different items.

Root cause: each HUD piece was positioned on its own with hard-coded
offsets (MainActivity: online chip and debug both top-right at 36 dp,
boss bar at 70 dp vs toast at 80 dp, health at bottom-start 78 dp vs
the stick at 96 dp); the hotbar Row filled the width but had no
pointer handling between its clickable slots; the initial
inventoryJson was a hard-coded kit.

Fix:
- Debug readout moves under the menu/settings buttons on the left.
- Boss bar and achievement toast share one top-centre Column.
- Glide chip, effects and hearts stack in one bottom-centre Column
  just above the hotbar (max 260 dp wide), between the stick and the
  action buttons.
- The hotbar Row wraps its slots and consumes taps on its padding and
  gaps (detectTapGestures with no action) before the world layer can.
- inventoryJson starts as "{}" (nine empty slots) until the engine
  publishes the real inventory.

User-visible effect: no overlapping HUD elements; near-miss hotbar
taps do nothing instead of placing blocks; no flash of wrong items on
load.

Verification: new Compose test in VoxelScreensTest taps the hotbar's
padding over a world-tap catcher and asserts the world saw nothing.

Diff

games/voxels/src/main/java/com/vayunmathur/games/voxels/MainActivity.kt
diff --git a/games/voxels/src/main/java/com/vayunmathur/games/voxels/MainActivity.kt b/games/voxels/src/main/java/com/vayunmathur/games/voxels/MainActivity.ktindex 5a865f7f57..d34563871b 100644--- a/games/voxels/src/main/java/com/vayunmathur/games/voxels/MainActivity.kt+++ b/games/voxels/src/main/java/com/vayunmathur/games/voxels/MainActivity.kt@@ -28,6 +28,7 @@ import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.width+import androidx.compose.foundation.layout.widthIn import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.systemGestureExclusion import androidx.compose.runtime.CompositionLocalProvider@@ -150,7 +151,9 @@ class MainActivity : ComponentActivity() {         com.vayunmathur.games.voxels.platform.SoundFx.init(this)         setContent {             VoxelsTheme {-                var inventoryJson by remember { mutableStateOf("""{"selected":0,"slots":[{"id":3,"count":64},{"id":2,"count":64},{"id":1,"count":64},{"id":4,"count":16},{"id":10,"count":32},{"id":6,"count":32},{"id":7,"count":16},{"id":8,"count":16},{"id":9,"count":16}]}""") }+                // Empty until the engine publishes the real inventory (it used to show a fake starter+                // kit that didn't match a loaded save for the first frames).+                var inventoryJson by remember { mutableStateOf("{}") }                 var debugJson by remember { mutableStateOf("Voxels Engine\nInitializing Vulkan...\nMatcha Atlas 64x64") }                 var healthJson by remember { mutableStateOf("{}") }                 // Player settings (gear button). The debug readout is now one of them, off by default.@@ -528,17 +531,15 @@ class MainActivity : ComponentActivity() {                             }                         } -                        // Health/effects HUD just above the hotbar.-                        Box(Modifier.align(Alignment.BottomStart).padding(start = 16.dp, bottom = 78.dp)) {-                            HealthOverlay(healthJson)-                        }-                        // Boss health bar (Ender Dragon) at the top.-                        Box(Modifier.align(Alignment.TopCenter).padding(top = 70.dp)) {-                            BossBar(healthJson)-                        }-                        // Elytra glide indicator, above the hotbar.-                        Box(Modifier.align(Alignment.BottomCenter).padding(bottom = 92.dp)) {+                        // Above the hotbar, centred between the stick and the action buttons: the glide+                        // chip, then effects, then hearts, stacked so they can't overlap each other or+                        // the stick (effect chips used to grow up into it from the bottom-left corner).+                        Column(+                            Modifier.align(Alignment.BottomCenter).padding(bottom = 80.dp).widthIn(max = 260.dp),+                            horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.spacedBy(4.dp),+                        ) {                             GlideIndicator(healthJson)+                            HealthOverlay(healthJson)                         }                          Box(Modifier.align(Alignment.BottomCenter).padding(bottom = 12.dp)) {@@ -556,12 +557,19 @@ class MainActivity : ComponentActivity() {                                     IconButton(onClick = { paused = true }, modifier = hudButton) { IconMenu(tint = Color.White) }                                     IconButton(onClick = { settingsOpen = true }, modifier = hudButton) { IconSettings(tint = Color.White) }                                 }+                                // Debug readout under the buttons (left), clear of the online chips (right).+                                if (settings.showDebug) { DebugOverlay(debugJson = debugJson, modifier = Modifier.widthIn(max = 280.dp)) }                             }-                            if (settings.showDebug) { DebugOverlay(debugJson = debugJson) }                         } -                        newAchievement?.let { ach ->-                            Box(Modifier.align(Alignment.TopCenter).padding(top = 80.dp)) {+                        // Boss bar and achievement toast share one top-centre column so they stack+                        // instead of drawing over each other.+                        Column(+                            Modifier.align(Alignment.TopCenter).padding(top = 70.dp),+                            horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.spacedBy(8.dp),+                        ) {+                            BossBar(healthJson)+                            newAchievement?.let { ach ->                                 AchievementNotification(ach) { achievements?.dismissNotification() }                             }                         }
games/voxels/src/main/java/com/vayunmathur/games/voxels/ui/Hotbar.kt
diff --git a/games/voxels/src/main/java/com/vayunmathur/games/voxels/ui/Hotbar.kt b/games/voxels/src/main/java/com/vayunmathur/games/voxels/ui/Hotbar.ktindex c9ee58d0e3..6750c30d00 100644--- a/games/voxels/src/main/java/com/vayunmathur/games/voxels/ui/Hotbar.kt+++ b/games/voxels/src/main/java/com/vayunmathur/games/voxels/ui/Hotbar.kt@@ -4,6 +4,7 @@ import androidx.compose.foundation.Image import androidx.compose.foundation.background import androidx.compose.foundation.border import androidx.compose.foundation.clickable+import androidx.compose.foundation.gestures.detectTapGestures import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Row@@ -21,6 +22,7 @@ import androidx.compose.ui.draw.clip import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.FilterQuality import androidx.compose.ui.graphics.asImageBitmap+import androidx.compose.ui.input.pointer.pointerInput import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.unit.dp import com.vayunmathur.library.ui.MaterialTheme@@ -184,8 +186,10 @@ fun Hotbar(         InventoryState()     }     val ctx = LocalContext.current+    // The row is only as wide as its slots, and swallows taps on its padding and in the gaps between+    // slots: a slightly-missed slot tap used to fall through and place a block in the world.     Row(-        modifier = modifier.fillMaxWidth().padding(8.dp),+        modifier = modifier.pointerInput(Unit) { detectTapGestures { } }.padding(8.dp),         horizontalArrangement = Arrangement.spacedBy(4.dp, Alignment.CenterHorizontally)     ) {         state.slots.take(9).forEachIndexed { idx, slot ->
games/voxels/src/test/java/com/vayunmathur/games/voxels/ui/VoxelScreensTest.kt
diff --git a/games/voxels/src/test/java/com/vayunmathur/games/voxels/ui/VoxelScreensTest.kt b/games/voxels/src/test/java/com/vayunmathur/games/voxels/ui/VoxelScreensTest.ktindex b0f270dc8c..a44065feaf 100644--- a/games/voxels/src/test/java/com/vayunmathur/games/voxels/ui/VoxelScreensTest.kt+++ b/games/voxels/src/test/java/com/vayunmathur/games/voxels/ui/VoxelScreensTest.kt@@ -3,6 +3,13 @@ package com.vayunmathur.games.voxels.ui import androidx.compose.ui.test.junit4.createComposeRule import androidx.compose.ui.test.onNodeWithContentDescription import androidx.compose.ui.test.onNodeWithText+import androidx.compose.ui.test.onNodeWithTag+import androidx.compose.ui.test.performTouchInput+import androidx.compose.ui.test.click+import androidx.compose.ui.platform.testTag+import androidx.compose.ui.input.pointer.pointerInput+import androidx.compose.foundation.gestures.detectTapGestures+import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.ui.test.performClick import androidx.compose.ui.test.performScrollTo import androidx.test.core.app.ApplicationProvider@@ -128,4 +135,20 @@ class VoxelScreensTest {         rule.onNodeWithText("Create & Play").performScrollTo().performClick()         assertEquals(com.vayunmathur.games.voxels.data.WorldMode.SURVIVAL, mode)     }++    @Test fun `taps in the hotbar's gaps don't reach the world`() {+        var worldTaps = 0+        rule.setContent {+            androidx.compose.foundation.layout.Box(androidx.compose.ui.Modifier.fillMaxSize()) {+                androidx.compose.foundation.layout.Box(+                    androidx.compose.ui.Modifier.fillMaxSize().pointerInput(Unit) { detectTapGestures { worldTaps++ } }+                )+                Hotbar(inventoryJson = "{}", onSelect = {}, modifier = androidx.compose.ui.Modifier.testTag("hotbar"))+            }+        }+        // The padding corner of the row is not on any slot.+        rule.onNodeWithTag("hotbar").performTouchInput { click(androidx.compose.ui.geometry.Offset(2f, 2f)) }+        rule.waitForIdle()+        assertEquals(0, worldTaps)+    } }