2024-01-01 16:33:20 +01:00
|
|
|
package app.revanced.integrations.youtube.swipecontrols.misc
|
2022-07-05 22:02:27 +02:00
|
|
|
|
|
|
|
import android.content.Context
|
|
|
|
import android.util.TypedValue
|
|
|
|
import kotlin.math.roundToInt
|
|
|
|
|
|
|
|
fun Float.clamp(min: Float, max: Float): Float {
|
|
|
|
if (this < min) return min
|
|
|
|
if (this > max) return max
|
|
|
|
return this
|
|
|
|
}
|
|
|
|
|
|
|
|
fun Int.clamp(min: Int, max: Int): Int {
|
|
|
|
if (this < min) return min
|
|
|
|
if (this > max) return max
|
|
|
|
return this
|
|
|
|
}
|
|
|
|
|
|
|
|
fun Int.applyDimension(context: Context, unit: Int): Int {
|
|
|
|
return TypedValue.applyDimension(
|
|
|
|
unit,
|
|
|
|
this.toFloat(),
|
2024-03-03 00:15:00 +01:00
|
|
|
context.resources.displayMetrics,
|
2022-07-05 22:02:27 +02:00
|
|
|
).roundToInt()
|
|
|
|
}
|