From 7a39599074287030f48dadaf28552fb10ba54441 Mon Sep 17 00:00:00 2001 From: Gael Ribes Date: Fri, 11 Dec 2015 11:54:05 +0100 Subject: [PATCH] Add Int.withAlpha to Helpers Returns `0x55FF0000` with `0xFF0000.withAlpha(0x55)` --- dsl/static/src/common/Helpers.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/dsl/static/src/common/Helpers.kt b/dsl/static/src/common/Helpers.kt index 9c1597ba..af75104f 100644 --- a/dsl/static/src/common/Helpers.kt +++ b/dsl/static/src/common/Helpers.kt @@ -32,6 +32,10 @@ val Int.gray: Int val Int.opaque: Int get() = this or 0xff000000.toInt() +fun Int.withAlpha(alpha: Int) { + require(alpha >= 0 && alpha <= 0xFF) + return this and 0x00FFFFFF or (alpha shl 24) +} enum class ScreenSize { SMALL, @@ -123,4 +127,4 @@ inline fun Fragment.configuration( fromSdk, sdk, uiMode, nightMode, rightToLeft, smallestWidth)) init() else null } else null -} \ No newline at end of file +}