mirror of
https://github.com/D-Modem/app.git
synced 2026-11-28 17:38:05 -08:00
Modem lights: a vertical LED option (off; a mockup beside the horizontal ones: lights-vertical.png)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0172Hejd12i4aYikYW9vgpZs
This commit is contained in:
2 files changed
+43
-11
No files matched your search
@@ -129,9 +129,9 @@ private val Badge = Color(0xffeceef1)
|
||||
|
||||
/** the panel drawn for [lights] (the screenshots draw it too) */
|
||||
@Composable
|
||||
fun Panel(lights: Lights, modifier: Modifier = Modifier, compact: Boolean = false, bare: Boolean = false) {
|
||||
fun Panel(lights: Lights, modifier: Modifier = Modifier, compact: Boolean = false, bare: Boolean = false, vertical: Boolean = false) {
|
||||
if (bare) {
|
||||
Strip(lights, modifier, compact = false)
|
||||
Strip(lights, modifier, compact = false, vertical)
|
||||
return
|
||||
}
|
||||
val shape = RectangleShape
|
||||
@@ -151,14 +151,14 @@ fun Panel(lights: Lights, modifier: Modifier = Modifier, compact: Boolean = fals
|
||||
// (the strip the lights sit in)
|
||||
Spacer(Modifier.height(10.dp))
|
||||
}
|
||||
Strip(lights, Modifier, compact)
|
||||
Strip(lights, Modifier, compact, vertical)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** the strip the lights sit in: their legends over them */
|
||||
@Composable
|
||||
private fun Strip(lights: Lights, modifier: Modifier, compact: Boolean) {
|
||||
private fun Strip(lights: Lights, modifier: Modifier, compact: Boolean, vertical: Boolean = false) {
|
||||
Box(
|
||||
modifier
|
||||
.fillMaxWidth()
|
||||
@@ -174,22 +174,24 @@ private fun Strip(lights: Lights, modifier: Modifier, compact: Boolean) {
|
||||
fontWeight = FontWeight.Bold, letterSpacing = 0.4.sp, maxLines = 1,
|
||||
)
|
||||
Spacer(Modifier.height(if (compact) 2.dp else 5.dp))
|
||||
Led(lit, if (compact) 4.dp else 6.dp)
|
||||
Led(lit, if (compact) 4.dp else 6.dp, vertical)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** an LED: a sharp-cornered red bar, dark when off; lit, bright with a square glow around it */
|
||||
/** an LED: a sharp-cornered red bar, dark when off; lit, bright with a square glow around it ([vertical]: standing up) */
|
||||
@Composable
|
||||
private fun Led(lit: Boolean, height: Dp) {
|
||||
val w = height * 2.2f
|
||||
val pad = height * 0.6f
|
||||
Canvas(Modifier.size(w + pad * 2, height + pad * 2)) {
|
||||
private fun Led(lit: Boolean, thickness: Dp, vertical: Boolean = false) {
|
||||
val long = thickness * 2.2f
|
||||
val w = if (vertical) thickness else long
|
||||
val h = if (vertical) long else thickness
|
||||
val pad = thickness * 0.6f
|
||||
Canvas(Modifier.size(w + pad * 2, h + pad * 2)) {
|
||||
val p = pad.toPx()
|
||||
val bw = w.toPx()
|
||||
val bh = height.toPx()
|
||||
val bh = h.toPx()
|
||||
val at = Offset(p, p)
|
||||
val bar = Size(bw, bh)
|
||||
if (lit) {
|
||||
|
||||
@@ -6,6 +6,7 @@ import android.graphics.Bitmap
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.ui.Modifier
|
||||
@@ -17,6 +18,8 @@ import androidx.compose.ui.test.junit4.createComposeRule
|
||||
import androidx.compose.ui.test.onNodeWithContentDescription
|
||||
import androidx.compose.ui.test.onNodeWithTag
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.compose.material3.Text
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
@@ -63,4 +66,31 @@ class ModemLightsTest {
|
||||
}
|
||||
assertTrue("lit LEDs drawn: $bright", bright > 50)
|
||||
}
|
||||
|
||||
/** a mockup: the LEDs lying down (as they are) and standing up, side by side: build/screens/lights-vertical.png */
|
||||
@Test
|
||||
@Config(sdk = [35], qualifiers = "w820dp-h900dp-xxhdpi")
|
||||
fun verticalMockup() {
|
||||
val online = Lights(mr = true, tr = true, cs = true, aa = true, cd = true, oh = true, rd = true, sd = false, arq = true)
|
||||
compose.setContent {
|
||||
Row(
|
||||
Modifier.testTag("all").background(Color(0xfff5f5f7)).padding(12.dp),
|
||||
horizontalArrangement = Arrangement.spacedBy(12.dp),
|
||||
) {
|
||||
for (vertical in listOf(false, true)) {
|
||||
Column(Modifier.width(380.dp), verticalArrangement = Arrangement.spacedBy(10.dp)) {
|
||||
Text(if (vertical) "Vertical" else "Horizontal (now)", fontSize = 14.sp, color = Color(0xff222222))
|
||||
Panel(Lights(mr = true, tr = true, cs = true, aa = true), vertical = vertical)
|
||||
Panel(online, vertical = vertical)
|
||||
Panel(online, compact = true, vertical = vertical)
|
||||
Panel(online, bare = true, vertical = vertical)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
compose.waitForIdle()
|
||||
val bmp = compose.onNodeWithTag("all").captureToImage().asAndroidBitmap()
|
||||
File("build/screens").mkdirs()
|
||||
File("build/screens/lights-vertical.png").outputStream().use { bmp.compress(Bitmap.CompressFormat.PNG, 100, it) }
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user