From a1ceb9a4898bef82329f3e5693adb465b3d6d938 Mon Sep 17 00:00:00 2001 From: Ash Date: Mon, 28 Mar 2022 00:04:44 +0800 Subject: [PATCH] Add surfaceColorAtElevation extension --- .../me/ash/reader/ui/extension/ColorScheme.kt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 app/src/main/java/me/ash/reader/ui/extension/ColorScheme.kt diff --git a/app/src/main/java/me/ash/reader/ui/extension/ColorScheme.kt b/app/src/main/java/me/ash/reader/ui/extension/ColorScheme.kt new file mode 100644 index 0000000..6ff4f0c --- /dev/null +++ b/app/src/main/java/me/ash/reader/ui/extension/ColorScheme.kt @@ -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) +} \ No newline at end of file