car: tint the car UI with the phone's Material You color

Cards over the map use the nav bar's color instead of near-black.
This commit is contained in:
Seb3thehacker committed 2026-10-24 13:53:05 -07:00
1 parent 1c4b472ce0
commit 0cf28b875c
3 files changed
+33 -2

No files matched your search

@@ -75,6 +75,7 @@ import androidx.compose.ui.res.vectorResource
import androidx.compose.ui.text.style.TextOverflow
import app.seb3thehacker.gearslip.R
import app.seb3thehacker.gearslip.car.theme.GsColors
import app.seb3thehacker.gearslip.car.theme.withTintedSurfaces
import app.seb3thehacker.gearslip.car.theme.GsIconBox
import app.seb3thehacker.gearslip.car.theme.GsIconButton
import app.seb3thehacker.gearslip.car.theme.GsButton
@@ -117,7 +118,7 @@ fun CarUi() {
AppTheme.LIGHT -> false
AppTheme.DARK -> true
}
val colors = if (dark) dynamicDarkColorScheme(appContext) else dynamicLightColorScheme(appContext)
val colors = (if (dark) dynamicDarkColorScheme(appContext) else dynamicLightColorScheme(appContext)).withTintedSurfaces(dark)
val base = LocalDensity.current
val insets by CarEnvironment.insets.collectAsState()
val navigator = remember { CarNavigator(CarSettings.openOnConnect.value) }
@@ -106,7 +106,8 @@ internal fun ChromeSurface(
) {
Surface(
shadowElevation = shadowElevation,
color = MaterialTheme.colorScheme.surface,
// The nav bar's own container colour, so cards over the map match the rest of the car UI.
color = MaterialTheme.colorScheme.surfaceContainer,
contentColor = MaterialTheme.colorScheme.onSurface,
shape = shape,
modifier = modifier,
@@ -0,0 +1,29 @@
package app.seb3thehacker.gearslip.car.theme
import androidx.compose.material3.ColorScheme
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.compositeOver
/**
* The phone's Material You colours, with its accent washed over the surfaces. Material You's own
* surfaces are nearly neutral, which reads as flat grey on a car screen; tinting them with the
* phone's primary colour (purple on a purple phone) gives the whole UI the phone's hue, the way
* Material 3's surface tint does, and it changes with the wallpaper like everything else.
* Higher containers take more of the tint, so cards still stand off the background.
*/
fun ColorScheme.withTintedSurfaces(dark: Boolean): ColorScheme {
val base = if (dark) 0.03f else 0.02f
fun tint(own: Color, step: Int) = primary.copy(alpha = base + step * (if (dark) 0.015f else 0.01f)).compositeOver(own)
return copy(
background = tint(background, 0),
surface = tint(surface, 0),
surfaceDim = tint(surfaceDim, 0),
surfaceContainerLowest = tint(surfaceContainerLowest, 0),
surfaceContainerLow = tint(surfaceContainerLow, 1),
surfaceContainer = tint(surfaceContainer, 2),
surfaceContainerHigh = tint(surfaceContainerHigh, 3),
surfaceContainerHighest = tint(surfaceContainerHighest, 4),
surfaceBright = tint(surfaceBright, 4),
surfaceVariant = tint(surfaceVariant, 3),
)
}