properly calculate the Enter icons position after enlarging it

This commit is contained in:
tibbi 2022-01-16 18:18:24 +01:00
parent 9d6f31c283
commit 9cf7f1574f
1 changed files with 14 additions and 7 deletions

View File

@ -623,15 +623,22 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
key.icon = resources.getDrawable(drawableId)
}
val drawableX = (key.width - padding.left - padding.right - key.icon!!.intrinsicWidth) / 2 + padding.left
val drawableY = (key.height - key.icon!!.intrinsicHeight) / 2
canvas.translate(drawableX.toFloat(), drawableY.toFloat())
if (key.codes.firstOrNull() == MyKeyboard.KEYCODE_ENTER) {
key.icon!!.setBounds(0, 0, (key.icon!!.intrinsicWidth * 1.2).toInt(), (key.icon!!.intrinsicHeight * 1.2).toInt())
val iconWidthToUse = if (key.codes.firstOrNull() == MyKeyboard.KEYCODE_ENTER) {
(key.icon!!.intrinsicWidth * 1.2).toInt()
} else {
key.icon!!.setBounds(0, 0, key.icon!!.intrinsicWidth, key.icon!!.intrinsicHeight)
key.icon!!.intrinsicWidth
}
val iconHeightToUse = if (key.codes.firstOrNull() == MyKeyboard.KEYCODE_ENTER) {
(key.icon!!.intrinsicHeight * 1.2).toInt()
} else {
key.icon!!.intrinsicHeight
}
val drawableX = (key.width - iconWidthToUse) / 2
val drawableY = (key.height - iconHeightToUse) / 2
canvas.translate(drawableX.toFloat(), drawableY.toFloat())
key.icon!!.setBounds(0, 0, iconWidthToUse, iconHeightToUse)
key.icon!!.draw(canvas)
canvas.translate(-drawableX.toFloat(), -drawableY.toFloat())
}