Compare commits

..
Author SHA1 Message Date
Claude 8990dde363 Yahtzee: two-column score card with larger text, scrolls sideways when needed
CI / Deploy to Cloudflare Pages (pull_request) Skipped
CI / Build and check (pull_request) Successful in 8m45s
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0177JQTtqM7EzJyXYiZYEJTX
2026-10-27 03:50:51 +00:00
@@ -6,6 +6,9 @@ import androidx.compose.foundation.border
import androidx.compose.foundation.clickable import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.Canvas import androidx.compose.foundation.Canvas
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
@@ -254,29 +257,62 @@ private fun ScoreCard(
writable: Set<YahtzeeCategory>, writable: Set<YahtzeeCategory>,
onWrite: (YahtzeeCategory) -> Unit, onWrite: (YahtzeeCategory) -> Unit,
) { ) {
Column(modifier = Modifier.fillMaxWidth()) { // Upper boxes and bonus on the left, lower boxes and total on the right, so
// each half is wide enough for text that can actually be read. Each half
// has a floor on its width; if two of them do not fit (many players, large
// text) the pair scrolls sideways instead of squeezing.
BoxWithConstraints(modifier = Modifier.fillMaxWidth()) {
val needed = (CARD_LABEL_WIDTH + CARD_SEAT_WIDTH * state.cards.size).dp
val half = maxOf((maxWidth - CARD_GAP.dp) / 2, needed)
Row(
modifier = Modifier.horizontalScroll(rememberScrollState()),
horizontalArrangement = Arrangement.spacedBy(CARD_GAP.dp),
) {
Column(modifier = Modifier.width(half)) {
CardHeader(state, localSeat)
CardSection(YahtzeeSection.UPPER, state, localSeat, writable, onWrite)
TotalRow("Bonus at 63", state.cards.map { it.upperBonus })
}
Column(modifier = Modifier.width(half)) {
CardHeader(state, localSeat)
CardSection(YahtzeeSection.LOWER, state, localSeat, writable, onWrite)
Divider()
TotalRow("Total", state.cards.indices.map { state.totalFor(it) }, bold = true)
}
}
}
}
private const val CARD_LABEL_WIDTH = 120
private const val CARD_SEAT_WIDTH = 56
private const val CARD_GAP = 12
@Composable
private fun CardHeader(state: YahtzeeState, localSeat: Int) {
Row(modifier = Modifier.fillMaxWidth()) { Row(modifier = Modifier.fillMaxWidth()) {
Text("", modifier = Modifier.weight(2f), style = MaterialTheme.typography.labelSmall) Text("", modifier = Modifier.weight(2f))
state.cards.indices.forEach { seat -> state.cards.indices.forEach { seat ->
Text( Text(
text = if (seat == localSeat) "You" else "S$seat", text = if (seat == localSeat) "You" else "S$seat",
modifier = Modifier.weight(1f), modifier = Modifier.weight(1f),
style = MaterialTheme.typography.labelSmall, style = MaterialTheme.typography.labelLarge,
fontWeight = FontWeight.Bold, fontWeight = FontWeight.Bold,
) )
} }
} }
YahtzeeSection.entries.forEach { section -> }
@Composable
private fun CardSection(
section: YahtzeeSection,
state: YahtzeeState,
localSeat: Int,
writable: Set<YahtzeeCategory>,
onWrite: (YahtzeeCategory) -> Unit,
) {
YahtzeeCategory.entries.filter { it.section == section }.forEach { category -> YahtzeeCategory.entries.filter { it.section == section }.forEach { category ->
CardRow(state, localSeat, category, writable, onWrite) CardRow(state, localSeat, category, writable, onWrite)
} }
if (section == YahtzeeSection.UPPER) {
TotalRow("Bonus at 63", state.cards.map { it.upperBonus })
}
}
Divider()
TotalRow("Total", state.cards.indices.map { state.totalFor(it) }, bold = true)
}
} }
@Composable @Composable
@@ -292,12 +328,12 @@ private fun CardRow(
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.clickable(enabled = open) { onWrite(category) } .clickable(enabled = open) { onWrite(category) }
.padding(vertical = 2.dp), .padding(vertical = 5.dp),
) { ) {
Text( Text(
text = category.label, text = category.label,
modifier = Modifier.weight(2f), modifier = Modifier.weight(2f),
style = MaterialTheme.typography.bodySmall, style = MaterialTheme.typography.bodyMedium,
fontWeight = if (open) FontWeight.Bold else FontWeight.Normal, fontWeight = if (open) FontWeight.Bold else FontWeight.Normal,
) )
state.cards.forEachIndexed { seat, card -> state.cards.forEachIndexed { seat, card ->
@@ -311,7 +347,7 @@ private fun CardRow(
else -> "—" else -> "—"
}, },
modifier = Modifier.weight(1f), modifier = Modifier.weight(1f),
style = MaterialTheme.typography.bodySmall, style = MaterialTheme.typography.bodyMedium,
color = if (written == null && open) WallaceRed else MaterialTheme.colorScheme.onSurface, color = if (written == null && open) WallaceRed else MaterialTheme.colorScheme.onSurface,
) )
} }
@@ -320,18 +356,18 @@ private fun CardRow(
@Composable @Composable
private fun TotalRow(label: String, values: List<Int>, bold: Boolean = false) { private fun TotalRow(label: String, values: List<Int>, bold: Boolean = false) {
Row(modifier = Modifier.fillMaxWidth().padding(vertical = 2.dp)) { Row(modifier = Modifier.fillMaxWidth().padding(vertical = 5.dp)) {
Text( Text(
text = label, text = label,
modifier = Modifier.weight(2f), modifier = Modifier.weight(2f),
style = MaterialTheme.typography.bodySmall, style = MaterialTheme.typography.bodyMedium,
fontWeight = if (bold) FontWeight.Bold else FontWeight.Normal, fontWeight = if (bold) FontWeight.Bold else FontWeight.Normal,
) )
values.forEach { values.forEach {
Text( Text(
text = "$it", text = "$it",
modifier = Modifier.weight(1f), modifier = Modifier.weight(1f),
style = MaterialTheme.typography.bodySmall, style = MaterialTheme.typography.bodyMedium,
fontWeight = if (bold) FontWeight.Bold else FontWeight.Normal, fontWeight = if (bold) FontWeight.Bold else FontWeight.Normal,
) )
} }