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:
2026-10-16 23:30:47 +01:00
parent af68a62ab8
commit dcd58b8a3d
3 changed files with 386 additions and 18 deletions
@@ -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)
}
}