Add a single geometry token file and a test that enforces it

Introduce ui/theme/Dimens.kt as the one source of truth for app geometry,
alongside Typography.kt for type. It defines the 4dp spacing scale
(SPACING_XXS/XS/S/M/L/XL/XXL) and receives the geometry constants that
already existed, each with a comment tying it to what it is: PEEK_WIDTH_DP
(the collapsed strip), PEEK_BUDGET_DP, MIN_ACTIVE_PANE_WIDTH_DP and
MIN_COVERED_PANE_WIDTH_DP from SlidingPaneStack.kt, DESTINATION_PILL_RESERVE
from PipelinesApp.kt, and WIDE_RAIL_WIDTH_DP and DETAIL_MAX_WIDTH_DP from
DetailTabs.kt. Call sites now import the tokens; every value is unchanged,
so no layout changes.

Add ui/theme/DimensTest.kt, a JVM test that scans the app's Kotlin sources
for raw dp/sp literals and fails with file:line:literal unless the literal
is a token or an explicit, reasoned allow-list entry. The allow-list records
the 34 literals that predate the token file, each with a written reason, and
is expected to shrink as call sites migrate onto the tokens.

Document the change and its verification in android/README.md.
This commit is contained in:
2026-10-16 11:50:26 +01:00
parent d019213c5b
commit f6b9424894
7 changed files with 337 additions and 29 deletions
@@ -64,6 +64,7 @@ import net.awan.pipelines.ui.screens.PipelineListScreen
import net.awan.pipelines.ui.screens.RunDetailScreen
import net.awan.pipelines.ui.screens.RunHistoryScreen
import net.awan.pipelines.ui.screens.SettingsScreen
import net.awan.pipelines.ui.theme.DESTINATION_PILL_RESERVE
private data class TopDestination(val route: String, val label: String, val icon: ImageVector)
@@ -450,7 +451,3 @@ internal val DESTINATION_ITEM_SIZE = 48.dp
/** The gap between destinations, also the pill's inner padding. */
internal val DESTINATION_ITEM_GAP = 4.dp
/** Bottom space reserved for the floating destination pill, so content is never
* permanently hidden behind it (pill height + its margins + a small gap). */
private val DESTINATION_PILL_RESERVE = 88.dp
@@ -45,6 +45,8 @@ import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import net.awan.pipelines.ui.theme.DETAIL_MAX_WIDTH_DP
import net.awan.pipelines.ui.theme.WIDE_RAIL_WIDTH_DP
import net.awan.pipelines.ui.theme.pipelinesText
/**
@@ -272,9 +274,3 @@ fun rememberSectionExpansion(
}
return remember(expanded) { SectionExpansionState(expanded) }
}
/** The always-visible wide section rail's width (icons with labels). */
private const val WIDE_RAIL_WIDTH_DP = 200
/** Comfortable max text width for a tab body on a wide window. */
const val DETAIL_MAX_WIDTH_DP = 840
@@ -32,26 +32,14 @@ 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
/**
* The named dimension tokens behind the pane geometry. No screen hardcodes a
* peek width or a pane width; every offset and width is derived from these, the
* measured host width and the system insets.
*
* [PEEK_WIDTH_DP] is the minimum width of one covered pane's tappable peek.
* [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.
*/
internal val PEEK_WIDTH_DP = 56.dp
internal val PEEK_BUDGET_DP = 224.dp
internal val MIN_ACTIVE_PANE_WIDTH_DP = 320.dp
internal val MIN_COVERED_PANE_WIDTH_DP = 112.dp
// 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 one slide timing every pane shares: the [MotionStandard] token, whose
@@ -0,0 +1,83 @@
package net.awan.pipelines.ui.theme
import androidx.compose.ui.unit.dp
/**
* The app's one dimension scale: the named geometry tokens every screen, pane
* and component should measure itself against instead of writing a raw `dp` or
* `sp` literal. It is the single source of truth for app geometry, the same way
* [PipelinesTypography] is the single source of truth for type.
*
* A literal is only meant to live here or in an explicit, reasoned entry of the
* allow-list in `DimensTest`; that test scans the app's Kotlin UI sources and
* fails when a raw `dp`/`sp` literal appears elsewhere without one. Values are
* unchanged from where they were moved, so introducing this file changes no
* layout on its own.
*/
// ---- Spacing scale ---------------------------------------------------------
// Every gap and padding is meant to be a multiple of the 4dp base step below:
// the existing UI already sits on 4/8/12/16/24/32, so the scale names them once
// rather than letting each call site re-derive them.
/** Half the 4dp base step; the tightest gap the UI uses (e.g. icon/label pairs). */
internal val SPACING_XXS = 2.dp
/** One step of the shared 4dp spacing scale. */
internal val SPACING_XS = 4.dp
/** Two steps of the shared 4dp spacing scale. */
internal val SPACING_S = 8.dp
/** Three steps of the shared 4dp spacing scale; the standard inline gap. */
internal val SPACING_M = 12.dp
/** Four steps of the shared 4dp spacing scale; the standard screen/card padding. */
internal val SPACING_L = 16.dp
/** Six steps of the shared 4dp spacing scale; the standard card inset. */
internal val SPACING_XL = 24.dp
/** Eight steps of the shared 4dp spacing scale; the largest padding in the UI. */
internal val SPACING_XXL = 32.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.
/** Minimum width of one covered pane's tappable peek (the collapsed strip). */
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. */
internal val MIN_COVERED_PANE_WIDTH_DP = 112.dp
// ---- Destination pill (ui/PipelinesApp.kt) ---------------------------------
/**
* Bottom space reserved by the floating destination pill, so content is never
* permanently hidden behind it (pill height + its margins + a small gap).
*/
internal val DESTINATION_PILL_RESERVE = 88.dp
// ---- Detail rail and max content width (ui/components/DetailTabs.kt) -------
/** The always-visible wide section rail's width (icons with labels). */
internal const val WIDE_RAIL_WIDTH_DP = 200
/** Comfortable max text width for a tab body on a wide window. */
const val DETAIL_MAX_WIDTH_DP = 840