Kotlin Inline Classes for Screen Dimension Units
This Kotlin Multi-platform library provides type safety over screen units, such as pixels. Available ScreenDimensionUnits
interface implementations include:
This provides type safety of knowing what you are working with (ex: fun drawLine(start: Pixels, end: Pixels)
).
The library is provided through Bintray. Refer to the releases for the latest version.
repositories {
maven {
url = uri("https://dl.bintray.com/chrynan/chrynan")
}
}
Base Kotlin Common Library:
implementation 'com.chrynan.pixel:pixel-core:VERSION'
Base Kotlin JVM Library:
implementation 'com.chrynan.pixel:pixel-core-jvm:VERSION'
Base Kotlin JS Library:
implementation 'com.chrynan.pixel:pixel-core-js:VERSION'
Android Library:
implementation 'com.chrynan.pixel:pixel-android:VERSION'
Android Jetpack Compose Library:
implementation 'com.chrynan.pixel:pixel-android-compose:VERSION'
ScreenDimensionUnitConverter
on the Pixel
object.Android:
class MyApplication : Application {
override fun onCreate() {
super.onCreate()
Pixel.converter = AndroidScreenDimensionUnitConverter(context = this)
}
}
Kotlin JS:
Pixel.converter = JsScreenDimensionUnitConverter()
Number
to a particular ScreenDimensionUnit
:val pixelSum = 10.px + 20.px
if (pixels > 150.px) { }
## Converting between Android Jetpack Compose Values
The Android Jetpack Compose framework comes with representations of `Dp` and `Px` values. This `pixel-android-compose` library provides ways to convert to and from the Android Jetpack Compose values.
```kotlin
val composePx = pxValue.inComposePx
val composeDp = dpValue.inComposeDp
val px = composePx.inPx
val dp = composeDp.inDp