From ca87d536325fcb0f0deb4bd02a6c8940586bd088 Mon Sep 17 00:00:00 2001 From: TMC Date: Mon, 16 Nov 2026 10:52:04 +0100 Subject: [PATCH] Make the home screen QR code readable from a monitor The desktop home screen showed the 53-module code at 132 dp, about two blurred pixels per module. It now takes up to 200 dp when the window is tall enough, and every QR code draws its modules in whole pixels so the edges stay sharp. Co-Authored-By: Claude Opus 5.5 --- .../commonMain/kotlin/hr/bela/shared/ui/HomeScreen.kt | 6 ++++-- .../kotlin/hr/bela/shared/ui/SettingsScreen.kt | 9 ++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/shared/src/commonMain/kotlin/hr/bela/shared/ui/HomeScreen.kt b/shared/src/commonMain/kotlin/hr/bela/shared/ui/HomeScreen.kt index d6cfe81..ad4deb7 100644 --- a/shared/src/commonMain/kotlin/hr/bela/shared/ui/HomeScreen.kt +++ b/shared/src/commonMain/kotlin/hr/bela/shared/ui/HomeScreen.kt @@ -138,6 +138,8 @@ private fun WideHome( val platform = LocalPlatform.current BoxWithConstraints(Modifier.fillMaxSize().feltBackground().padding(horizontal = 56.dp, vertical = 32.dp)) { val logo = minOf(380.dp, maxHeight * 0.48f) + // As large as the window's height allows: a phone has to read it off a monitor. + val qr = (maxHeight - 462.dp).coerceIn(132.dp, 200.dp) Row( Modifier.align(Alignment.Center).widthIn(max = 1180.dp).fillMaxWidth(), verticalAlignment = Alignment.CenterVertically, @@ -194,8 +196,8 @@ private fun WideHome( Rule() Spacer(Modifier.height(6.dp)) Row(verticalAlignment = Alignment.CenterVertically) { - QrCode(QrMatrix.LATEST_APK, Modifier.width(132.dp)) - Column(Modifier.padding(start = 18.dp)) { + QrCode(QrMatrix.LATEST_APK, Modifier.width(qr)) + Column(Modifier.padding(start = 16.dp)) { Overline("Android", color = Gold) Text( "Skeniraj kod mobitelom i igraj Belu i u aplikaciji.", diff --git a/shared/src/commonMain/kotlin/hr/bela/shared/ui/SettingsScreen.kt b/shared/src/commonMain/kotlin/hr/bela/shared/ui/SettingsScreen.kt index 3386317..0affad4 100644 --- a/shared/src/commonMain/kotlin/hr/bela/shared/ui/SettingsScreen.kt +++ b/shared/src/commonMain/kotlin/hr/bela/shared/ui/SettingsScreen.kt @@ -47,6 +47,7 @@ import hr.bela.shared.PlatformBackHandler import hr.bela.shared.res.Res import hr.bela.shared.res.logo import org.jetbrains.compose.resources.imageResource +import kotlin.math.floor /** * Settings: about the app, updating it ([updates]: the Android app's own section, none on the web) and a QR code @@ -220,12 +221,14 @@ fun QrCode(rows: List, modifier: Modifier = Modifier) { ) { Canvas(Modifier.fillMaxSize()) { val n = rows.size - val cell = size.width / n + // Whole pixels per module, so every module is sharp (a fractional size blurs the edges, which a phone + // camera reading a monitor struggles with). The few pixels left over widen the white margin. + val cell = floor(size.width / n).coerceAtLeast(1f) + val origin = floor((size.width - cell * n) / 2) for (y in 0 until n) { for (x in 0 until n) { if (rows[y][x] == '#') { - // Slight overlap so neighbouring modules join without hairline gaps. - drawRect(Color(0xFF14261C), topLeft = Offset(x * cell, y * cell), size = Size(cell + 0.6f, cell + 0.6f)) + drawRect(Color(0xFF14261C), topLeft = Offset(origin + x * cell, origin + y * cell), size = Size(cell, cell)) } } }