From cb13453e22499a1e58cecb8b84363474a2b04f6a Mon Sep 17 00:00:00 2001 From: vrubelroman Date: Sat, 24 Oct 2026 13:03:29 +0300 Subject: [PATCH] =?UTF-8?q?Android:=20player=20layout=20after=20review=20?= =?UTF-8?q?=E2=80=94=20fonts,=20studies,=20scroll,=20title?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - List rows grow with the font scale (fixed heights cut letters at 1.3); a study's or a book's title starts on the first line and is read as the title. - Notation keeps the current move a third down what is visible, whole even beside the board with the engine on (only two or three rows there). - Top bar: no event or site — the database's name; 'round' in lower case; the whole title space opens the game's details. - The winner's 1 in medium weight; TalkBack reads ratings as Elo and the result in words. Co-Authored-By: Claude Opus 5.5 --- .../vrubelroman/chesspenguin/ui/Common.kt | 3 +- .../vrubelroman/chesspenguin/ui/GameScreen.kt | 11 +++-- .../chesspenguin/ui/GamesScreen.kt | 46 +++++++++++++------ .../vrubelroman/chesspenguin/ui/Notation.kt | 5 +- 4 files changed, 44 insertions(+), 21 deletions(-) diff --git a/androidApp/app/src/main/java/io/github/vrubelroman/chesspenguin/ui/Common.kt b/androidApp/app/src/main/java/io/github/vrubelroman/chesspenguin/ui/Common.kt index b0cfee7..58dfdce 100644 --- a/androidApp/app/src/main/java/io/github/vrubelroman/chesspenguin/ui/Common.kt +++ b/androidApp/app/src/main/java/io/github/vrubelroman/chesspenguin/ui/Common.kt @@ -155,7 +155,7 @@ fun PlayerLine( Row(modifier, verticalAlignment = Alignment.CenterVertically) { if (disc != null) { SideDisc(disc) - Spacer(Modifier.width(10.dp)) + Spacer(Modifier.width(8.dp)) } Row(Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically) { PlayerName(name, style, Modifier.weight(1f, fill = false), nameColor, maxLines, abbreviate) @@ -168,6 +168,7 @@ fun PlayerLine( result ?: "", style = style.merge(Tabular), color = if (result == "1") MaterialTheme.colorScheme.onSurface else MaterialTheme.colorScheme.onSurfaceVariant, + fontWeight = if (result == "1") androidx.compose.ui.text.font.FontWeight.Medium else null, textAlign = androidx.compose.ui.text.style.TextAlign.End, maxLines = 1, modifier = Modifier.width(24.dp), diff --git a/androidApp/app/src/main/java/io/github/vrubelroman/chesspenguin/ui/GameScreen.kt b/androidApp/app/src/main/java/io/github/vrubelroman/chesspenguin/ui/GameScreen.kt index e4a9475..5ab6fea 100644 --- a/androidApp/app/src/main/java/io/github/vrubelroman/chesspenguin/ui/GameScreen.kt +++ b/androidApp/app/src/main/java/io/github/vrubelroman/chesspenguin/ui/GameScreen.kt @@ -129,6 +129,8 @@ fun GameScreen(db: String, startPlace: Int, query: String, onBack: () -> Unit, o val app = app() val context = LocalContext.current val prefs by app.settings.prefs.collectAsState() + val libraryEntries by app.library.entries.collectAsState() + val dbEntry = libraryEntries.firstOrNull { it.id == db } var games by remember { mutableStateOf(app.shown[db]) } var place by rememberSaveable { mutableIntStateOf(startPlace) } var game by remember { mutableStateOf(null) } @@ -553,14 +555,16 @@ fun GameScreen(db: String, startPlace: Int, query: String, onBack: () -> Unit, o title = { // The event and year (else the site); the game's place and round. A tap // shows the game's details. + // No event and no site: the database's name. val event = joinKnown(tag("Event"), year(tag("Date"))).ifEmpty { joinKnown(tag("Site")) } + .ifEmpty { dbEntry?.let { displayName(it) } ?: "" } val round = tag("Round").trim().takeIf { it.isNotEmpty() && it != "?" && it != "-" } val placeLine = joinKnown( if (total > 0) stringResource(R.string.game_of, place + 1, total) else "", - round?.let { stringResource(R.string.tag_round) + " " + it } ?: "", + round?.let { stringResource(R.string.tag_round).lowercase() + " " + it } ?: "", ) Column( - Modifier.clickable( + Modifier.fillMaxWidth().clickable( enabled = g != null, onClickLabel = stringResource(R.string.game_info), role = Role.Button, @@ -937,7 +941,8 @@ private fun PlayerBar(name: String, elo: String, white: Boolean, result: String? name = name, elo = elo, result = result, - style = MaterialTheme.typography.titleSmall, + // A missing name shows the side greyed and in the regular weight (§7.11). + style = MaterialTheme.typography.titleSmall.let { if (known) it else it.copy(fontWeight = androidx.compose.ui.text.font.FontWeight.Normal) }, modifier = Modifier.fillMaxWidth().heightIn(min = 36.dp).padding(horizontal = 16.dp), disc = white, nameColor = if (known) androidx.compose.ui.graphics.Color.Unspecified else MaterialTheme.colorScheme.onSurfaceVariant, diff --git a/androidApp/app/src/main/java/io/github/vrubelroman/chesspenguin/ui/GamesScreen.kt b/androidApp/app/src/main/java/io/github/vrubelroman/chesspenguin/ui/GamesScreen.kt index c2a3eb4..4cd1020 100644 --- a/androidApp/app/src/main/java/io/github/vrubelroman/chesspenguin/ui/GamesScreen.kt +++ b/androidApp/app/src/main/java/io/github/vrubelroman/chesspenguin/ui/GamesScreen.kt @@ -282,18 +282,21 @@ private fun numberWidth(count: Int): androidx.compose.ui.unit.Dp { /// sentence by TalkBack. @Composable private fun GameRowView(number: Int, numberWidth: androidx.compose.ui.unit.Dp, row: GameRow?, onClick: () -> Unit) { + // 6 + 24 + 24 + 20 + 6 = 80 dp at the normal font size; the lines grow with a larger font. + val nameLine = lineHeight(MaterialTheme.typography.bodyLarge, 24.dp) + val detailsLine = lineHeight(MaterialTheme.typography.bodyMedium, 20.dp) val said = row?.let { rowDescription(number, it) } ?: "" Row( Modifier .fillMaxWidth() - .height(80.dp) + .height(12.dp + nameLine * 2 + detailsLine) .clickable(enabled = row != null, onClick = onClick) .clearAndSetSemantics { if (row != null) contentDescription = said } .padding(horizontal = 16.dp, vertical = 6.dp), verticalAlignment = Alignment.Top, ) { // Level with White's line. - Box(Modifier.width(numberWidth).height(24.dp), contentAlignment = Alignment.CenterEnd) { + Box(Modifier.width(numberWidth).height(nameLine), contentAlignment = Alignment.CenterEnd) { Text( groupDigits(number), style = MaterialTheme.typography.bodySmall.merge(Tabular), @@ -302,12 +305,12 @@ private fun GameRowView(number: Int, numberWidth: androidx.compose.ui.unit.Dp, r ) } Spacer(Modifier.width(12.dp)) - GameRowText(row, Modifier.weight(1f)) + GameRowText(row, nameLine, detailsLine, Modifier.weight(1f)) } } @Composable -private fun GameRowText(row: GameRow?, modifier: Modifier) { +private fun GameRowText(row: GameRow?, nameLine: androidx.compose.ui.unit.Dp, detailsLine: androidx.compose.ui.unit.Dp, modifier: Modifier) { Column(modifier) { if (row == null) return@Column val style = MaterialTheme.typography.bodyLarge @@ -316,10 +319,13 @@ private fun GameRowText(row: GameRow?, modifier: Modifier) { val black = row.black.trim().takeIf { it.isNotEmpty() && it != "?" } if (white != null && black == null) { // A study or a book position: a title for White and no Black — two lines of it. - PlayerLine(white, elo(row.whiteElo), null, style, Modifier.height(48.dp), maxLines = 2, abbreviate = false) + // From the top, level with the number, not centred in the two lines. + Box(Modifier.height(nameLine * 2)) { + PlayerLine(white, elo(row.whiteElo), null, style, maxLines = 2, abbreviate = false) + } } else { - PlayerLine(white ?: "?", elo(row.whiteElo), sideResult(row.result, true), style, Modifier.height(24.dp), nameColor = if (white == null) muted else androidx.compose.ui.graphics.Color.Unspecified) - PlayerLine(black ?: "?", elo(row.blackElo), sideResult(row.result, false), style, Modifier.height(24.dp), nameColor = if (black == null) muted else androidx.compose.ui.graphics.Color.Unspecified) + PlayerLine(white ?: "?", elo(row.whiteElo), sideResult(row.result, true), style, Modifier.height(nameLine), nameColor = if (white == null) muted else androidx.compose.ui.graphics.Color.Unspecified) + PlayerLine(black ?: "?", elo(row.blackElo), sideResult(row.result, false), style, Modifier.height(nameLine), nameColor = if (black == null) muted else androidx.compose.ui.graphics.Color.Unspecified) } val details = joinKnown(row.event, year(row.date), row.eco) if (details.isNotEmpty()) { @@ -329,7 +335,7 @@ private fun GameRowText(row: GameRow?, modifier: Modifier) { color = muted, maxLines = 1, overflow = TextOverflow.Ellipsis, - modifier = Modifier.height(20.dp), + modifier = Modifier.height(detailsLine), ) } } @@ -339,21 +345,31 @@ private fun GameRowText(row: GameRow?, modifier: Modifier) { @Composable private fun rowDescription(number: Int, row: GameRow): String { val player = { label: String, name: String, rating: String -> - "$label: " + joinKnownComma(name.trim().takeIf { it.isNotEmpty() } ?: "?", elo(rating)) + "$label: " + joinKnownComma(name.trim().takeIf { it.isNotEmpty() } ?: "?", elo(rating).let { if (it.isEmpty()) "" else "Elo $it" }) } val result = when (row.result) { - "1-0" -> "1-0, " + stringResource(R.string.white_won) - "0-1" -> "0-1, " + stringResource(R.string.black_won) - "1/2-1/2" -> "½-½, " + stringResource(R.string.draw) + "1-0" -> "1-0, " + stringResource(R.string.white_won).lowercase() + "0-1" -> "0-1, " + stringResource(R.string.black_won).lowercase() + "1/2-1/2" -> stringResource(R.string.draw) else -> "" } + // A study or a book chapter: a title for White and no Black is read as the title. + val title = row.white.trim().takeIf { it.isNotEmpty() && it != "?" && row.black.trim().let { b -> b.isEmpty() || b == "?" } } return listOf( stringResource(R.string.game_number, groupDigits(number)), - player(stringResource(R.string.tag_white), row.white, row.whiteElo), - player(stringResource(R.string.tag_black), row.black, row.blackElo), + title ?: player(stringResource(R.string.tag_white), row.white, row.whiteElo), + if (title != null) "" else player(stringResource(R.string.tag_black), row.black, row.blackElo), result, - joinKnown(row.event, year(row.date), row.eco), + listOf(row.event, year(row.date), row.eco).map { it.trim() }.filter { it.isNotEmpty() && it != "?" }.joinToString(", "), ).filter { it.isNotEmpty() }.joinToString(". ") } private fun joinKnownComma(vararg parts: String): String = parts.filter { it.isNotEmpty() }.joinToString(", ") + +/// A text style's line height in dp (it grows with the font scale), at least `min`. +@Composable +private fun lineHeight(style: androidx.compose.ui.text.TextStyle, min: androidx.compose.ui.unit.Dp): androidx.compose.ui.unit.Dp { + val h = style.lineHeight + if (!h.isSp) return min + return with(androidx.compose.ui.platform.LocalDensity.current) { h.toDp() }.coerceAtLeast(min) +} diff --git a/androidApp/app/src/main/java/io/github/vrubelroman/chesspenguin/ui/Notation.kt b/androidApp/app/src/main/java/io/github/vrubelroman/chesspenguin/ui/Notation.kt index 784f982..7e79fe2 100644 --- a/androidApp/app/src/main/java/io/github/vrubelroman/chesspenguin/ui/Notation.kt +++ b/androidApp/app/src/main/java/io/github/vrubelroman/chesspenguin/ui/Notation.kt @@ -221,8 +221,9 @@ fun Notation( val at = where[current] ?: if (current == 0) 0 else return@LaunchedEffect val visible = state.layoutInfo.visibleItemsInfo if (visible.none { it.index == at } || visible.firstOrNull()?.index == at || visible.lastOrNull()?.index == at) { - // Keep the current move about the middle of what is visible. - state.animateScrollToItem((at - 2).coerceAtLeast(0)) + // The current move a third down what is visible: whole however few rows fit + // (beside the board with the engine on, only two or three). + state.animateScrollToItem(at, -(state.layoutInfo.viewportSize.height / 3)) } } LazyColumn(modifier, state = state, contentPadding = PaddingValues(bottom = 8.dp)) {