Add surfaceColorAtElevation extension

This commit is contained in:
Ash 2022-03-28 00:04:44 +08:00
parent 6fb60c8dc4
commit a1ceb9a489

View File

@ -0,0 +1,16 @@
package me.ash.reader.ui.extension
import androidx.compose.material3.ColorScheme
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.compositeOver
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import kotlin.math.ln
fun ColorScheme.surfaceColorAtElevation(
elevation: Dp,
): Color {
if (elevation == 0.dp) return surface
val alpha = ((4.5f * ln(elevation.value + 1)) + 2f) / 100f
return primary.copy(alpha = alpha).compositeOver(surface)
}