mirror of
https://github.com/danilkinkin/buckwheat.git
synced 2025-12-31 04:13:02 +00:00
feat: added helpers toDP and toSP
This commit is contained in:
parent
4d4c3da693
commit
71278742a2
2 changed files with 16 additions and 0 deletions
|
|
@ -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()
|
||||
|
|
@ -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()
|
||||
Loading…
Add table
Add a link
Reference in a new issue