From 7b61906e1b2d6102c2584c35eae89d2df779f403 Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Fri, 16 Oct 2026 05:28:39 +0100 Subject: [PATCH] Lead the run summary with a width-derived artifact grid In the run detail summary, artifacts now appear at the top of the page and as a grid rather than a list: - RunDetailScreen emits the "run-artifacts" LazyColumn item before the "run-summary" item, so the captured screenshots are the first thing the operator sees. The rest of the summary and its collapsed-by-default sections are unchanged. - ArtifactGallery derives its geometry from the measured width via the new pure artifactGrid(availableWidth, preferred, spacing): it fits as many preferred-shaped cells as the width allows and stretches them to fill the row, instead of the removed fixed ARTIFACT_GRID_COLUMNS count. A host narrower than one preferred cell falls back to a single narrower cell; a non-positive preferred token never divides by zero. Tiles still open the full-size image on tap; non-image artifacts keep their compact list form. - ArtifactGalleryTest replaces the fixed-column cases with grid cases covering a narrow pane (fewer, larger cells), a wide window (more columns), a very wide window (cells near the preferred shape), the single-cell fallback and degenerate inputs, asserting the row never overflows the host. Verified with assembleDebug (APK 17,863,337 bytes, sha256 32e9081b28f5caa85f5bfa24f7fe7149eeddb919d4e71cf497e9017b80f54ce7) and the unit tests (140 tests, 0 failures/errors/skipped); captured on emulator-5554 at both window widths. --- .../net/awan/pipelines/ui/graph/Artifacts.kt | 47 +++++++------ .../pipelines/ui/screens/RunDetailScreen.kt | 37 +++++----- .../pipelines/ui/graph/ArtifactGalleryTest.kt | 70 ++++++++++++------- 3 files changed, 90 insertions(+), 64 deletions(-) diff --git a/android/app/src/main/java/net/awan/pipelines/ui/graph/Artifacts.kt b/android/app/src/main/java/net/awan/pipelines/ui/graph/Artifacts.kt index f9acba51..9b6335af 100644 --- a/android/app/src/main/java/net/awan/pipelines/ui/graph/Artifacts.kt +++ b/android/app/src/main/java/net/awan/pipelines/ui/graph/Artifacts.kt @@ -99,9 +99,10 @@ internal fun ArtifactsSection( * hardcodes a host. The grid is built from non-lazy chunked [Row]s, so it never * nests a scrollable inside the Summary [LazyColumn] or the pane's scroll. * - * The tile side is derived from the measured width (one [BoxWithConstraints]): - * a fixed tile would overflow a narrow phone pane, so each tile is the widest - * that fits the row up to the preferred [ARTIFACT_TILE_DP]. + * The grid geometry is derived from the measured width (one [BoxWithConstraints], + * see [artifactGrid]): as many cells as fit at the preferred [ARTIFACT_TILE_DP] + * shape, stretched to fill the row, so a wide window shows several thumbnails per + * row and a narrow one shows fewer, larger ones — never a fixed column count. */ @Composable internal fun ArtifactGallery( @@ -113,11 +114,10 @@ internal fun ArtifactGallery( ) { val text = pipelinesText() BoxWithConstraints(modifier.fillMaxWidth()) { - val tile = artifactTileDp( + val grid = artifactGrid( availableWidth = maxWidth, - columns = ARTIFACT_GRID_COLUMNS, - spacing = ARTIFACT_TILE_SPACING_DP, preferred = ARTIFACT_TILE_DP, + spacing = ARTIFACT_TILE_SPACING_DP, ) Column(Modifier.fillMaxWidth(), verticalArrangement = Arrangement.spacedBy(8.dp)) { groups.forEach { group -> @@ -129,17 +129,17 @@ internal fun ArtifactGallery( } val images = group.artifacts.filter { isImageContentType(it.contentType) } val others = group.artifacts.filterNot { isImageContentType(it.contentType) } - images.chunked(ARTIFACT_GRID_COLUMNS).forEach { rowArtifacts -> + images.chunked(grid.columns).forEach { rowArtifacts -> Row( modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(ARTIFACT_TILE_SPACING_DP), ) { rowArtifacts.forEach { artifact -> - ArtifactTile(artifact, configuredServerUrl, fetchArtifactBytes, tile) + ArtifactTile(artifact, configuredServerUrl, fetchArtifactBytes, grid.cell) } // Keep a partial last row's tiles aligned to the grid. - repeat(ARTIFACT_GRID_COLUMNS - rowArtifacts.size) { - Box(Modifier.size(tile)) + repeat(grid.columns - rowArtifacts.size) { + Box(Modifier.size(grid.cell)) } } } @@ -152,15 +152,23 @@ internal fun ArtifactGallery( } /** - * The side of one square gallery tile: the widest that fits [columns] tiles and - * their gaps in [availableWidth], capped at the preferred [preferred] so a wide - * window keeps compact thumbnails and a narrow one keeps every tile fully on - * screen. Pure, so the fitting is unit-tested without a device. + * One gallery row's geometry: the number of cells that fit the measured width at + * the preferred tile shape and the side each cell is stretched to. Pure, so the + * fitting is unit-tested without a device. */ -internal fun artifactTileDp(availableWidth: Dp, columns: Int, spacing: Dp, preferred: Dp): Dp { - if (columns <= 0) return preferred - val fit = (availableWidth - spacing * (columns - 1)) / columns - return fit.coerceIn(0.dp, preferred) +internal data class ArtifactGrid(val columns: Int, val cell: Dp) + +/** + * The gallery geometry for [availableWidth]: the most [preferred]-shaped cells + * that fit with their [spacing] gaps, and each cell widened to fill the row + * exactly. A window narrower than one preferred cell falls back to a single, + * narrower cell; a non-positive preferred token never divides by zero. Pure. + */ +internal fun artifactGrid(availableWidth: Dp, preferred: Dp, spacing: Dp): ArtifactGrid { + if (preferred <= 0.dp) return ArtifactGrid(columns = 1, cell = availableWidth.coerceAtLeast(0.dp)) + val columns = ((availableWidth + spacing) / (preferred + spacing)).toInt().coerceAtLeast(1) + val cell = ((availableWidth - spacing * (columns - 1)) / columns).coerceAtLeast(0.dp) + return ArtifactGrid(columns = columns, cell = cell) } /** @@ -335,6 +343,3 @@ private val ARTIFACT_TILE_DP = 96.dp /** Gap between gallery thumbnails; shared by the row arrangement and the fitting. */ private val ARTIFACT_TILE_SPACING_DP = 8.dp - -/** Image thumbnails per gallery row. */ -private const val ARTIFACT_GRID_COLUMNS = 3 diff --git a/android/app/src/main/java/net/awan/pipelines/ui/screens/RunDetailScreen.kt b/android/app/src/main/java/net/awan/pipelines/ui/screens/RunDetailScreen.kt index 8336dbc7..99e2caed 100644 --- a/android/app/src/main/java/net/awan/pipelines/ui/screens/RunDetailScreen.kt +++ b/android/app/src/main/java/net/awan/pipelines/ui/screens/RunDetailScreen.kt @@ -301,6 +301,26 @@ private fun RunSummaryTab( modifier = columnModifier, contentPadding = PaddingValues(vertical = 16.dp), ) { + // The artifacts gallery leads the summary: the captured screenshots + // are the first thing the operator sees, with the run's own facts + // below it. + item(key = "run-artifacts") { + Column( + modifier = Modifier.fillMaxWidth().padding(horizontal = 16.dp, vertical = 8.dp), + verticalArrangement = Arrangement.spacedBy(8.dp), + ) { + Text("Artifacts", style = text.sectionHeader) + if (artifactGroups.isEmpty()) { + Text(artifactsEmptyMessage(run.executing), style = text.meta) + } else { + ArtifactGallery( + groups = artifactGroups, + configuredServerUrl = configuredServerUrl, + fetchArtifactBytes = fetchArtifactBytes, + ) + } + } + } item(key = "run-summary") { Column( modifier = Modifier.fillMaxWidth().padding(horizontal = 16.dp), @@ -336,23 +356,6 @@ private fun RunSummaryTab( CodeBlock("Diagnostic", run.diagnostic, Modifier.padding(top = 8.dp)) } } - item(key = "run-artifacts") { - Column( - modifier = Modifier.fillMaxWidth().padding(horizontal = 16.dp, vertical = 8.dp), - verticalArrangement = Arrangement.spacedBy(8.dp), - ) { - Text("Artifacts", style = text.sectionHeader) - if (artifactGroups.isEmpty()) { - Text(artifactsEmptyMessage(run.executing), style = text.meta) - } else { - ArtifactGallery( - groups = artifactGroups, - configuredServerUrl = configuredServerUrl, - fetchArtifactBytes = fetchArtifactBytes, - ) - } - } - } } } } diff --git a/android/app/src/test/java/net/awan/pipelines/ui/graph/ArtifactGalleryTest.kt b/android/app/src/test/java/net/awan/pipelines/ui/graph/ArtifactGalleryTest.kt index 94d76c2a..ab097d4e 100644 --- a/android/app/src/test/java/net/awan/pipelines/ui/graph/ArtifactGalleryTest.kt +++ b/android/app/src/test/java/net/awan/pipelines/ui/graph/ArtifactGalleryTest.kt @@ -1,5 +1,6 @@ package net.awan.pipelines.ui.graph +import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp import net.awan.pipelines.data.protocol.StageArtifact import org.junit.Assert.assertEquals @@ -34,43 +35,60 @@ class ArtifactGalleryTest { } @Test - fun narrowWidthShrinksTilesSoTheRowNeverOverflows() { - // A depth-2 phone stage pane is ~360dp less two 56dp peeks and the 16dp - // side paddings ≈216dp; three preferred 96dp tiles would overflow, so the - // tile shrinks to the widest that fits. - val tile = artifactTileDp(availableWidth = 216.dp, columns = 3, spacing = spacing, preferred = preferred) - assertEquals((216f - 2 * 8f) / 3f, tile.value, 0.001f) - assertTrue(tile < preferred) - assertTrue(tile.value * 3 + 2 * 8f <= 216f) + fun aNarrowPaneShowsFewerLargerCellsRatherThanAFixedCount() { + // A depth-2 phone stage pane is ~360dp less the peeks and side paddings + // ≈216dp: the grid fits two preferred-shaped cells (not a forced three) + // and stretches each to fill the row. + val grid = artifactGrid(availableWidth = 216.dp, preferred = preferred, spacing = spacing) + assertEquals(2, grid.columns) + assertEquals((216f - 8f) / 2f, grid.cell.value, 0.001f) + assertTrue(grid.cell >= preferred) + assertRowFits(grid, availableWidth = 216.dp) } @Test - fun widthThatFitsThreePreferredTilesKeepsThePreferredTile() { - // 328dp fits 3x96 + 2x8 with room to spare, so tiles stay compact and the - // row does not overflow. - val tile = artifactTileDp(availableWidth = 328.dp, columns = 3, spacing = spacing, preferred = preferred) - assertEquals(preferred, tile) - assertTrue(tile.value * 3 + 2 * 8f <= 328f) + fun aWiderWindowFitsMoreColumnsOfThePreferredShape() { + // 328dp fits three preferred 96dp cells plus their gaps, so the grid adds + // a column instead of inflating the cells. + val grid = artifactGrid(availableWidth = 328.dp, preferred = preferred, spacing = spacing) + assertEquals(3, grid.columns) + assertEquals((328f - 2 * 8f) / 3f, grid.cell.value, 0.001f) + assertRowFits(grid, availableWidth = 328.dp) } @Test - fun wideWidthKeepsThePreferredCompactTile() { - val tile = artifactTileDp(availableWidth = 1200.dp, columns = 3, spacing = spacing, preferred = preferred) - assertEquals(preferred, tile) + fun aVeryWideWindowKeepsCellsNearThePreferredShape() { + // The cell never grows far past the preferred token; the width becomes + // more columns instead. + val grid = artifactGrid(availableWidth = 1200.dp, preferred = preferred, spacing = spacing) + assertTrue(grid.columns > 3) + assertTrue(grid.cell.value in preferred.value..(preferred.value + spacing.value)) + assertRowFits(grid, availableWidth = 1200.dp) } @Test - fun exactFitKeepsThePreferredTile() { - val available = preferred * 3 + spacing * 2 - val tile = artifactTileDp(availableWidth = available, columns = 3, spacing = spacing, preferred = preferred) - assertEquals(preferred, tile) + fun aHostNarrowerThanOnePreferredCellFallsBackToASingleCell() { + val grid = artifactGrid(availableWidth = 60.dp, preferred = preferred, spacing = spacing) + assertEquals(1, grid.columns) + assertEquals(60.dp, grid.cell) + assertRowFits(grid, availableWidth = 60.dp) } @Test - fun degenerateInputsReturnValidTiles() { - // A zero/negative column count or a host narrower than the gaps never - // yields a negative tile. - assertEquals(preferred, artifactTileDp(availableWidth = 300.dp, columns = 0, spacing = spacing, preferred = preferred)) - assertEquals(0.dp, artifactTileDp(availableWidth = 4.dp, columns = 3, spacing = spacing, preferred = preferred)) + fun degenerateInputsReturnAValidGrid() { + // A tiny or zero host, or a non-positive preferred token, never yields a + // zero/negative column count or a negative cell. + assertEquals(1, artifactGrid(availableWidth = 4.dp, preferred = preferred, spacing = spacing).columns) + assertEquals(4.dp, artifactGrid(availableWidth = 4.dp, preferred = preferred, spacing = spacing).cell) + assertEquals(0.dp, artifactGrid(availableWidth = 0.dp, preferred = preferred, spacing = spacing).cell) + val noPreferred = artifactGrid(availableWidth = 300.dp, preferred = 0.dp, spacing = spacing) + assertEquals(1, noPreferred.columns) + assertEquals(300.dp, noPreferred.cell) + } + + /** The one invariant every grid must hold: the row never overflows the host. */ + private fun assertRowFits(grid: ArtifactGrid, availableWidth: Dp) { + val used = grid.columns * grid.cell.value + (grid.columns - 1) * spacing.value + assertTrue("row $used wider than $availableWidth", used <= availableWidth.value + 0.001f) } }