feat: added helpers toDP and toSP

This commit is contained in:
danilkinkin 2022-07-03 19:03:19 +04:00
parent 4d4c3da693
commit 71278742a2
2 changed files with 16 additions and 0 deletions

View file

@ -0,0 +1,8 @@
package com.danilkinkin.buckwheat.utils
import android.content.res.Resources
import kotlin.math.roundToInt
fun Int.toDP(): Int = (this * Resources.getSystem().displayMetrics.density).roundToInt()
fun Float.toDP(): Int = (this * Resources.getSystem().displayMetrics.density).roundToInt()

View file

@ -0,0 +1,8 @@
package com.danilkinkin.buckwheat.utils
import android.content.res.Resources
import kotlin.math.roundToInt
fun Int.toSP(): Int = (this * Resources.getSystem().displayMetrics.scaledDensity).roundToInt()
fun Float.toSP(): Int = (this * Resources.getSystem().displayMetrics.scaledDensity).roundToInt()