Fix text drawable icon scaling

This commit is contained in:
MM20
2022-04-09 17:37:13 +02:00
parent 0711d02dbf
commit 11df4376a1
4 changed files with 19 additions and 22 deletions
@@ -7,7 +7,8 @@ import android.graphics.drawable.Drawable
class TextDrawable(
val text: String,
val color: Int = Color.WHITE,
fontSize: Float = 13f,
val height: Int? = null,
val fontSize: Float = 13f,
typeface: Typeface = Typeface.DEFAULT
): Drawable() {
@@ -25,6 +26,8 @@ class TextDrawable(
override fun draw(canvas: Canvas) {
val bounds = bounds
if (height != null) paint.textSize = fontSize * bounds.height().toFloat() / height.toFloat()
else paint.textSize = fontSize
paint.getTextBounds(text, 0, text.length, rect)
canvas.drawText(text, bounds.exactCenterX(), bounds.exactCenterY() + rect.height() / 2f, paint)
}