From 613b56b892e12326db7909a0503aa48e678018ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20R=C3=BCmpelein?= Date: Thu, 2 Sep 2021 18:24:59 +0200 Subject: [PATCH] Some Color Adoptions --- src/main/kotlin/components/PlayerCard.kt | 2 +- src/main/kotlin/components/Question.kt | 2 +- src/main/kotlin/data/ColorData.kt | 19 +++++++++++++++---- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/components/PlayerCard.kt b/src/main/kotlin/components/PlayerCard.kt index 3afdcb6..ea4c33f 100644 --- a/src/main/kotlin/components/PlayerCard.kt +++ b/src/main/kotlin/components/PlayerCard.kt @@ -34,7 +34,7 @@ fun PlayerCard( Text( text = player.name, fontSize = 2.5.em, - color = Color.LightGray + color = Color.White ) Text( text = points.toString(), diff --git a/src/main/kotlin/components/Question.kt b/src/main/kotlin/components/Question.kt index 57e4ec5..85b538c 100644 --- a/src/main/kotlin/components/Question.kt +++ b/src/main/kotlin/components/Question.kt @@ -85,7 +85,7 @@ fun Question( Text( text = "${questionData.actualDisplayPoints(secondRoundDouble)}", fontSize = 3.em, - color = if (pointsButtonActive) Color.Gray else Color.LightGray + color = if (pointsButtonActive) Color.Gray else Color.White ) } } diff --git a/src/main/kotlin/data/ColorData.kt b/src/main/kotlin/data/ColorData.kt index 8ea657b..67ead34 100644 --- a/src/main/kotlin/data/ColorData.kt +++ b/src/main/kotlin/data/ColorData.kt @@ -7,11 +7,22 @@ import kotlinx.serialization.Serializable class ColorData( val red: Int, val green: Int, - val blue: Int, - val alpha: Int = 0xFF -) + val blue: Int +) { + + constructor(rgbHexString: String) : this( + red = rgbHexString.redFromHex(), + green = rgbHexString.greenFromHex(), + blue = rgbHexString.blueFromHex() + ) +} + +internal fun String.colorFromHex(startPos: Int) = ("0x" + this[startPos] + this[startPos + 1]).toInt() +internal fun String.redFromHex() = colorFromHex(2) +internal fun String.greenFromHex() = colorFromHex(4) +internal fun String.blueFromHex() = colorFromHex(6) fun ColorData?.toColorOrNull() = this?.toColor() fun ColorData?.toColorOrDefault() = this?.toColor() ?: Color.Blue -fun ColorData.toColor() = Color(red, green, blue, alpha) +fun ColorData.toColor() = Color(red, green, blue)