mirror of
https://gitlab.futo.org/keyboard/latinime.git
synced 2024-09-28 14:54:30 +01:00
Fix imprecise row Y positioning
This commit is contained in:
parent
777aec644a
commit
25b23008a0
@ -75,7 +75,7 @@ fun List<LayoutEntry.Key>.addGap(totalGap: Float): List<LayoutEntry> {
|
|||||||
data class LayoutRow(
|
data class LayoutRow(
|
||||||
val entries: List<LayoutEntry>,
|
val entries: List<LayoutEntry>,
|
||||||
val widths: Map<KeyWidth, Float>,
|
val widths: Map<KeyWidth, Float>,
|
||||||
val height: Int,
|
val height: Float,
|
||||||
val splittable: Boolean
|
val splittable: Boolean
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -160,6 +160,8 @@ data class LayoutEngine(
|
|||||||
private val maxFunctionalKeyWidth = (layoutWidth * maxOf(0.15f,
|
private val maxFunctionalKeyWidth = (layoutWidth * maxOf(0.15f,
|
||||||
keyboard.overrideWidths[KeyWidth.FunctionalKey] ?: 0.15f))
|
keyboard.overrideWidths[KeyWidth.FunctionalKey] ?: 0.15f))
|
||||||
|
|
||||||
|
private val bottomRegularKeyWidth = 0.1f * layoutWidth
|
||||||
|
|
||||||
|
|
||||||
private fun computeRegularKeyWidth(layoutWidth: Int = this.layoutWidth): Float {
|
private fun computeRegularKeyWidth(layoutWidth: Int = this.layoutWidth): Float {
|
||||||
return keyboard.overrideWidths[KeyWidth.Regular]?.let { it * layoutWidth.toFloat() } ?: run {
|
return keyboard.overrideWidths[KeyWidth.Regular]?.let { it * layoutWidth.toFloat() } ?: run {
|
||||||
@ -321,7 +323,7 @@ data class LayoutEngine(
|
|||||||
private fun buildLayoutRow(
|
private fun buildLayoutRow(
|
||||||
computedRowWithoutWidths: List<LayoutEntry.Key>,
|
computedRowWithoutWidths: List<LayoutEntry.Key>,
|
||||||
widths: Map<KeyWidth, Float>,
|
widths: Map<KeyWidth, Float>,
|
||||||
height: Int,
|
height: Float,
|
||||||
splittable: Boolean
|
splittable: Boolean
|
||||||
): LayoutRow {
|
): LayoutRow {
|
||||||
val computedRow = computedRowWithoutWidths.map { key ->
|
val computedRow = computedRowWithoutWidths.map { key ->
|
||||||
@ -352,7 +354,9 @@ data class LayoutEngine(
|
|||||||
|
|
||||||
val rowRegularKeyWidths = rows.map {
|
val rowRegularKeyWidths = rows.map {
|
||||||
// Special case: action row uses regular key width to match the other rows
|
// 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
|
regularKeyWidth
|
||||||
} else {
|
} else {
|
||||||
unsplitRegularKeyWidth
|
unsplitRegularKeyWidth
|
||||||
@ -430,15 +434,15 @@ data class LayoutEngine(
|
|||||||
|
|
||||||
val computedRowWithWidths = computedRowWithoutWidths.mapIndexed { i, row ->
|
val computedRowWithWidths = computedRowWithoutWidths.mapIndexed { i, row ->
|
||||||
val height = if(rows[i].isBottomRow) {
|
val height = if(rows[i].isBottomRow) {
|
||||||
bottomRowHeightPx.roundToInt()
|
bottomRowHeightPx
|
||||||
} else {
|
} else {
|
||||||
(rows[i].rowHeight * rowHeightPx).roundToInt()
|
(rows[i].rowHeight * rowHeightPx)
|
||||||
}
|
}
|
||||||
|
|
||||||
buildLayoutRow(
|
buildLayoutRow(
|
||||||
row,
|
row,
|
||||||
rowWidths[i],
|
rowWidths[i],
|
||||||
height,
|
height.toFloat(),
|
||||||
rows[i].splittable
|
rows[i].splittable
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -533,21 +537,21 @@ data class LayoutEngine(
|
|||||||
if(isSplitLayout && row.splittable) {
|
if(isSplitLayout && row.splittable) {
|
||||||
val splitRows = row.entries.splitRow()
|
val splitRows = row.entries.splitRow()
|
||||||
|
|
||||||
addRowAlignLeft(splitRows.first, y, row.height)
|
addRowAlignLeft(splitRows.first, y, row.height.toInt())
|
||||||
addRowAlignRight(splitRows.second, y, row.height)
|
addRowAlignRight(splitRows.second, y, row.height.toInt())
|
||||||
} else {
|
} else {
|
||||||
addRowAlignLeft(row.entries, y, row.height)
|
addRowAlignLeft(row.entries, y, row.height.toInt())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addKeys(rows: List<LayoutRow>): Int {
|
private fun addKeys(rows: List<LayoutRow>): Int {
|
||||||
var currentY = 0
|
var currentY = 0.0f
|
||||||
rows.forEach { row ->
|
rows.forEach { row ->
|
||||||
addRow(row, currentY)
|
addRow(row, currentY.toInt())
|
||||||
currentY += row.height
|
currentY += row.height
|
||||||
}
|
}
|
||||||
|
|
||||||
return currentY
|
return currentY.roundToInt()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun build(): org.futo.inputmethod.keyboard.Keyboard {
|
fun build(): org.futo.inputmethod.keyboard.Keyboard {
|
||||||
|
Loading…
Reference in New Issue
Block a user