Extract naturalCardBaseDp and scaledDensity helpers so tests bind to real code

resolvedCardHeight previously routed through a two-branch if(isWide)
hidden inside the composable extension, so the regression tests for
the global-slider reach bug only exercised the inner resolveCardHeight
(which was never broken). Lift the aspect -> natural base mapping
into a pure naturalCardBaseDp(AspectRatio) function with an exhaustive
when, and test that directly. SQUARE and FOUR_THREE rows piggyback on
the TALL global by design; the override branch still handles their
absolute heightDp values (Music presets at 100dp, etc.).

MainContent and DisplaySizePage's preview now both call a single
scaledDensity(base, percent) helper instead of inlining Density(...)
constructions. The double-fontScale-multiply regression has a real
guard now: tests assert scaledDensity(2.0, 1.0, 150) returns density
3.0 and fontScale 1.0 (not 1.5), and a third test confirms an
accessibility fontScale survives a UI scale change.

Pure refactor + test sharpening; no behaviour change.
This commit is contained in:
Justin Visser 2026-05-26 15:11:30 +02:00
parent 71e74949b7
commit 0b61007b3f
4 changed files with 75 additions and 35 deletions

View file

@ -19,7 +19,6 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.dp
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.compose.LifecycleEventEffect
@ -41,6 +40,7 @@ import com.github.damontecres.wholphin.ui.setup.SwitchServerContent
import com.github.damontecres.wholphin.ui.setup.SwitchUserContent
import com.github.damontecres.wholphin.ui.util.InterfaceCustomization
import com.github.damontecres.wholphin.ui.util.LocalInterfaceCustomization
import com.github.damontecres.wholphin.ui.util.scaledDensity
@Composable
fun MainContent(
@ -63,17 +63,13 @@ fun MainContent(
val interfaceCustomization =
remember(appPreferences) { InterfaceCustomization(appPreferences) }
val baseDensity = LocalDensity.current
val scaledDensity =
val uiScaleDensity =
remember(baseDensity, interfaceCustomization.uiScalePercent) {
val factor = interfaceCustomization.uiScalePercent / 100f
Density(
density = baseDensity.density * factor,
fontScale = baseDensity.fontScale,
)
scaledDensity(baseDensity, interfaceCustomization.uiScalePercent)
}
CompositionLocalProvider(
LocalInterfaceCustomization provides interfaceCustomization,
LocalDensity provides scaledDensity,
LocalDensity provides uiScaleDensity,
) {
NavDisplay(
backStack = backStack,