Skip to content

Commit

Permalink
Merge pull request #24 from sham0688/issue/#7-hex-colors
Browse files Browse the repository at this point in the history
Issue #7 hex colors
  • Loading branch information
Alex009 authored Jun 30, 2021
2 parents 5b9a661 + 8dead75 commit 564905d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ data class Color(
blue = (colorRGBA.shr(8) and 0xFF).toInt(),
alpha = (colorRGBA.shr(0) and 0xFF).toInt()
)

companion object
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright 2021 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license.
*/

package dev.icerock.moko.graphics

fun Color.Companion.parseColor(colorHEX: String): Color {
if (colorHEX[0] != '#') throw IllegalArgumentException("Unknown color")
var ARGB = colorHEX.substring(1).toLong(16)
if (colorHEX.length == 7) {
ARGB = ARGB or 0x00000000ff000000
} else if (colorHEX.length != 9) {
throw IllegalArgumentException("Unknown color")
}
return Color(
alpha = (ARGB.shr(24) and 0xFF).toInt(),
red = (ARGB.shr(16) and 0xFF).toInt(),
green = (ARGB.shr(8) and 0xFF).toInt(),
blue = (ARGB.shr(0) and 0xFF).toInt(),
)
}

0 comments on commit 564905d

Please sign in to comment.