Some Color Adoptions

This commit is contained in:
Oliver Rümpelein 2021-09-02 18:24:59 +02:00
parent 9eaf6f54ef
commit 613b56b892
3 changed files with 17 additions and 6 deletions

View file

@ -34,7 +34,7 @@ fun PlayerCard(
Text( Text(
text = player.name, text = player.name,
fontSize = 2.5.em, fontSize = 2.5.em,
color = Color.LightGray color = Color.White
) )
Text( Text(
text = points.toString(), text = points.toString(),

View file

@ -85,7 +85,7 @@ fun Question(
Text( Text(
text = "${questionData.actualDisplayPoints(secondRoundDouble)}", text = "${questionData.actualDisplayPoints(secondRoundDouble)}",
fontSize = 3.em, fontSize = 3.em,
color = if (pointsButtonActive) Color.Gray else Color.LightGray color = if (pointsButtonActive) Color.Gray else Color.White
) )
} }
} }

View file

@ -7,11 +7,22 @@ import kotlinx.serialization.Serializable
class ColorData( class ColorData(
val red: Int, val red: Int,
val green: Int, val green: Int,
val blue: Int, val blue: Int
val alpha: Int = 0xFF ) {
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?.toColorOrNull() = this?.toColor()
fun ColorData?.toColorOrDefault() = this?.toColor() ?: Color.Blue fun ColorData?.toColorOrDefault() = this?.toColor() ?: Color.Blue
fun ColorData.toColor() = Color(red, green, blue, alpha) fun ColorData.toColor() = Color(red, green, blue)