From 25b23008a079c4d770813104b6e46c791e6d0aa4 Mon Sep 17 00:00:00 2001 From: Aleksandras Kostarevas Date: Thu, 19 Sep 2024 10:11:51 +0300 Subject: [PATCH] Fix imprecise row Y positioning --- .../inputmethod/v2keyboard/LayoutEngine.kt | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/java/src/org/futo/inputmethod/v2keyboard/LayoutEngine.kt b/java/src/org/futo/inputmethod/v2keyboard/LayoutEngine.kt index 549d4e825..155fc9cb0 100644 --- a/java/src/org/futo/inputmethod/v2keyboard/LayoutEngine.kt +++ b/java/src/org/futo/inputmethod/v2keyboard/LayoutEngine.kt @@ -75,7 +75,7 @@ fun List.addGap(totalGap: Float): List { data class LayoutRow( val entries: List, val widths: Map, - val height: Int, + val height: Float, val splittable: Boolean ) @@ -160,6 +160,8 @@ data class LayoutEngine( private val maxFunctionalKeyWidth = (layoutWidth * maxOf(0.15f, keyboard.overrideWidths[KeyWidth.FunctionalKey] ?: 0.15f)) + private val bottomRegularKeyWidth = 0.1f * layoutWidth + private fun computeRegularKeyWidth(layoutWidth: Int = this.layoutWidth): Float { return keyboard.overrideWidths[KeyWidth.Regular]?.let { it * layoutWidth.toFloat() } ?: run { @@ -321,7 +323,7 @@ data class LayoutEngine( private fun buildLayoutRow( computedRowWithoutWidths: List, widths: Map, - height: Int, + height: Float, splittable: Boolean ): LayoutRow { val computedRow = computedRowWithoutWidths.map { key -> @@ -352,7 +354,9 @@ data class LayoutEngine( val rowRegularKeyWidths = rows.map { // Special case: action row uses regular key width to match the other rows - if(it.splittable || it.isBottomRow) { + if(it.isBottomRow) { + bottomRegularKeyWidth + } else if(it.splittable) { regularKeyWidth } else { unsplitRegularKeyWidth @@ -430,15 +434,15 @@ data class LayoutEngine( val computedRowWithWidths = computedRowWithoutWidths.mapIndexed { i, row -> val height = if(rows[i].isBottomRow) { - bottomRowHeightPx.roundToInt() + bottomRowHeightPx } else { - (rows[i].rowHeight * rowHeightPx).roundToInt() + (rows[i].rowHeight * rowHeightPx) } buildLayoutRow( row, rowWidths[i], - height, + height.toFloat(), rows[i].splittable ) } @@ -533,21 +537,21 @@ data class LayoutEngine( if(isSplitLayout && row.splittable) { val splitRows = row.entries.splitRow() - addRowAlignLeft(splitRows.first, y, row.height) - addRowAlignRight(splitRows.second, y, row.height) + addRowAlignLeft(splitRows.first, y, row.height.toInt()) + addRowAlignRight(splitRows.second, y, row.height.toInt()) } else { - addRowAlignLeft(row.entries, y, row.height) + addRowAlignLeft(row.entries, y, row.height.toInt()) } } private fun addKeys(rows: List): Int { - var currentY = 0 + var currentY = 0.0f rows.forEach { row -> - addRow(row, currentY) + addRow(row, currentY.toInt()) currentY += row.height } - return currentY + return currentY.roundToInt() } fun build(): org.futo.inputmethod.keyboard.Keyboard {