voxels: make on-screen controls legible over bright scenes (#ux-audit)
- Commit
76fa5ff1f615458d89f5e2040946eea2425f0dd1- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-13 01:44 UTC (23 days ago)
- Parents
e778a9c
Symptom: over snow, sand, sky or a sunlit beach the move stick, the look stick and the Jump/Sneak/Use buttons almost disappeared: they were drawn as white at 8-30% alpha with white labels. Root cause: ui/Joystick.kt and HoldButton drew light-on-transparent fills only (Joystick.kt:84-91, :195-204), which have no contrast against bright backgrounds. Fix: - New ui/HudStyle.kt with shared HUD tokens: a dark translucent fill (black 38%), a light outline (white 70%), a dark label shadow, and drawStickBase/drawStickKnob helpers. - Move stick and floating look stick: dark ring with light outline, light knob with dark outline (brighter while dragged). - HoldButton (Jump/Sneak/Up/Down/Fly/Use): dark fill, light 1.5 dp border, full-white label with shadow; the dimmed state stays distinguishable. - Menu and settings icon buttons get a dark disc behind white glyphs. User-visible effect: controls stay readable on any terrain, day or night. Verification: visual change; covered by the on-device test plan (snow biome at noon, cave at night).
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 de4093fdda..fd14175cd9 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.shape.CircleShape import androidx.compose.foundation.systemGestureExclusion import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.runtime.LaunchedEffect@@ -550,8 +551,10 @@ class MainActivity : ComponentActivity() { horizontalArrangement = Arrangement.SpaceBetween, verticalAlignment = Alignment.Top) { Column(verticalArrangement = Arrangement.spacedBy(6.dp)) { Row(horizontalArrangement = Arrangement.spacedBy(6.dp)) {- IconButton(onClick = { paused = true }) { IconMenu() }- IconButton(onClick = { settingsOpen = true }) { IconSettings() }+ // Dark disc + white glyph so the buttons read over bright snow or sky too.+ val hudButton = Modifier.background(Color.Black.copy(alpha = 0.38f), CircleShape)+ IconButton(onClick = { paused = true }, modifier = hudButton) { IconMenu(tint = Color.White) }+ IconButton(onClick = { settingsOpen = true }, modifier = hudButton) { IconSettings(tint = Color.White) } } } if (settings.showDebug) { DebugOverlay(debugJson = debugJson) }
games/voxels/src/main/java/com/vayunmathur/games/voxels/ui/FloatingLookJoystick.kt
diff --git a/games/voxels/src/main/java/com/vayunmathur/games/voxels/ui/FloatingLookJoystick.kt b/games/voxels/src/main/java/com/vayunmathur/games/voxels/ui/FloatingLookJoystick.ktindex e50c6e8495..97ed492377 100644--- a/games/voxels/src/main/java/com/vayunmathur/games/voxels/ui/FloatingLookJoystick.kt+++ b/games/voxels/src/main/java/com/vayunmathur/games/voxels/ui/FloatingLookJoystick.kt@@ -125,9 +125,8 @@ fun FloatingLookJoystick( drawLine(col, c - Offset(0f, arm), c + Offset(0f, arm), strokeWidth = w) } if (active) {- drawCircle(color = Color.White.copy(alpha = 0.18f), radius = 70.dp.toPx(), center = origin)- drawCircle(color = Color.White.copy(alpha = 0.08f), radius = 65.dp.toPx(), center = origin)- drawCircle(color = Color.White.copy(alpha = 0.5f), radius = 30.dp.toPx(), center = origin + knob)+ drawStickBase(origin, 70.dp.toPx())+ drawStickKnob(origin + knob, 30.dp.toPx(), active = true) } hold?.let { h -> // Progress ring around the held finger: fills toward the next mine/attack.
games/voxels/src/main/java/com/vayunmathur/games/voxels/ui/HoldButton.kt
diff --git a/games/voxels/src/main/java/com/vayunmathur/games/voxels/ui/HoldButton.kt b/games/voxels/src/main/java/com/vayunmathur/games/voxels/ui/HoldButton.ktindex 6a8c597834..9e40322aca 100644--- a/games/voxels/src/main/java/com/vayunmathur/games/voxels/ui/HoldButton.kt+++ b/games/voxels/src/main/java/com/vayunmathur/games/voxels/ui/HoldButton.kt@@ -1,6 +1,7 @@ package com.vayunmathur.games.voxels.ui import androidx.compose.foundation.background+import androidx.compose.foundation.border import androidx.compose.foundation.gestures.detectTapGestures import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.height@@ -14,6 +15,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.graphics.Color import androidx.compose.ui.input.pointer.pointerInput+import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp@@ -38,7 +40,8 @@ fun HoldButton( .width(96.dp) .height(52.dp) .clip(RoundedCornerShape(12.dp))- .background(Color.White.copy(alpha = if (dimmed) 0.12f else 0.24f))+ .background(if (dimmed) HudFillDim else HudFill)+ .border(1.5.dp, HudOutline.copy(alpha = if (dimmed) 0.4f else 0.7f), RoundedCornerShape(12.dp)) .pointerInput(Unit) { detectTapGestures( onPress = { press(); tryAwaitRelease(); release() },@@ -47,6 +50,9 @@ fun HoldButton( }, contentAlignment = Alignment.Center ) {- Text(label, color = Color.White.copy(alpha = if (dimmed) 0.5f else 0.95f), fontWeight = FontWeight.SemiBold, fontSize = 16.sp)+ Text(+ label, color = Color.White.copy(alpha = if (dimmed) 0.6f else 1f), fontWeight = FontWeight.SemiBold, fontSize = 16.sp,+ style = TextStyle(shadow = HudTextShadow),+ ) } }
games/voxels/src/main/java/com/vayunmathur/games/voxels/ui/HudStyle.kt
diff --git a/games/voxels/src/main/java/com/vayunmathur/games/voxels/ui/HudStyle.kt b/games/voxels/src/main/java/com/vayunmathur/games/voxels/ui/HudStyle.ktnew file mode 100644index 0000000000..12b5de331f--- /dev/null+++ b/games/voxels/src/main/java/com/vayunmathur/games/voxels/ui/HudStyle.kt@@ -0,0 +1,33 @@+package com.vayunmathur.games.voxels.ui++import androidx.compose.ui.geometry.Offset+import androidx.compose.ui.graphics.Color+import androidx.compose.ui.graphics.Shadow+import androidx.compose.ui.graphics.drawscope.DrawScope+import androidx.compose.ui.graphics.drawscope.Stroke+import androidx.compose.ui.unit.dp++// On-screen controls sit over a 3D world that can be anything from a night cave to a sunlit snow+// field. White-on-transparent vanished over bright scenes, so controls use a dark translucent fill+// with a light outline, and labels carry a dark shadow: legible over both extremes.++/** Fill behind a control. */+internal val HudFill = Color.Black.copy(alpha = 0.38f)+/** Fill behind a toggled-on / dimmed control. */+internal val HudFillDim = Color.Black.copy(alpha = 0.22f)+/** Outline around a control. */+internal val HudOutline = Color.White.copy(alpha = 0.7f)+/** Shadow under control labels. */+internal val HudTextShadow = Shadow(color = Color.Black.copy(alpha = 0.85f), offset = Offset(0f, 2f), blurRadius = 4f)++/** A stick's ring (dark fill + light outline) centred at [center]. */+internal fun DrawScope.drawStickBase(center: Offset, radius: Float) {+ drawCircle(HudFill, radius = radius, center = center)+ drawCircle(HudOutline, radius = radius, center = center, style = Stroke(1.5.dp.toPx()))+}++/** A stick's knob (light fill + dark outline) at [center]; brighter while [active]. */+internal fun DrawScope.drawStickKnob(center: Offset, radius: Float, active: Boolean) {+ drawCircle(Color.White.copy(alpha = if (active) 0.85f else 0.6f), radius = radius, center = center)+ drawCircle(Color.Black.copy(alpha = 0.6f), radius = radius, center = center, style = Stroke(1.5.dp.toPx()))+}
games/voxels/src/main/java/com/vayunmathur/games/voxels/ui/Joystick.kt
diff --git a/games/voxels/src/main/java/com/vayunmathur/games/voxels/ui/Joystick.kt b/games/voxels/src/main/java/com/vayunmathur/games/voxels/ui/Joystick.ktindex c1254aac5e..b4849caf97 100644--- a/games/voxels/src/main/java/com/vayunmathur/games/voxels/ui/Joystick.kt+++ b/games/voxels/src/main/java/com/vayunmathur/games/voxels/ui/Joystick.kt@@ -12,7 +12,6 @@ import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.geometry.Offset-import androidx.compose.ui.graphics.Color import androidx.compose.ui.input.pointer.pointerInput import androidx.compose.ui.unit.dp import kotlin.math.sqrt@@ -69,14 +68,8 @@ fun Joystick( } ) { val c = Offset(size.width / 2f, size.height / 2f)- drawCircle(color = Color.White.copy(alpha = 0.18f), radius = 65.dp.toPx(), center = c)- drawCircle(color = Color.White.copy(alpha = 0.08f), radius = 60.dp.toPx(), center = c)- val knobAbs = c + knob- drawCircle(- color = if (dragging) Color.White.copy(alpha = 0.55f) else Color.White.copy(alpha = 0.3f),- radius = 27.dp.toPx(),- center = knobAbs- )+ drawStickBase(c, 63.dp.toPx())+ drawStickKnob(c + knob, 27.dp.toPx(), active = dragging) } } }