Just override hue
This commit is contained in:
1 parent
d0c150d419
commit
8da5f53856
1 file changed
+3
-19
@@ -39,7 +39,6 @@ import com.materialkolor.hct.Hct
|
||||
import com.materialkolor.ktx.from
|
||||
import com.materialkolor.ktx.toColor
|
||||
import eu.kanade.tachiyomi.util.lang.withUIContext
|
||||
import kotlin.math.abs
|
||||
import splitties.systemservices.downloadManager
|
||||
|
||||
object EhUtils {
|
||||
@@ -119,25 +118,10 @@ object EhUtils {
|
||||
|
||||
fun invCategory(category: Int): Int = category.inv() and ALL_CATEGORY
|
||||
|
||||
private fun differenceDegrees(a: Double, b: Double): Double = 180.0 - abs(abs(a - b) - 180.0)
|
||||
|
||||
private fun sanitizeDegreesDouble(degrees: Double): Double {
|
||||
val deg = degrees % 360.0
|
||||
return if (deg < 0) deg + 360.0 else deg
|
||||
}
|
||||
|
||||
private fun rotationDirection(from: Double, to: Double): Double {
|
||||
val increasingDifference = sanitizeDegreesDouble(to - from)
|
||||
return if (increasingDifference <= 180.0) 1.0 else -1.0
|
||||
}
|
||||
|
||||
val harmonizeWithRole = { primaryContainer: Color, src: Color ->
|
||||
val mergeColor = { primaryContainer: Color, src: Color ->
|
||||
val fromHct = Hct.from(src)
|
||||
val toHct = Hct.from(primaryContainer)
|
||||
val differenceDegrees = differenceDegrees(toHct.hue, fromHct.hue)
|
||||
val rotationDegrees = minOf(differenceDegrees * 0.5, 15.0)
|
||||
val outputHue = sanitizeDegreesDouble(fromHct.hue + rotationDegrees * rotationDirection(fromHct.hue, toHct.hue))
|
||||
Hct.from(outputHue, toHct.chroma, toHct.tone).toColor()
|
||||
Hct.from(fromHct.hue, toHct.chroma, toHct.tone).toColor()
|
||||
}.memoize()
|
||||
|
||||
@Stable
|
||||
@@ -161,7 +145,7 @@ object EhUtils {
|
||||
)
|
||||
return if (Settings.harmonizeCategoryColor) {
|
||||
val primaryContainer = MaterialTheme.colorScheme.primaryContainer
|
||||
harmonizeWithRole(primaryContainer, primary)
|
||||
mergeColor(primaryContainer, primary)
|
||||
} else {
|
||||
primary
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user