Reach the covered pane's full statistics and wrap its title at whole words
A covered pane's width is spent on the covered region (`identityWidth +
startInset`), and when a second level is covered `coveredEdgesDp` gives the
nearest identity that region less the thin older edge (`startInset + minTouch`;
the leading gesture inset cancels), i.e. `identityWidth - minTouch`. Flooring a
statistics-bearing identity at the full block alone (`MIN_COVERED_PANE_WIDTH_DP +
PEEK_WIDTH_DP`, 168dp) therefore left the nearest edge at 120dp, below the
`paneStatTier` Full boundary, so a pipeline's last-run/age and average lines were
filtered out at every depth a pipeline is ever covered. `coveredIdentityWidthDp`
now floors a statistics-bearing identity one touch target above the block
(`+ minTouch`), so the nearest edge is exactly 168dp and reaches Full, while the
single-covered and title-only cases are unchanged and the active pane width still
does not depend on depth.
The covered title also broke mid-word in a narrow strip ("Complete a Task" ->
"Complet"/"e a Task"). `wholeWordTitle` now packs the title greedily onto
whole-word lines and, once they are full, drops the remaining words and
ellipsizes the last line at a word boundary; a word wider than the whole strip is
the one exception, ellipsized to the width because it has no internal boundary.
It takes an injected `measure`, so the packing rule is unit-testable without a
device, and `PaneIdentity` measures with the same `cardTitle` role it draws with.
`PaneIdentityTest` adds the pure cases: the width-degradation tiers, the
statistics-bearing width floor, the nearest-edge geometry at depth 2 (which fails
without the `+ minTouch` reserve, so it pins the defect), and the whole-word
wrap/ellipsis/oversized-word/no-room cases. `android/README.md` records the
corrected geometry, the fix and the run's build/test evidence.
android/ only; no new dependency, no server field, and no server/Go/installer/
Docker change. Build and unit tests only (no device): 300 tests, 0 failures.
This commit is contained in:
@@ -73,6 +73,115 @@ internal fun visiblePaneStats(stats: List<PaneStat>, tier: PaneStatTier): List<P
|
||||
PaneStatTier.Full -> stats
|
||||
}
|
||||
|
||||
/**
|
||||
* The width a covered identity must reserve for its compact content: [contentWidth]
|
||||
* (the wider of the title and the icon, already measured) plus the identity's own
|
||||
* horizontal padding, floored at the platform touch target [minTouch]. When the
|
||||
* identity carries statistics ([withStats]) it is also floored one touch target
|
||||
* above the full statistics block's width ([MIN_COVERED_PANE_WIDTH_DP] +
|
||||
* [PEEK_WIDTH_DP] + [minTouch]), because this width is spent on the covered region
|
||||
* and when a second level is covered the nearest edge gives the thin older edge
|
||||
* ([minTouch]; the leading gesture inset cancels against the region's own — see
|
||||
* `coveredEdgesDp`) inside that region, so its visible edge is this width less
|
||||
* [minTouch]. Flooring at the block alone left the nearest edge below the Full
|
||||
* boundary of [paneStatTier], so a pipeline's last-run and average lines were
|
||||
* filtered out at every depth it was covered; the floor is what makes them
|
||||
* reachable. The invariant the unit test pins is therefore [paneStatTier] of the
|
||||
* nearest *edge*, not of this width: pure, so the floor needs no device.
|
||||
*/
|
||||
internal fun coveredIdentityWidthDp(
|
||||
contentWidth: Dp,
|
||||
minTouch: Dp,
|
||||
withStats: Boolean,
|
||||
): Dp {
|
||||
val statsWidth = if (withStats) MIN_COVERED_PANE_WIDTH_DP + PEEK_WIDTH_DP + minTouch else 0.dp
|
||||
return maxOf(contentWidth + SPACING_S * 2, statsWidth, minTouch)
|
||||
}
|
||||
|
||||
/**
|
||||
* [title] laid out for a strip [maxWidthPx] wide and at most [maxLines] lines:
|
||||
* words pack greedily onto whole-word lines and, once the lines are full, the
|
||||
* remaining words are dropped and the last line is ellipsized at a word boundary,
|
||||
* so a title is never broken mid-word. A word wider than the whole strip is the
|
||||
* one exception — it is ellipsized to the width rather than wrapped, because it
|
||||
* has no internal boundary to break at. [measure] returns a candidate line's width
|
||||
* in pixels, injected so the packing rule is unit-testable without a device; blank
|
||||
* input, no room or no lines yields an empty string.
|
||||
*/
|
||||
internal fun wholeWordTitle(
|
||||
title: String,
|
||||
maxWidthPx: Int,
|
||||
maxLines: Int,
|
||||
ellipsis: String,
|
||||
measure: (String) -> Int,
|
||||
): String {
|
||||
if (maxWidthPx <= 0 || maxLines <= 0) return ""
|
||||
val words = title.trim().split(WHITESPACE).filter { it.isNotEmpty() }
|
||||
if (words.isEmpty()) return ""
|
||||
|
||||
val lines = mutableListOf<String>()
|
||||
var line = ""
|
||||
for (word in words) {
|
||||
val candidate = if (line.isEmpty()) word else "$line $word"
|
||||
if (line.isEmpty() || measure(candidate) <= maxWidthPx) {
|
||||
line = candidate
|
||||
} else {
|
||||
lines += line
|
||||
line = word
|
||||
}
|
||||
}
|
||||
if (line.isNotEmpty()) lines += line
|
||||
|
||||
val truncated = lines.size > maxLines
|
||||
val kept = if (truncated) lines.subList(0, maxLines) else lines
|
||||
return kept.mapIndexed { index, keptLine ->
|
||||
when {
|
||||
measure(keptLine) > maxWidthPx -> ellipsizeToWidth(keptLine, maxWidthPx, ellipsis, measure)
|
||||
truncated && index == kept.lastIndex -> appendEllipsis(keptLine, maxWidthPx, ellipsis, measure)
|
||||
else -> keptLine
|
||||
}
|
||||
}.joinToString("\n")
|
||||
}
|
||||
|
||||
/** The longest prefix of [text] that still leaves room for [ellipsis] in [maxWidthPx]. */
|
||||
private fun ellipsizeToWidth(
|
||||
text: String,
|
||||
maxWidthPx: Int,
|
||||
ellipsis: String,
|
||||
measure: (String) -> Int,
|
||||
): String {
|
||||
if (measure(ellipsis) > maxWidthPx) return ""
|
||||
var low = 0
|
||||
var high = text.length
|
||||
while (low < high) {
|
||||
val mid = (low + high + 1) / 2
|
||||
if (measure(text.substring(0, mid) + ellipsis) <= maxWidthPx) low = mid else high = mid - 1
|
||||
}
|
||||
return text.substring(0, low) + ellipsis
|
||||
}
|
||||
|
||||
/** [line] with a trailing [ellipsis], dropping whole trailing words until it fits. */
|
||||
private fun appendEllipsis(
|
||||
line: String,
|
||||
maxWidthPx: Int,
|
||||
ellipsis: String,
|
||||
measure: (String) -> Int,
|
||||
): String {
|
||||
var words = line.split(' ').filter { it.isNotEmpty() }
|
||||
while (words.isNotEmpty() && measure(words.joinToString(" ") + " " + ellipsis) > maxWidthPx) {
|
||||
words = words.dropLast(1)
|
||||
}
|
||||
return when {
|
||||
words.isEmpty() -> ellipsizeToWidth(line, maxWidthPx, ellipsis, measure)
|
||||
else -> words.joinToString(" ") + " " + ellipsis
|
||||
}
|
||||
}
|
||||
|
||||
private val WHITESPACE = Regex("\\s+")
|
||||
|
||||
/** At most three title lines in a covered strip; the statistics are secondary to it. */
|
||||
private const val TITLE_MAX_LINES = 3
|
||||
|
||||
/**
|
||||
* A covered pane's compact identity: its title and, when there are any, a
|
||||
* compact vertical statistics block, both centred in the peek strip. A covered
|
||||
@@ -81,14 +190,16 @@ internal fun visiblePaneStats(stats: List<PaneStat>, tier: PaneStatTier): List<P
|
||||
*
|
||||
* The strip is narrow but the identity is the whole point of it, so the title
|
||||
* wraps onto a few centered lines rather than becoming an unreadable ellipsis; it
|
||||
* is the one place a title may legitimately run over more than one line. The
|
||||
* statistics are secondary to it and degrade with the width ([paneStatTier]):
|
||||
* each is a label above its own value, only whole statistics are shown, and a
|
||||
* strip too thin for a labelled number keeps the title alone — never a number
|
||||
* clipped mid-digit or a figure without its label. [subtitle] remains for the
|
||||
* panes whose covered identity is a single status/type word (the stage pane)
|
||||
* rather than statistics, and [icon] is the pane-kind glyph drawn above the
|
||||
* title.
|
||||
* is the one place a title may legitimately run over more than one line. It wraps
|
||||
* at whole-word boundaries and ellipsizes whole words rather than breaking one
|
||||
* mid-word ([wholeWordTitle]), so a covered "Complete a Task" reads as whole words
|
||||
* instead of "Complet"/"e a Task". The statistics are secondary to it and degrade
|
||||
* with the width ([paneStatTier]): each is a label above its own value, only whole
|
||||
* statistics are shown, and a strip too thin for a labelled number keeps the title
|
||||
* alone — never a number clipped mid-digit or a figure without its label.
|
||||
* [subtitle] remains for the panes whose covered identity is a single status/type
|
||||
* word (the stage pane) rather than statistics, and [icon] is the pane-kind glyph
|
||||
* drawn above the title.
|
||||
*/
|
||||
@Composable
|
||||
fun PaneIdentity(
|
||||
@@ -99,10 +210,25 @@ fun PaneIdentity(
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
val text = pipelinesText()
|
||||
val measurer = rememberTextMeasurer()
|
||||
val density = LocalDensity.current
|
||||
// The strip's width is measured here so the statistics block can degrade with
|
||||
// the space actually available, never from a fixed depth assumption.
|
||||
BoxWithConstraints(modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
|
||||
val shown = visiblePaneStats(stats, paneStatTier(maxWidth))
|
||||
// Whole-word fit, measured against the strip's own text width (the
|
||||
// identity's horizontal padding aside) so no word is split mid-word.
|
||||
val titleLines = remember(title, maxWidth, text, measurer, density) {
|
||||
wholeWordTitle(
|
||||
title = title,
|
||||
maxWidthPx = with(density) { (maxWidth - SPACING_S * 2).toPx() }.toInt(),
|
||||
maxLines = TITLE_MAX_LINES,
|
||||
ellipsis = "…",
|
||||
measure = { candidate ->
|
||||
measurer.measure(AnnotatedString(candidate), style = text.cardTitle).size.width
|
||||
},
|
||||
)
|
||||
}
|
||||
Column(
|
||||
modifier = Modifier.padding(horizontal = SPACING_S, vertical = SPACING_M),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
@@ -115,10 +241,10 @@ fun PaneIdentity(
|
||||
Icon(imageVector = icon, contentDescription = null)
|
||||
}
|
||||
Text(
|
||||
text = title,
|
||||
text = titleLines,
|
||||
style = text.cardTitle,
|
||||
textAlign = TextAlign.Center,
|
||||
maxLines = 3,
|
||||
maxLines = TITLE_MAX_LINES,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
)
|
||||
if (!subtitle.isNullOrBlank()) {
|
||||
@@ -167,18 +293,27 @@ fun PaneIdentity(
|
||||
* the identity [icon]'s own size and the measured width of [label] (the shortest
|
||||
* label that identifies the pane, measured at runtime with the app's own type
|
||||
* role and the platform's font metrics), plus the identity's own horizontal
|
||||
* padding. The platform minimum touch target is the floor, so an edge is never
|
||||
* derived below what can be tapped; no window percentage, budget or new dp token
|
||||
* stands in for it. The caller passes this to `SlidingPaneStack`, which uses it as
|
||||
* the whole covered region's width at every depth.
|
||||
* padding. When the identity carries statistics ([withStats]) it is also floored
|
||||
* one touch target above the full statistics block's width, so a covered pane is
|
||||
* not sized for its bare title while the statistics it must carry are always
|
||||
* filtered out — the reserve covers the thin older edge the nearest identity
|
||||
* gives up when a second level is covered ([coveredIdentityWidthDp] holds the
|
||||
* pure rule). The platform minimum touch target is the floor for the whole edge,
|
||||
* so an edge is never derived below what can be tapped. The caller passes this to
|
||||
* `SlidingPaneStack`, which uses it as the whole covered region's width at every
|
||||
* depth, so the nearest edge still clears the statistics block.
|
||||
*/
|
||||
@Composable
|
||||
internal fun rememberCompactIdentityWidth(label: String, icon: ImageVector? = null): Dp {
|
||||
internal fun rememberCompactIdentityWidth(
|
||||
label: String,
|
||||
icon: ImageVector? = null,
|
||||
withStats: Boolean = false,
|
||||
): Dp {
|
||||
val measurer = rememberTextMeasurer()
|
||||
val text = pipelinesText()
|
||||
val density = LocalDensity.current
|
||||
val minTouch = LocalMinimumInteractiveComponentSize.current
|
||||
return remember(measurer, label, icon, text, density, minTouch) {
|
||||
return remember(measurer, label, icon, text, density, minTouch, withStats) {
|
||||
val labelWidth = with(density) {
|
||||
measurer.measure(
|
||||
text = AnnotatedString(label),
|
||||
@@ -187,7 +322,6 @@ internal fun rememberCompactIdentityWidth(label: String, icon: ImageVector? = nu
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
).size.width.toDp()
|
||||
}
|
||||
val content = maxOf(labelWidth, icon?.defaultWidth ?: 0.dp)
|
||||
maxOf(content + SPACING_S * 2, minTouch)
|
||||
coveredIdentityWidthDp(maxOf(labelWidth, icon?.defaultWidth ?: 0.dp), minTouch, withStats)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,148 @@
|
||||
package net.awan.pipelines.ui.components
|
||||
|
||||
import androidx.compose.ui.unit.dp
|
||||
import net.awan.pipelines.ui.theme.MIN_COVERED_PANE_WIDTH_DP
|
||||
import net.awan.pipelines.ui.theme.PEEK_WIDTH_DP
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
/**
|
||||
* The covered pane's statistics degrade by width through a pure decision, so
|
||||
* which statistics show at which width is asserted here without a device: a thin
|
||||
* strip keeps the title only, a medium strip the run counts, and a wide strip the
|
||||
* full block. No tier ever shows a figure without its label.
|
||||
*/
|
||||
class PaneIdentityTest {
|
||||
|
||||
private val counts = listOf(
|
||||
PaneStat("runs", "11"),
|
||||
PaneStat("succeeded", "9"),
|
||||
PaneStat("failed", "2"),
|
||||
PaneStat("active", "1"),
|
||||
)
|
||||
private val details = listOf(
|
||||
PaneStat("last", "succeeded · 2h ago", detail = true),
|
||||
PaneStat("avg", "1m 5s", detail = true),
|
||||
)
|
||||
|
||||
@Test
|
||||
fun aStripThinnerThanOnePeekKeepsTheTitleOnly() {
|
||||
assertEquals(PaneStatTier.Title, paneStatTier(PEEK_WIDTH_DP - 1.dp))
|
||||
assertTrue(visiblePaneStats(counts + details, PaneStatTier.Title).isEmpty())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aMinimumCoveredStripShowsTheRunCounts() {
|
||||
assertEquals(PaneStatTier.Counts, paneStatTier(MIN_COVERED_PANE_WIDTH_DP))
|
||||
assertEquals(counts, visiblePaneStats(counts + details, PaneStatTier.Counts))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aStripWideEnoughForTheLongestLineShowsEveryStatistic() {
|
||||
assertEquals(PaneStatTier.Full, paneStatTier(MIN_COVERED_PANE_WIDTH_DP + PEEK_WIDTH_DP))
|
||||
assertEquals(counts + details, visiblePaneStats(counts + details, PaneStatTier.Full))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun theTierBoundariesAreMonotonic() {
|
||||
val widths = listOf(0.dp, PEEK_WIDTH_DP, MIN_COVERED_PANE_WIDTH_DP, 400.dp)
|
||||
val tiers = widths.map(::paneStatTier)
|
||||
assertEquals(listOf(PaneStatTier.Title, PaneStatTier.Counts, PaneStatTier.Counts, PaneStatTier.Full), tiers)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun everyShownStatisticKeepsItsLabel() {
|
||||
for (tier in PaneStatTier.entries) {
|
||||
visiblePaneStats(counts + details, tier).forEach {
|
||||
assertTrue("a statistic without a label at $tier: $it", it.label.isNotBlank())
|
||||
assertTrue("a statistic without a value at $tier: $it", it.value.isNotBlank())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aStatisticsBearingIdentityIsNeverSizedForItsBareTitle() {
|
||||
// A short label ("Runs" measures below one peek) must still reserve the full
|
||||
// block width when it carries statistics, so the last-run/average lines are
|
||||
// reachable instead of always filtered out by the tier.
|
||||
val width = coveredIdentityWidthDp(contentWidth = 30.dp, minTouch = 48.dp, withStats = true)
|
||||
assertTrue("a stats identity below the full block width: $width", width >= MIN_COVERED_PANE_WIDTH_DP + PEEK_WIDTH_DP)
|
||||
assertEquals(PaneStatTier.Full, paneStatTier(width))
|
||||
assertEquals(counts + details, visiblePaneStats(counts + details, paneStatTier(width)))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun theNearestEdgeOfAStatisticsBearingStackStillShowsTheFullBlock() {
|
||||
// The defect this pins: a statistics-bearing identity's width is spent on
|
||||
// the covered region, and when a second level is covered the nearest edge
|
||||
// gives up the thin older edge (startInset + minTouch) inside that region.
|
||||
// Sizing the identity for the block alone left that nearest edge — the only
|
||||
// pipeline-scoped pane that is ever covered — below the Full boundary, so
|
||||
// its last-run and average lines were unreachable. The region must
|
||||
// therefore be sized so the nearest edge, not the identity width, clears the
|
||||
// block; the leading inset cancels, so the reserve is exactly one touch
|
||||
// target.
|
||||
val minTouch = 48.dp
|
||||
val startInset = 30.dp
|
||||
val identity = coveredIdentityWidthDp(contentWidth = 30.dp, minTouch = minTouch, withStats = true)
|
||||
val region = identity + startInset
|
||||
val edges = coveredEdgesDp(covered = 2, region = region, minTouch = minTouch, startInset = startInset)
|
||||
// The nearest (last) edge is the covered pipeline identity; the first edge
|
||||
// is inset past the left gesture area, any other is already clear of it.
|
||||
val nearest = edges.last()
|
||||
val visible = nearest.width - if (edges.size == 1) startInset else 0.dp
|
||||
assertTrue(
|
||||
"nearest statistics edge below the full block: $visible",
|
||||
visible >= MIN_COVERED_PANE_WIDTH_DP + PEEK_WIDTH_DP,
|
||||
)
|
||||
assertEquals(PaneStatTier.Full, paneStatTier(visible))
|
||||
assertEquals(counts + details, visiblePaneStats(counts + details, paneStatTier(visible)))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aTitleOnlyIdentityIsStillSizedFromItsContentAndTheTouchTarget() {
|
||||
// Without statistics the floor is the platform touch target, so a title that
|
||||
// measures wider than it is not shrunk and a short one stays tappable.
|
||||
assertEquals(48.dp, coveredIdentityWidthDp(contentWidth = 0.dp, minTouch = 48.dp, withStats = false))
|
||||
assertEquals(100.dp, coveredIdentityWidthDp(contentWidth = 84.dp, minTouch = 48.dp, withStats = false))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun theTitleWrapsAtWholeWordsAndNeverSplitsOne() {
|
||||
// The measured width is one pixel per character, so the packing is exact.
|
||||
val fitted = wholeWordTitle("Complete a Task", maxWidthPx = 10, maxLines = 3, ellipsis = "…") { it.length }
|
||||
assertEquals("Complete a\nTask", fitted)
|
||||
// A word too wide for the line starts a new line instead of being broken.
|
||||
val wrapped = wholeWordTitle("Complete a Task", maxWidthPx = 8, maxLines = 3, ellipsis = "…") { it.length }
|
||||
assertEquals("Complete\na Task", wrapped)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun theTitleEllipsizesWholeWordsWhenTheLinesAreFull() {
|
||||
val fitted = wholeWordTitle(
|
||||
"Focused tweak implement review",
|
||||
maxWidthPx = 10,
|
||||
maxLines = 2,
|
||||
ellipsis = "…",
|
||||
) { it.length }
|
||||
assertEquals("Focused\ntweak …", fitted)
|
||||
// No split word ever appears: every line boundary falls between words.
|
||||
assertFalse(fitted.contains("twea\n"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aWordWiderThanTheStripIsEllipsizedRatherThanWrapped() {
|
||||
// The one documented exception: no internal boundary exists, so it is
|
||||
// ellipsized in place (and still fits the strip) instead of wrapped.
|
||||
val fitted = wholeWordTitle("Extraordinarily", maxWidthPx = 5, maxLines = 3, ellipsis = "…") { it.length }
|
||||
assertEquals("Extr…", fitted)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aTitleWithNoRoomOrNoWordsIsEmpty() {
|
||||
assertEquals("", wholeWordTitle("Complete a Task", maxWidthPx = 0, maxLines = 3, ellipsis = "…") { it.length })
|
||||
assertEquals("", wholeWordTitle(" ", maxWidthPx = 100, maxLines = 3, ellipsis = "…") { it.length })
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user