Measure the covered pane edge instead of spending a fixed budget

The covered panes spent a fixed 224dp (PEEK_BUDGET_DP) whatever the window
width, so a folded window lost over half its width and the active pane was
squeezed as levels were added. Derive the covered region at runtime from the
compact identity a covered edge must show - an icon plus the shortest label
that identifies the pane, measured with the app's own type role and floored at
the platform minimum touch target - plus the leading gesture inset.

coveredEdgesDp now returns edges that sum to exactly that region, so the active
pane opens at hostWidth - region and its width is identical at every depth:
opening a level only adds a thin edge inside the region. The nearest covered
level shows its identity, one older level is a thinner touch-target edge, and
older levels fold into a count rather than accumulating width; tapping an edge
still pops everything above it. Removes PEEK_BUDGET_DP, MIN_ACTIVE_PANE_WIDTH_DP
and the peekBudgetDp/peekStripsDp budget split from Dimens.kt and
SlidingPaneStack.kt. PaneIdentity gains the pane-kind icon drawn above the title
at the vector's own measured default size, and each destination passes its
compact label/icon.

The touched files also carry the in-flight covered-pane statistics and list-scroll
plumbing they depend on (PaneStat/paneStatTier/visiblePaneStats, per-destination
LazyListState); the remaining pieces of that work remain uncommitted.
This commit is contained in:
2026-10-16 18:50:36 +01:00
parent b003872032
commit af68a62ab8
11 changed files with 490 additions and 255 deletions
+92
View File
@@ -955,6 +955,11 @@ frames and pinch-zoom (adb cannot drive a two-finger pinch).
## Adaptive pane navigation and a fixed peek budget (15 Oct 2026)
> **Superseded** by "The covered edge is measured, not budgeted" below: the fixed
> `PEEK_BUDGET_DP` (`224.dp`) is gone. The covered region is now measured from the
> compact identity a covered edge has to show, so the active pane is no longer
> charged a fixed `224dp` whatever the window width is.
The pane stack was made adaptive to the window width and its peek space changed
from one peek per level to a single fixed budget shared between the covered
panes. `android/` only; nothing in the Pipelines server, its Go source, the
@@ -1220,6 +1225,11 @@ artifacts is a data issue in that run, not re-tested against a repaired copy.
## Covered panes show a compact identity, with a minimum peek width (16 Oct 2026)
> **Superseded** by "The covered edge is measured, not budgeted" below: the
> `MIN_COVERED_PANE_WIDTH_DP`/`PEEK_WIDTH_DP` split of a fixed budget no longer
> decides the layout. A covered edge is now as wide as the identity it has to
> show; the two tokens only bound which statistics that identity shows.
A wide-window stack no longer squeezes a full pane into each covered peek: a
covered pane now renders only its compact identity (a title and at most one
status/subtitle, centred in its strip) and its full body — tab rail, list,
@@ -3662,3 +3672,85 @@ distribution, `ANDROID_HOME=~/Library/Android/sdk`, every Gradle command with
shares the one `runListState`, so it gets the same treatment as the normally
opened runs list. A real hardware fold to the cover display was not exercised
(narrow was produced with `wm size`).
## The covered edge is measured, not budgeted (16 Oct 2026)
The covered panes used to spend the fixed `PEEK_BUDGET_DP` (`224.dp`) whatever the
window width was, so on a folded window the covered area was over half the screen
and the active pane was left with a fixed, small width. The stack now derives the
covered region from what a covered edge actually has to show and takes the active
pane's width from what remains. `android/` only; no dependency was added, no run
was started from the app, the Pipelines server/Go source/installer/Docker files
were not touched, and the operator's Pixel 10 Pro Fold was not used at all
(implementation verified with the build and the unit tests, per the brief).
- **The region is measured, not budgeted.** `rememberCompactIdentityWidth`
(`ui/components/PaneIdentity.kt`) measures the width one covered edge needs for
its compact identity — an icon plus the shortest label that identifies the pane
— at runtime, with the app's own type role and the platform's font metrics, and
floors it at the platform minimum touch target
(`LocalMinimumInteractiveComponentSize`). `SlidingPaneStack` adds the leading
system-gesture inset (`systemBars ∪ systemGestures`) and uses that as the whole
covered region. No percentage of the window, budget token or new dp constant
stands in for it; the only fixed values left are platform ones (the minimum
touch target and the leading gesture inset) plus the identity's own existing
`SPACING_S` padding and the icon's own default size.
- **The active pane's width is the same at every depth — the invariant.**
`coveredEdgesDp` (`ui/components/SlidingPaneStack.kt`) always returns edges that
sum to exactly the region, so `activeStart` is the region and the active pane
measures `hostWidth - region` at depth 1, 2, 3 and 4 alike. Opening another
level only adds an edge *inside* the region; it never widens the region or
resizes or reflows a pane already there. `SlidingPaneStackTest` asserts the sum
is constant across depths (`theCoveredRegionIsTheSameAtEveryDepthSoTheActiveWidthNeverChanges`).
- **The stack reads as a stack, and depth does not consume width.** The nearest
covered level shows its identity. One older level is shown as a thinner edge —
the platform minimum touch target, the thinnest edge that stays tappable after
the leading inset — and every level older than that folds into that edge's
count (`"<n> more"`) instead of spending width on each. When the region cannot
fit the thin older edge as well as a full touch target for the nearest identity
(one identity width is usually less than two touch targets), the older levels
fold into the nearest edge's count rather than being squeezed: nothing is
derived below the platform minimum. Tapping an edge still calls the same
`onPopTo(level)`, closing everything above it.
- **The old token and what replaced it.** `PEEK_BUDGET_DP` was `224.dp` and is
removed, together with `MIN_ACTIVE_PANE_WIDTH_DP` (`320.dp`) and the
`peekBudgetDp`/`peekStripsDp` split of a fixed budget. What replaced it is the
measured compact-identity width above. `PEEK_WIDTH_DP` (`56.dp`) and
`MIN_COVERED_PANE_WIDTH_DP` (`112.dp`) no longer place anything either: they now
only bound which statistics a covered identity shows (see
`paneStatTier`/`visiblePaneStats`) and are documented as such in `Dimens.kt`.
- **The identity carries an icon.** `PaneIdentity` gained an `icon` parameter
drawn above the title at the vector's own default size, so the drawn identity
matches the width that was measured for it. The list, pipeline-detail,
run-detail and stage panes each pass their own glyph.
Evidence (macOS, JDK 17 from Homebrew `openjdk@17`, the cached Gradle 8.11.1
distribution, `ANDROID_HOME=~/Library/Android/sdk`, `--offline`, every command
with `--no-daemon`):
- `gradle :app:testDebugUnitTest :app:assembleDebug --no-daemon --offline
--console=plain` → `BUILD SUCCESSFUL`. The result XMLs total **293 tests, 0
failures, 0 errors, 0 skipped** across 34 files. The rewritten
`SlidingPaneStackTest` pins the invariant and the fold rules: a narrow window
spends nothing, the edges sum to the region at every depth (so the active width
is constant), one covered level keeps the whole identity edge, two covered
levels show the nearest identity plus one thinner older edge, beyond two the
older levels fold into one count edge, a region too small to fit both a thin
edge and the nearest touch target collapses to a single counted edge, the
nearest edge keeps its touch target after the gesture inset, and the edges stay
monotonic and deterministic.
- `app/build/outputs/apk/debug/app-debug.apk` is 18,247,412 bytes, sha256
`77db131cdb2737da64286384e5f7387540b1c87588b89c36bf4c34821f091372`; it was
copied to `~/.local/share/pipelines/data/artifacts/166/1/pipelines-debug-wip-b003872.apk`
(`b003872` = `git rev-parse --short HEAD`; the tree is WIP on top of it).
`curl -I http://10.0.0.249:8080/artifacts/166/1/pipelines-debug-wip-b003872.apk`
returned `HTTP/1.1 200 OK`, `Content-Type: application/vnd.android.package-archive`,
`Content-Length: 18247412`.
Not verified in this pass: the derived widths on a real window, the stacked look
and the identifiers on the left, the covered area's share of the window, and the
two- and four-level screenshots — all of that is runtime/visual evidence for the
review stages, and the device policy for this brief keeps the implementation to
the build and the unit tests. Four levels are also unreachable in the app itself
(`MasterPane.List/Detail/Stage`, `MAX_PANE_DEPTH = 2`), so the four-level fold is
covered by the pure `coveredEdgesDp` cases rather than by a screenshot.
@@ -17,6 +17,7 @@ import androidx.compose.foundation.layout.only
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.windowInsetsPadding
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.selection.selectable
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
@@ -110,6 +111,13 @@ fun PipelinesApp(vm: AppViewModel) {
mutableStateOf(PaneSelection())
}
// One list scroll position each, owned here above the NavHost so it survives
// the destination (and list screen) being recreated when a pane is covered or
// the runs selection changes, as well as a configuration change and process
// death. The list screens only clamp it when the list changed underneath.
val pipelineListState = rememberSaveable(saver = LazyListState.Saver) { LazyListState() }
val runListState = rememberSaveable(saver = LazyListState.Saver) { LazyListState() }
val onNavigate: (TopDestination) -> Unit = { destination ->
if (currentRoute != destination.route) {
navController.navigate(destination.route) {
@@ -159,6 +167,7 @@ fun PipelinesApp(vm: AppViewModel) {
PipelineDestination(
vm = vm,
wide = wide,
listState = pipelineListState,
onOpenRun = { runId ->
runSelection = PaneSelection(
pane = MasterPane.Detail,
@@ -174,6 +183,7 @@ fun PipelinesApp(vm: AppViewModel) {
wide = wide,
selection = runSelection,
onSelectionChange = { runSelection = it },
listState = runListState,
)
}
composable("settings") {
@@ -203,7 +213,12 @@ fun PipelinesApp(vm: AppViewModel) {
* closes every pane to its right via [popTo].
*/
@Composable
private fun PipelineDestination(vm: AppViewModel, wide: Boolean, onOpenRun: (Long) -> Unit) {
private fun PipelineDestination(
vm: AppViewModel,
wide: Boolean,
listState: LazyListState,
onOpenRun: (Long) -> Unit,
) {
var selection by rememberSaveable(stateSaver = PaneSelectionSaver) {
mutableStateOf(PaneSelection())
}
@@ -220,6 +235,8 @@ private fun PipelineDestination(vm: AppViewModel, wide: Boolean, onOpenRun: (Lon
depth = depth,
wide = wide,
onPopTo = { level -> selection = popTo(selection, level) },
compactLabel = "Pipelines",
compactIcon = Icons.Filled.AccountTree,
backContentDescription = { level -> if (level == 0) "Back to pipelines" else "Back to pipeline" },
pane = { level, covered, paneModifier ->
when (level) {
@@ -231,6 +248,7 @@ private fun PipelineDestination(vm: AppViewModel, wide: Boolean, onOpenRun: (Lon
modifier = paneModifier,
selectedId = selection.itemId.takeIf { depth >= 1 },
covered = covered,
listState = listState,
)
1 -> rememberPaneContent(
selection.itemId.takeIf { it != 0L }?.let {
@@ -285,6 +303,7 @@ private fun RunsDestination(
wide: Boolean,
selection: PaneSelection,
onSelectionChange: (PaneSelection) -> Unit,
listState: LazyListState,
) {
val depth = selection.depth
val onBack: () -> Unit = { onSelectionChange(backFrom(selection)) }
@@ -298,6 +317,8 @@ private fun RunsDestination(
depth = depth,
wide = wide,
onPopTo = { level -> onSelectionChange(popTo(selection, level)) },
compactLabel = "Runs",
compactIcon = Icons.Filled.History,
backContentDescription = { level -> if (level == 0) "Back to runs" else "Back to run" },
pane = { level, covered, paneModifier ->
when (level) {
@@ -307,6 +328,7 @@ private fun RunsDestination(
modifier = paneModifier,
selectedRunId = selection.itemId.takeIf { depth >= 1 },
covered = covered,
listState = listState,
)
1 -> rememberPaneContent(
selection.itemId.takeIf { it != 0L }?.let { it to selection.sectionIndex },
@@ -1,40 +1,119 @@
package net.awan.pipelines.ui.components
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Icon
import androidx.compose.material3.LocalMinimumInteractiveComponentSize
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.rememberTextMeasurer
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.Dp
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 net.awan.pipelines.ui.theme.SPACING_M
import net.awan.pipelines.ui.theme.SPACING_S
import net.awan.pipelines.ui.theme.SPACING_XS
import net.awan.pipelines.ui.theme.pipelinesText
/**
* A covered pane's compact identity: its title and, when there is one, a single
* status/subtitle line, both centred in the peek strip. A covered pane renders
* this instead of its full body, so its tab rail, list, gallery and scrollable
* body are never drawn squeezed into a sliver.
* One labelled statistic a covered pane shows: its [label] (e.g. `runs`) and its
* [value] (e.g. `11`). The label always travels with its value so a reader can
* tell what the number means, and a [detail] statistic is the kind dropped first
* when the strip is too thin.
*/
data class PaneStat(
val label: String,
val value: String,
val detail: Boolean = false,
)
/**
* How much of a covered pane's statistics block fits at a given width: the title
* only ([Title]), the run counts ([Counts]) or the full block including the last
* run and the average duration ([Full]).
*/
internal enum class PaneStatTier { Title, Counts, Full }
/**
* The statistics tier for a covered strip [widthDp]: a strip narrower than one
* tappable peek ([PEEK_WIDTH_DP]) is too thin even for a labelled number, so it
* keeps the title only; a strip at least one minimum covered pane wide plus one
* peek ([MIN_COVERED_PANE_WIDTH_DP] + [PEEK_WIDTH_DP]) has room for the longest
* line (the last run's status and age), so it shows the full block. The
* boundaries reuse the named identity-tier tokens rather than new literals, and
* the decision is pure so it is unit-testable without a device.
*/
internal fun paneStatTier(widthDp: Dp): PaneStatTier = when {
widthDp < PEEK_WIDTH_DP -> PaneStatTier.Title
widthDp < MIN_COVERED_PANE_WIDTH_DP + PEEK_WIDTH_DP -> PaneStatTier.Counts
else -> PaneStatTier.Full
}
/**
* The statistics of [stats] that fit [tier]: nothing at [PaneStatTier.Title]
* (never a bare figure without its label), only the run counts at
* [PaneStatTier.Counts], and every line at [PaneStatTier.Full]. Pure, so the
* degradation rule is asserted in a unit test without composing anything.
*/
internal fun visiblePaneStats(stats: List<PaneStat>, tier: PaneStatTier): List<PaneStat> = when (tier) {
PaneStatTier.Title -> emptyList()
PaneStatTier.Counts -> stats.filterNot { it.detail }
PaneStatTier.Full -> stats
}
/**
* 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
* pane renders this instead of its full body, so its tab rail, list, gallery and
* scrollable body are never drawn squeezed into a sliver.
*
* 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.
* 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.
*/
@Composable
fun PaneIdentity(title: String, subtitle: String? = null, modifier: Modifier = Modifier) {
fun PaneIdentity(
title: String,
subtitle: String? = null,
stats: List<PaneStat> = emptyList(),
icon: ImageVector? = null,
modifier: Modifier = Modifier,
) {
val text = pipelinesText()
Box(modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
// 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))
Column(
modifier = Modifier.padding(horizontal = SPACING_S, vertical = SPACING_M),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(SPACING_XS),
) {
if (icon != null) {
// Drawn at the vector's own default size, which is exactly what
// [rememberCompactIdentityWidth] measures, so the measured width
// and the drawn identity agree without a new size token.
Icon(imageVector = icon, contentDescription = null)
}
Text(
text = title,
style = text.cardTitle,
@@ -51,6 +130,64 @@ fun PaneIdentity(title: String, subtitle: String? = null, modifier: Modifier = M
overflow = TextOverflow.Ellipsis,
)
}
if (shown.isNotEmpty()) {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(SPACING_S),
) {
shown.forEach { stat ->
// Each statistic is its own label above its value, so the
// number is on a line wide enough for it and never shares a
// line with a label that could push it into an ellipsis.
Column(horizontalAlignment = Alignment.CenterHorizontally) {
Text(
text = stat.label,
style = text.meta,
textAlign = TextAlign.Center,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
)
Text(
text = stat.value,
style = text.label,
textAlign = TextAlign.Center,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
)
}
}
}
}
}
}
}
/**
* The width one covered edge must have to show its compact identity: the wider of
* 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.
*/
@Composable
internal fun rememberCompactIdentityWidth(label: String, icon: ImageVector? = null): Dp {
val measurer = rememberTextMeasurer()
val text = pipelinesText()
val density = LocalDensity.current
val minTouch = LocalMinimumInteractiveComponentSize.current
return remember(measurer, label, icon, text, density, minTouch) {
val labelWidth = with(density) {
measurer.measure(
text = AnnotatedString(label),
style = text.cardTitle,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
).size.width.toDp()
}
val content = maxOf(labelWidth, icon?.defaultWidth ?: 0.dp)
maxOf(content + SPACING_S * 2, minTouch)
}
}
@@ -11,16 +11,19 @@ import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.safeDrawing
import androidx.compose.foundation.layout.systemGestures
import androidx.compose.foundation.layout.union
import androidx.compose.foundation.layout.width
import androidx.compose.material3.LocalMinimumInteractiveComponentSize
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.input.pointer.PointerEventPass
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.platform.LocalLayoutDirection
@@ -32,14 +35,15 @@ import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import net.awan.pipelines.ui.MAX_PANE_DEPTH
import net.awan.pipelines.ui.theme.MIN_ACTIVE_PANE_WIDTH_DP
import net.awan.pipelines.ui.theme.MIN_COVERED_PANE_WIDTH_DP
import net.awan.pipelines.ui.theme.PEEK_BUDGET_DP
import net.awan.pipelines.ui.theme.PEEK_WIDTH_DP
import net.awan.pipelines.ui.theme.SPACING_XS
import net.awan.pipelines.ui.theme.pipelinesText
// The pane geometry tokens (peek width/budget and the minimum active/covered
// pane widths) live in ui/theme/Dimens.kt, the single source of truth for app
// geometry; this file only derives offsets and widths from them.
// The covered region's width is not a token: it is measured from the compact
// identity a covered pane actually has to show (an icon plus the shortest label
// that identifies it) plus the leading gesture inset, so no screen or constant
// decides how much of a folded window the stack spends. The only fixed values
// left are platform ones: the minimum touch target that keeps an edge tappable
// and the leading system gesture inset this file already reads from the window.
/**
* The one slide timing every pane shares: the [MotionStandard] token, whose
@@ -74,87 +78,73 @@ internal fun paneSlideDelayMillis(level: Int, depth: Int, previousDepth: Int): I
internal fun paneSlideSpec(level: Int, depth: Int, previousDepth: Int): TweenSpec<Dp> =
MotionStandard.spec(delayMillis = paneSlideDelayMillis(level, depth, previousDepth))
/**
* The peek budget actually spent on a wide window: the fixed [PEEK_BUDGET_DP]
* token, reduced only when that would leave the active pane narrower than
* [MIN_ACTIVE_PANE_WIDTH_DP] on a small host. The budget never depends on the
* stack depth, so the active pane keeps a constant width as levels are added.
* Pure so the budget is unit-testable without a device.
*/
internal fun peekBudgetDp(hostWidth: Dp, requested: Dp = PEEK_BUDGET_DP): Dp =
requested.coerceAtMost((hostWidth - MIN_ACTIVE_PANE_WIDTH_DP).coerceAtLeast(0.dp))
/**
* The width of the pane whose open left edge is [offset] on a wide window: from
* that offset to the host's right edge. The active pane therefore measures
* `hostWidth - budget`; a narrow host can never yield a negative width.
* that offset to the host's right edge. The active pane therefore measures the
* host less the covered region; a narrow host can never yield a negative width.
*/
internal fun paneWidthDp(hostWidth: Dp, offset: Dp): Dp =
maxOf(0.dp, hostWidth - offset)
/**
* One covered strip of a wide-window stack, in left-to-right order. [level] is
* the pane whose compact identity it shows; a [folded] count greater than one
* marks a strip that stands in for that many older levels (one edge indicator
* with a count) instead of a single pane, so no covered pane is squeezed below
* the named minimum width.
* One covered pane's visible edge in a wide stack's covered region, in
* left-to-right order. [level] is the pane whose compact identity the edge shows
* (for a folded edge, the newest of the levels it stands in for). [folded] is the
* number of *additional* older levels that edge represents, so those levels
* collapse into its count instead of spending width on each of them.
*/
internal data class PeekStrip(
internal data class PaneEdge(
val level: Int,
val start: Dp,
val width: Dp,
val folded: Int = 1,
val folded: Int = 0,
)
/**
* The covered strips of a wide stack for [covered] covered levels and the fixed
* [budget]. Every shown pane keeps at least `minCovered`; the leftmost strip is
* widened first so that after [startInset] it still leaves [minPeek] tappable,
* and the rest of the budget is then split evenly between the other strips.
* The covered edges of a wide stack for [covered] covered levels, laid out inside
* the one covered region [region]. The region is derived from the measured
* compact-identity width (see [rememberCompactIdentityWidth]) plus the leading
* gesture inset [startInset], and is **the same at every depth**: the nearest
* covered level keeps the whole region less, at most, one thinner edge. The active
* pane's left edge — and therefore its width — is the region, so it never changes
* as levels are added. That is the invariant: opening another level only ever adds
* its own thin edge inside the region, never widens the region.
*
* When [covered] levels cannot each get `minCovered` out of [budget], one strip
* (the leftmost) is reserved as an edge indicator folding the oldest levels into
* a single count, and only the newest levels keep their own peek: the number of
* peeks shown shrinks rather than the width of each. The active pane's left edge
* is therefore still exactly the budget. Pure, so the shared-budget geometry and
* the fold rule need no device; an empty list means nothing is covered.
* The nearest covered level always shows its identity. One older level is shown
* as a thinner edge — the platform minimum touch target [minTouch], the thinnest
* an edge may be and stay tappable after [startInset] — and every level older than
* that collapses into that edge's [PaneEdge.folded] count rather than
* accumulating width. When the region cannot fit that thinner edge as well as a
* full [minTouch] identity, nothing is squeezed below the touch target: the older
* levels fold into the nearest edge's count instead. Pure, so the invariant, the
* thin edge and the fold rule need no device; an empty list means nothing is
* covered.
*/
internal fun peekStripsDp(
internal fun coveredEdgesDp(
covered: Int,
budget: Dp,
region: Dp,
minTouch: Dp,
startInset: Dp,
minPeek: Dp,
minCovered: Dp = MIN_COVERED_PANE_WIDTH_DP,
): List<PeekStrip> {
if (covered <= 0 || budget <= 0.dp) return emptyList()
// How many covered panes the budget can show at the minimum width. When some
// levels have to fold, one of those slots is spent on the edge indicator.
val capacity = if (minCovered > 0.dp) (budget.value / minCovered.value).toInt() else covered
val fold = covered > capacity
val shown = if (fold) (capacity - 1).coerceAtLeast(0) else covered
val folded = covered - shown
val slots = shown + if (fold) 1 else 0
val first = minOf(budget, maxOf(budget / slots, startInset + minPeek))
val rest = budget - first
val steps = slots - 1
val starts = ArrayList<Dp>(slots + 1)
starts += 0.dp
starts += first
for (i in 1 until slots) {
starts += first + rest * i / steps
): List<PaneEdge> {
if (covered <= 0 || region <= 0.dp) return emptyList()
val nearest = covered - 1
if (covered == 1) return listOf(PaneEdge(nearest, 0.dp, region))
// The thinner older edge keeps one touch target after the leading inset; the
// nearest identity needs one too, or the older levels fold into its count.
val older = startInset + minTouch
return if (region >= older + minTouch) {
listOf(
PaneEdge(
level = (covered - 2).coerceAtLeast(0),
start = 0.dp,
width = older,
folded = (covered - 2).coerceAtLeast(0),
),
PaneEdge(nearest, older, region - older),
)
} else {
listOf(PaneEdge(nearest, 0.dp, region, folded = covered - 1))
}
val strips = ArrayList<PeekStrip>(slots)
var slot = 0
if (fold) {
strips += PeekStrip(folded - 1, starts[0], starts[1] - starts[0], folded = folded)
slot = 1
}
for (i in 0 until shown) {
val level = folded + i
val s = slot + i
strips += PeekStrip(level, starts[s], starts[s + 1] - starts[s])
}
return strips
}
/**
@@ -180,18 +170,21 @@ internal fun paneSafeArea(): WindowInsets = WindowInsets.safeDrawing
*
* On a **narrow** window ([wide] false) it is not a stack at all: there is no
* peek and no leftover strip, and each opened pane is a full-window screen that
* slides in over the last. On a **wide** window ([wide] true) the panes stack,
* but the space spent on the covered panes is a single fixed budget shared
* between them: the active pane's left edge is always exactly the budget, so it
* keeps a constant width and the stack never consumes more than the budget
* however deep it gets.
* slides in over the last. On a **wide** window ([wide] true) the panes stack:
* the covered panes sit under the active one, each showing its left edge, and the
* covered region's width is not a constant but is measured from the compact
* identity a covered edge has to show ([compactLabel], see
* [rememberCompactIdentityWidth]) plus the leading gesture inset. The active
* pane's left edge is always exactly that region, so its width is the same at
* every depth: opening another level only adds its own thin edge inside the
* region and never resizes the panes already there.
*
* A covered pane shows a compact identity only (its pane composable is told
* [covered] and is expected to render just a title/status), constrained to the
* visible strip, so its full body is never drawn into a sliver. When the budget
* cannot give every covered pane the named minimum width, the oldest levels
* fold into a single edge indicator carrying their count rather than being
* squeezed.
* visible edge, so its full body is never drawn into a sliver. The nearest
* covered level shows its identity; one older level is a thinner edge and every
* older level than that folds into that edge's count ([coveredEdgesDp]), so no
* level is ever squeezed below the platform minimum touch target.
*
* [depth] is the number of visible panes minus one (0..[MAX_PANE_DEPTH]);
* [pane] composes the level's content. The stack mounts a level while it is open
@@ -211,13 +204,15 @@ internal fun paneSafeArea(): WindowInsets = WindowInsets.safeDrawing
* are retargeted in reverse, and several levels closing in one tap reverse in
* order. A covered pane is hidden from accessibility and made non-interactive so
* TalkBack focus follows the top pane and a tap can never leak through to a
* covered one; on a wide window only its peek strip stays tappable.
* covered one; on a wide window only its edge stays tappable.
*/
@Composable
fun SlidingPaneStack(
depth: Int,
wide: Boolean,
onPopTo: (Int) -> Unit,
compactLabel: String,
compactIcon: ImageVector? = null,
modifier: Modifier = Modifier,
backContentDescription: (Int) -> String = { "Back" },
pane: @Composable (level: Int, covered: Boolean, modifier: Modifier) -> Unit,
@@ -236,48 +231,27 @@ fun SlidingPaneStack(
// The strip/compact identity area: the host clear of the top/bottom insets.
val stripHeight = maxOf(0.dp, maxHeight - topInset - bottomInset)
// Narrow: no peek at all (budget 0, every pane fills the host). Wide: one
// fixed budget shared between the covered panes, folded when it cannot
// give each the named minimum. The platform's minimum interactive size is
// the floor for a tappable strip, never a literal.
val minPeek = maxOf(PEEK_WIDTH_DP, LocalMinimumInteractiveComponentSize.current)
val budget = if (wide) peekBudgetDp(hostWidth) else 0.dp
val strips = peekStripsDp(depth, budget, startInset, minPeek)
val stripByLevel = strips.associateBy { it.level }
val folded = strips.firstOrNull()?.takeIf { it.folded > 1 }?.folded ?: 0
// The active pane always opens at the whole budget (or 0 when narrow).
val activeStart = strips.fold(0.dp) { acc, strip -> acc + strip.width }
// Narrow: no peek at all, so every pane fills the host and the covered
// region is empty. Wide: the region is one measured compact identity plus
// the leading gesture inset; it is the same at every depth, so the active
// pane's width never depends on how deep the stack is. The platform's
// minimum interactive size is the floor for each tappable edge, never a
// literal.
val minTouch = LocalMinimumInteractiveComponentSize.current
val identityWidth = rememberCompactIdentityWidth(compactLabel, compactIcon)
val region = if (wide) identityWidth + startInset else 0.dp
val edges = coveredEdgesDp(depth, region, minTouch, startInset)
val edgeByLevel = edges.associateBy { it.level }
val shownCovered = edges.map { it.level }.toSet()
// The active pane always opens at exactly the covered region's width (0
// when nothing is covered or the window is narrow, so it fills the host).
val activeStart = edges.fold(0.dp) { acc, edge -> acc + edge.width }
// The depth just before the current one, so a pop knows how many levels
// were open (to stagger their reversal). Held stable for a given depth so
// the slide spec never changes part-way through a slide.
val depthTrack = remember { PaneDepthTrack(depth) }
val closingFrom = remember(depth) { depthTrack.previous.also { depthTrack.previous = depth } }
// The folded older levels as one edge indicator with a count, clear of the
// status/nav bars and of the left gesture area; tapping it jumps back to
// the newest folded level.
if (folded > 0) {
val strip = strips.first()
Box(
Modifier
.align(Alignment.TopStart)
.offset(x = startInset, y = topInset)
.width(maxOf(0.dp, strip.width - startInset))
.height(stripHeight)
.clickable(
role = Role.Button,
onClickLabel = backContentDescription(folded - 1),
onClick = { onPopTo(folded - 1) },
)
.semantics {
contentDescription = backContentDescription(folded - 1)
role = Role.Button
},
) {
PaneIdentity("$folded more", null, Modifier.fillMaxSize())
}
}
// Panes 0..MAX are always given their own long-lived animator, in order,
// even while closed, so a retarget slides rather than jumps and the
// animator stays warm; a level beyond the depth waits exactly off the
@@ -285,20 +259,22 @@ fun SlidingPaneStack(
// exact time-reverse of opening.
for (level in 0..MAX_PANE_DEPTH) {
val covered = level < depth
// A level folded into the edge indicator is not drawn on its own.
if (covered && level < folded) continue
val strip = if (covered) stripByLevel[level] else null
// A level folded into an older edge's count is not drawn on its own.
// A narrow window has no edges at all, so every covered level keeps
// composing its full body under the active one, as before.
if (covered && edges.isNotEmpty() && level !in shownCovered) continue
val edge = if (covered) edgeByLevel[level] else null
// An open pane sits at its shared-budget offset; a closed one waits
// exactly off the right edge. Its width is already the width it will
// have when open, so it slides rather than grows.
// An open pane sits at its edge's offset; a closed one waits exactly
// off the right edge. Its width is already the width it will have when
// open, so it slides rather than grows.
val openOffset = when {
level > depth -> hostWidth
level == depth -> activeStart
strip != null -> strip.start
edge != null -> edge.start
else -> 0.dp
}
val openWidth = paneWidthDp(hostWidth, if (level <= depth) openOffset else budget)
val openWidth = paneWidthDp(hostWidth, if (level <= depth) openOffset else region)
val offset by animateDpAsState(
targetValue = openOffset,
animationSpec = paneSlideSpec(level, depth, closingFrom),
@@ -318,20 +294,30 @@ fun SlidingPaneStack(
.fillMaxHeight()
.then(if (level < depth) Modifier.blockPointerInput() else Modifier),
) {
if (strip != null) {
// Constrain the compact identity to the visible strip so it
// is centred in the space the covered pane actually has. It
// rides with the pane's own offset and slides in so it also
// slides back out with it.
val stripInset = if (level == 0) startInset else 0.dp
if (edge != null) {
// Constrain the compact identity to the visible edge so it
// is centred in the space the covered pane actually has, and
// carry this level's share of the folded older levels as a
// count. It rides with the pane's own offset and slides in so
// it also slides back out with it.
val edgeInset = if (edge === edges.first()) startInset else 0.dp
Box(
Modifier
.align(Alignment.TopStart)
.offset(x = stripInset, y = topInset)
.width(maxOf(0.dp, strip.width - stripInset))
.offset(x = edgeInset, y = topInset)
.width(maxOf(0.dp, edge.width - edgeInset))
.height(stripHeight),
) {
pane(level, true, Modifier.fillMaxSize())
if (edge.folded > 0) {
Text(
text = "${edge.folded} more",
style = pipelinesText().meta,
modifier = Modifier
.align(Alignment.TopEnd)
.padding(SPACING_XS),
)
}
}
} else {
pane(level, false, Modifier.fillMaxSize())
@@ -339,26 +325,26 @@ fun SlidingPaneStack(
}
}
// The covered pane's tappable peek (wide windows only): the strip
// The covered pane's tappable edge (wide windows only): the edge
// between this pane's offset and the next pane's, clear of the
// status/nav bars and of the left gesture area. It sits above the
// pane's compact identity so tapping it closes every pane to its
// right; it never overlaps the next pane.
if (strip != null) {
val stripInset = if (level == 0) startInset else 0.dp
if (edge != null) {
val edgeInset = if (edge === edges.first()) startInset else 0.dp
Box(
Modifier
.align(Alignment.TopStart)
.offset(x = strip.start + stripInset, y = topInset)
.width(maxOf(0.dp, strip.width - stripInset))
.offset(x = edge.start + edgeInset, y = topInset)
.width(maxOf(0.dp, edge.width - edgeInset))
.height(stripHeight)
.clickable(
role = Role.Button,
onClickLabel = backContentDescription(level),
onClick = { onPopTo(level) },
onClickLabel = backContentDescription(edge.level),
onClick = { onPopTo(edge.level) },
)
.semantics {
contentDescription = backContentDescription(level)
contentDescription = backContentDescription(edge.level)
role = Role.Button
},
)
@@ -12,6 +12,7 @@ import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material.icons.filled.Hub
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
@@ -334,6 +335,7 @@ fun StageDetailPane(
PaneIdentity(
title = GraphSemantics.nodeLabel(stageKey),
subtitle = if (stage != null) effectiveStageType(stage.type) else "terminal",
icon = Icons.Filled.Hub,
modifier = modifier.fillMaxSize(),
)
return
@@ -15,6 +15,7 @@ import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material.icons.filled.AccountTree
import androidx.compose.material.icons.filled.ContentCopy
import androidx.compose.material.icons.filled.PlayArrow
import androidx.compose.material.icons.filled.Refresh
@@ -42,6 +43,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalClipboardManager
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import java.time.OffsetDateTime
import net.awan.pipelines.data.ErrorMessages
import net.awan.pipelines.data.protocol.PipelineDetail
import net.awan.pipelines.data.protocol.VersionSummary
@@ -89,6 +91,7 @@ fun PipelineDetailScreen(
covered: Boolean = false,
) {
val state by vm.pipelineDetail.collectAsStateWithLifecycle()
val runsState by vm.runs.collectAsStateWithLifecycle()
var showStart by remember { mutableStateOf(false) }
LaunchedEffect(pipelineId, version) { vm.loadPipeline(pipelineId, version) }
@@ -101,11 +104,18 @@ fun PipelineDetailScreen(
val shownDetail = rememberPaneContent(detail)
// A covered pane shows its compact identity only; the tab rail and section
// body must never be drawn squeezed into the peek strip.
// body must never be drawn squeezed into the peek strip. When the run history
// is in hand the identity carries this pipeline's statistics (run counts, the
// last run and the average duration) instead of a bare version/stage line.
if (covered) {
val now = remember { OffsetDateTime.now() }
val stats = remember(runsState.data, pipelineId, now) {
pipelineStatLines(runsState.data?.runs, pipelineId, now)
}
PaneIdentity(
title = detail?.name ?: "Pipeline",
subtitle = detail?.let { "v$version · ${it.graph.stages.size} stages" },
stats = stats,
icon = Icons.Filled.AccountTree,
modifier = modifier.fillMaxSize(),
)
return
@@ -116,6 +116,7 @@ fun PipelineListScreen(
PaneIdentity(
title = "Pipelines",
stats = stats,
icon = Icons.Filled.AccountTree,
modifier = modifier.fillMaxSize(),
)
return
@@ -16,6 +16,7 @@ import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material.icons.automirrored.filled.DirectionsRun
import androidx.compose.material.icons.filled.AttachFile
import androidx.compose.material.icons.filled.Cancel
import androidx.compose.material.icons.filled.Refresh
@@ -173,6 +174,7 @@ fun RunDetailScreen(
PaneIdentity(
title = run?.name ?: "Run",
stats = stats,
icon = Icons.AutoMirrored.Filled.DirectionsRun,
modifier = modifier.fillMaxSize(),
)
return
@@ -18,6 +18,7 @@ import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.List
import androidx.compose.material.icons.filled.Refresh
import androidx.compose.material3.Card
import androidx.compose.material3.CircularProgressIndicator
@@ -130,6 +131,7 @@ fun RunHistoryScreen(
PaneIdentity(
title = if (filterPipelineId == null) "Runs" else "Runs for this pipeline",
stats = stats,
icon = Icons.AutoMirrored.Filled.List,
modifier = modifier.fillMaxSize(),
)
return
@@ -58,29 +58,19 @@ internal val ICON_LIST_DP = 20.dp
/** Wide detail-rail tab glyph size. */
internal val ICON_RAIL_DP = 24.dp
// ---- Pane geometry (ui/components/SlidingPaneStack.kt) ---------------------
// The sliding pane stack derives every offset and width from these plus the
// measured host width and the system insets; no screen hardcodes a peek or pane
// width. [PEEK_WIDTH_DP] is the minimum width of one covered pane's tappable
// peek (the "collapsed strip"). [PEEK_BUDGET_DP] is the fixed *total* peek
// budget a wide window may spend on all covered panes together, however deep the
// stack gets. [MIN_ACTIVE_PANE_WIDTH_DP] is the least width worth leaving to the
// active (topmost) pane before the budget has to be reduced.
// [MIN_COVERED_PANE_WIDTH_DP] is the least width a covered pane's compact
// identity needs to stay readable and tappable; when the budget cannot give
// every covered pane this much, the oldest levels are folded into one edge
// indicator instead of being squeezed below it.
// ---- Covered-pane identity tiers (ui/components/PaneIdentity.kt) -----------
// The sliding pane stack no longer derives its width from a token: the covered
// region is measured from the compact identity a covered edge must show (see
// `rememberCompactIdentityWidth`), so there is no fixed peek budget and the
// active pane's width does not depend on the stack's depth. What remains here
// only bounds the *statistics* a covered identity shows once it is drawn: a
// strip narrower than one peek keeps the title alone, and a strip at least one
// minimum covered pane plus one peek wide has room for the full block.
/** Minimum width of one covered pane's tappable peek (the collapsed strip). */
/** Least width a covered identity needs before it shows labelled statistics. */
internal val PEEK_WIDTH_DP = 56.dp
/** Fixed total peek budget a wide window may spend on all covered panes. */
internal val PEEK_BUDGET_DP = 224.dp
/** Least width left to the active (topmost) pane before the budget is reduced. */
internal val MIN_ACTIVE_PANE_WIDTH_DP = 320.dp
/** Least width a covered pane's compact identity needs to stay usable. */
/** Width beyond which a covered identity has room for its full statistics. */
internal val MIN_COVERED_PANE_WIDTH_DP = 112.dp
// ---- Destination pill (ui/PipelinesApp.kt) ---------------------------------
@@ -2,128 +2,119 @@ package net.awan.pipelines.ui.components
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import net.awan.pipelines.ui.theme.MIN_ACTIVE_PANE_WIDTH_DP
import net.awan.pipelines.ui.theme.MIN_COVERED_PANE_WIDTH_DP
import net.awan.pipelines.ui.theme.PEEK_BUDGET_DP
import net.awan.pipelines.ui.theme.PEEK_WIDTH_DP
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
/**
* The pane geometry is pure, so the adaptive width and fold rules are checked
* here without a device: a narrow window spends no peek at all, a wide window
* spends one fixed budget shared between the covered panes however deep the
* stack gets, every shown peek keeps the named minimum covered width, and when
* the budget cannot give the whole stack that much the oldest levels fold into a
* single edge indicator rather than being squeezed.
* The pane geometry is pure, so the width invariant and the fold rules are
* checked here without a device: a narrow window spends no covered region at any
* depth, the covered region — and therefore the active pane's width — is the same
* at every depth, the nearest covered level keeps its identity edge, one older
* level is a thinner edge, and levels older than that fold into that edge's count
* rather than accumulating width. When the region cannot fit both a touch target
* for the thin edge and one for the nearest identity, the older levels fold into
* the nearest edge instead of being squeezed below the platform minimum.
*/
class SlidingPaneStackTest {
private fun assertDp(expected: Dp, actual: Dp, delta: Float = 0.01f) =
assertEquals(expected.value, actual.value, delta)
private fun totalWidth(strips: List<PeekStrip>): Dp =
strips.fold(0.dp) { acc, strip -> acc + strip.width }
private val minTouch = 48.dp
private fun totalWidth(edges: List<PaneEdge>): Dp =
edges.fold(0.dp) { acc, edge -> acc + edge.width }
@Test
fun narrowWindowSpendsNoPeekAtAnyDepth() {
// Budget 0 is the narrow model: no stack and no leftover strip, so there
// are no covered strips and every pane opens at the host's left edge.
fun narrowWindowSpendsNothingAtAnyDepth() {
// A region of 0 is the narrow model: no covered strip, so every pane opens
// at the host's left edge.
for (covered in 0..4) {
assertTrue(peekStripsDp(covered, 0.dp, 30.dp, PEEK_WIDTH_DP).isEmpty())
assertTrue(coveredEdgesDp(covered, 0.dp, minTouch, 30.dp).isEmpty())
}
}
@Test
fun wideActivePaneKeepsAConstantWidthAtEveryDepth() {
fun theCoveredRegionIsTheSameAtEveryDepthSoTheActiveWidthNeverChanges() {
val host = 800.dp
val budget = peekBudgetDp(host)
assertDp(PEEK_BUDGET_DP, budget)
// The covered strips always sum to exactly the budget, so the active
// (topmost) pane's left edge — and its width — never depend on depth.
for (covered in 1..4) {
val strips = peekStripsDp(covered, budget, startInset = 0.dp, minPeek = PEEK_WIDTH_DP)
assertDp(budget, totalWidth(strips))
assertDp(host - budget, paneWidthDp(host, totalWidth(strips)))
val region = 200.dp
// The edges always sum to exactly the region, so the active (topmost)
// pane's left edge — and its width — never depend on depth. That is the
// invariant: opening another level only adds an edge inside the region.
for (covered in 1..6) {
val edges = coveredEdgesDp(covered, region, minTouch, startInset = 30.dp)
assertDp(region, totalWidth(edges))
assertDp(host - region, paneWidthDp(host, totalWidth(edges)))
}
}
@Test
fun twoCoveredLevelsEachKeepTheMinimumCoveredWidth() {
val strips = peekStripsDp(2, PEEK_BUDGET_DP, startInset = 0.dp, minPeek = PEEK_WIDTH_DP)
// Three levels (list + detail + stage): two covered panes, no fold, and
// each has at least the named minimum so its compact identity reads.
assertEquals(2, strips.size)
assertEquals(listOf(0, 1), strips.map { it.level })
strips.forEach { assertTrue("peek below the minimum: $it", it.width >= MIN_COVERED_PANE_WIDTH_DP) }
assertTrue(strips.all { it.folded == 1 })
fun oneCoveredLevelKeepsTheWholeIdentityEdge() {
val edges = coveredEdgesDp(1, 200.dp, minTouch, startInset = 30.dp)
assertEquals(1, edges.size)
assertEquals(0, edges.first().level)
assertDp(200.dp, edges.first().width)
assertEquals(0, edges.first().folded)
}
@Test
fun aFourthLevelFoldsTheOldestIntoOneIndicator() {
// Four levels (three covered) with a budget of two minimums: the oldest
// levels collapse into one edge indicator carrying their count instead of
// squeezing all three, and one peek still shows the newest covered pane.
val strips = peekStripsDp(3, PEEK_BUDGET_DP, startInset = 0.dp, minPeek = PEEK_WIDTH_DP)
assertEquals(2, strips.size)
assertEquals(2, strips.first().folded)
assertEquals(1, strips.last().folded)
assertEquals(2, strips.last().level)
assertTrue(strips.all { it.width >= MIN_COVERED_PANE_WIDTH_DP })
assertDp(PEEK_BUDGET_DP, totalWidth(strips))
fun twoCoveredLevelsShowTheNearestIdentityAndOneThinnerOlderEdge() {
val edges = coveredEdgesDp(2, 200.dp, minTouch, startInset = 30.dp)
assertEquals(2, edges.size)
// The older level (0) is the thinner edge — one touch target after the
// leading gesture inset; the nearest level (1) keeps its identity and a
// full touch target of its own.
assertEquals(listOf(0, 1), edges.map { it.level })
assertDp(30.dp + minTouch, edges.first().width)
assertTrue("nearest identity below the touch target: $edges", edges.last().width >= minTouch)
assertEquals(0, edges.last().folded)
}
@Test
fun foldedLevelsAreTheOldestAndTheNewestStillPeeks() {
val covered = 4
val strips = peekStripsDp(covered, PEEK_BUDGET_DP, startInset = 0.dp, minPeek = PEEK_WIDTH_DP)
// The newest covered level keeps its own peek; all older ones fold.
assertEquals(covered - 1, strips.last().level)
assertEquals(3, strips.first().folded)
fun beyondTwoCoveredLevelsTheOlderOnesFoldIntoOneCountEdge() {
val edges = coveredEdgesDp(4, 260.dp, minTouch, startInset = 30.dp)
assertEquals(2, edges.size)
// Levels 0..2 collapse into the single older edge (showing its newest,
// level 2) carrying their count; the nearest level (3) keeps its identity.
assertEquals(listOf(2, 3), edges.map { it.level })
assertEquals(2, edges.first().folded)
assertEquals(0, edges.last().folded)
assertDp(260.dp, totalWidth(edges))
}
@Test
fun firstStripStaysTappableAfterTheGestureInset() {
val startInset = 30.dp
val strips = peekStripsDp(2, PEEK_BUDGET_DP, startInset, PEEK_WIDTH_DP)
// The leftmost strip is widened so the tappable part (after the inset)
// still measures at least the named minimum.
assertTrue(strips.first().width - startInset >= PEEK_WIDTH_DP)
// Even when the fold forces the smallest split, the widening holds.
val folded = peekStripsDp(4, PEEK_BUDGET_DP, 80.dp, PEEK_WIDTH_DP)
assertTrue(folded.first().width - 80.dp >= PEEK_WIDTH_DP)
fun whenThereIsNoRoomTheOlderLevelsFoldIntoTheNearestCount() {
// A region that cannot give the thin older edge and the nearest identity a
// touch target each collapses to a single edge carrying the count: nothing
// is squeezed below the platform minimum touch target.
val edges = coveredEdgesDp(3, 100.dp, minTouch, startInset = 30.dp)
assertEquals(1, edges.size)
assertEquals(2, edges.first().level)
assertEquals(2, edges.first().folded)
assertDp(100.dp, edges.first().width)
}
@Test
fun budgetShrinksSoTheActivePaneNeverCollapses() {
// A host narrower than the ideal leaves room for: the budget is clamped
// so the active pane keeps at least the named minimum width.
val host = 400.dp
val budget = peekBudgetDp(host)
assertTrue(budget >= 0.dp)
assertTrue(paneWidthDp(host, budget) >= MIN_ACTIVE_PANE_WIDTH_DP)
fun theNearestEdgeKeepsATouchTargetAfterTheGestureInset() {
val startInset = 40.dp
val region = 260.dp
for (covered in 1..5) {
val edges = coveredEdgesDp(covered, region, minTouch, startInset)
val nearest = edges.last()
// The first edge is inset past the left gesture area; any other edge
// is already clear of it.
val inset = if (edges.size == 1) startInset else 0.dp
assertTrue("nearest edge below the touch target: $edges", nearest.width - inset >= minTouch)
}
}
@Test
fun tinyHostNeverProducesNegativeGeometry() {
assertDp(0.dp, peekBudgetDp(100.dp))
val empty = peekStripsDp(3, peekBudgetDp(100.dp), 0.dp, PEEK_WIDTH_DP)
assertTrue(empty.isEmpty())
assertTrue(paneWidthDp(100.dp, 0.dp) >= 0.dp)
// A tiny non-zero budget still yields one usable strip, never negative.
val tiny = peekStripsDp(3, 40.dp, 0.dp, PEEK_WIDTH_DP)
assertEquals(1, tiny.size)
assertTrue(tiny.first().width >= 0.dp)
assertTrue(paneWidthDp(100.dp, totalWidth(tiny)) >= 0.dp)
}
@Test
fun stripsAreMonotonicAndDeterministic() {
// Same inputs give the same strips (opening and closing are mirrors),
// the strips never overlap, and they never run past the budget.
val a = peekStripsDp(3, PEEK_BUDGET_DP, 30.dp, PEEK_WIDTH_DP)
val b = peekStripsDp(3, PEEK_BUDGET_DP, 30.dp, PEEK_WIDTH_DP)
fun edgesAreMonotonicAndDeterministic() {
// Same inputs give the same edges (opening and closing are mirrors), the
// edges never overlap, and they never run past the region.
val a = coveredEdgesDp(4, 260.dp, minTouch, 30.dp)
val b = coveredEdgesDp(4, 260.dp, minTouch, 30.dp)
assertEquals(a, b)
a.zipWithNext { x, y -> assertTrue(y.start >= x.start + x.width) }
assertTrue(a.all { it.width >= 0.dp })