fix: properly placed secondary icon to the top right corner of key.

This commit is contained in:
ismailnurudeen 2023-02-11 22:23:02 +01:00
parent 9eed3982e0
commit ec9625b8f8
1 changed files with 21 additions and 15 deletions

View File

@ -618,30 +618,36 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
val secondaryIcon = key.secondaryIcon val secondaryIcon = key.secondaryIcon
if (secondaryIcon != null) { if (secondaryIcon != null) {
val keyIconWidth = (keyIcon.intrinsicWidth * .8).toInt() val keyIconWidth = (keyIcon.intrinsicWidth * .8f).toInt()
val keyIconHeight = (keyIcon.intrinsicWidth * .8).toInt() val keyIconHeight = (keyIcon.intrinsicHeight * .8f).toInt()
val secondaryIconWidth = (secondaryIcon.intrinsicWidth * .4).toInt() val secondaryIconWidth = (secondaryIcon.intrinsicWidth * .6f).toInt()
val secondaryIconHeight = (secondaryIcon.intrinsicHeight * .4).toInt() val secondaryIconHeight = (secondaryIcon.intrinsicHeight * .6f).toInt()
val drawableX = (key.width - keyIconWidth) / 2 val centerX = key.width / 2
val drawableY = (key.height - keyIconHeight) / 2 val centerY = key.height / 2
canvas.translate(drawableX.toFloat(), drawableY.toFloat()) val keyIconLeft = centerX - keyIconWidth / 2
val keyIconTop = centerY - keyIconHeight / 2
keyIcon.setBounds(0, 0, keyIconWidth, keyIconHeight) keyIcon.setBounds(keyIconLeft, keyIconTop, keyIconLeft + keyIconWidth, keyIconTop + keyIconHeight)
keyIcon.draw(canvas) keyIcon.draw(canvas)
val secIconPaddingBottom = 8 val secondaryIconPaddingRight = 8
val secIconPaddingRight = 4 val secondaryIconLeft = key.width - secondaryIconPaddingRight - secondaryIconWidth
val secondaryIconRight = secondaryIconLeft + secondaryIconWidth
val secondaryIconTop = 12 // This will act as a topPadding
val secondaryIconBottom = secondaryIconTop + secondaryIconHeight
secondaryIcon.setBounds( secondaryIcon.setBounds(
keyIconWidth - secIconPaddingRight, secondaryIconLeft,
-secIconPaddingBottom, secondaryIconTop,
(keyIconWidth + secondaryIconWidth) - secIconPaddingRight, secondaryIconRight,
secondaryIconHeight - secIconPaddingBottom secondaryIconBottom
) )
secondaryIcon.draw(canvas) secondaryIcon.draw(canvas)
canvas.translate(-drawableX.toFloat(), -drawableY.toFloat()) secondaryIcon.draw(canvas)
} else { } else {
val drawableX = (key.width - keyIcon.intrinsicWidth) / 2 val drawableX = (key.width - keyIcon.intrinsicWidth) / 2
val drawableY = (key.height - keyIcon.intrinsicHeight) / 2 val drawableY = (key.height - keyIcon.intrinsicHeight) / 2