feat(ui): Steam Deck menu icons, and Compose previews rendered to PNGs (#2900)

* Rail and second-screen icons in the Steam Deck menu's style

Solid icons throughout the rail, and Steam's glyphs where Steam has the
same place: Library is the four-square grid, Stores the price tag,
Downloads the download arrow, Settings the gear. On the second screen,
Screenshots uses Steam's Media picture and Chat its Friends people.

* Compose previews of the launcher and the in-game menu, rendered to PNGs

Debug-only previews of the launcher on each tab and the in-game menu's
pages, built from the production composables with sample state and
no-op actions, at the Duo's handheld size and in portrait.
PreviewRenderTest draws each with Robolectric's native graphics into
app/build/preview-renders/, so a UI change can be looked at without a
device, and fails on a preview that throws or draws nothing.
docs/compose-previews.md says how to run and extend them.

* Preview renders wait for store accounts before drawing

A preview case can name what the render test waits for. The Library and
Stores cases wait for store accounts, which load on a background thread,
so their PNGs never catch the loading state.

* Preview renders step the paused clock while waiting for a case to be ready
This commit is contained in:
Kurt Himebauch authored and GitHub committed 2026-11-19 19:12:10 -05:00
1 parent df48a85a71
commit d4af37937a
8 files changed
+266 -51

No files matched your search

@@ -0,0 +1,63 @@
package com.droiddeck.launcher.ui
import android.app.Application
import android.graphics.Bitmap
import android.graphics.Canvas
import android.view.inspector.WindowInspector
import androidx.compose.ui.test.junit4.createComposeRule
import org.junit.Assert.assertTrue
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.ParameterizedRobolectricTestRunner
import org.robolectric.ParameterizedRobolectricTestRunner.Parameters
import org.robolectric.annotation.Config
import org.robolectric.annotation.GraphicsMode
import java.io.File
/**
* Draws every preview case with Robolectric's native graphics and saves it as a PNG under app/build/preview-renders/,
* so UI changes can be looked at without a device. Fails on a preview that throws or draws a single flat colour.
*/
@RunWith(ParameterizedRobolectricTestRunner::class)
@Config(sdk = [34], application = Application::class, qualifiers = "w960dp-h540dp-land-xhdpi")
@GraphicsMode(GraphicsMode.Mode.NATIVE)
internal class PreviewRenderTest(private val case: PreviewCase) {
@get:Rule val compose = createComposeRule()
@Test fun handheld() = render("handheld")
@Test @Config(qualifiers = "w540dp-h960dp-port-xhdpi")
fun portrait() = render("portrait")
private fun render(size: String) {
compose.mainClock.autoAdvance = false
compose.setContent { case.content() }
// The clock is paused, so step it while waiting: navigation and the loads that make a case ready run in frames.
compose.waitUntil(timeoutMillis = 15_000) { compose.mainClock.advanceTimeByFrame(); case.ready() }
// Entrance animations settle well within this.
compose.mainClock.advanceTimeBy(2_000)
compose.waitForIdle()
compose.runOnIdle { save(size) }
}
private fun save(size: String) {
// A dialog has its own window; the last one is on top.
val view = WindowInspector.getGlobalWindowViews().last()
assertTrue("${case.name}: empty bounds", view.width > 0 && view.height > 0)
val image = Bitmap.createBitmap(view.width, view.height, Bitmap.Config.ARGB_8888)
view.draw(Canvas(image))
val pixels = IntArray(image.width * image.height)
image.getPixels(pixels, 0, image.width, 0, 0, image.width, image.height)
assertTrue("${case.name}: drew one flat colour", pixels.any { it != pixels.first() })
val out = File("build/preview-renders/$size/${case.name}.png")
out.parentFile?.mkdirs()
out.outputStream().use { image.compress(Bitmap.CompressFormat.PNG, 100, it) }
image.recycle()
}
companion object {
@JvmStatic @Parameters(name = "{0}")
fun cases(): List<Array<Any>> = previewCases.map { arrayOf(it) }
}
}