mirror of
https://github.com/Myzel394/NumberHub.git
synced 2025-06-18 16:25:27 +02:00
fix: Improve ConverterKeyboard.kt
Signed-off-by: Myzel394 <50424412+Myzel394@users.noreply.github.com>
This commit is contained in:
parent
38ba85abaa
commit
b343b78753
@ -81,6 +81,7 @@ import app.myzel394.numberhub.core.ui.common.icons.iconpack.Power
|
||||
import app.myzel394.numberhub.core.ui.common.icons.iconpack.RightBracket
|
||||
import app.myzel394.numberhub.core.ui.common.icons.iconpack.Root
|
||||
import app.myzel394.numberhub.data.model.converter.unit.BasicUnit
|
||||
import app.myzel394.numberhub.feature.converter.createSortedArray
|
||||
import kotlin.math.ceil
|
||||
|
||||
@Composable
|
||||
@ -521,25 +522,3 @@ private fun PreviewConverterKeyboardNumberBase() {
|
||||
basis = BasicUnit.NumberBase.Hexadecimal,
|
||||
)
|
||||
}
|
||||
|
||||
// So here's the problem. If we just go down from 3 downto 0 with columns 2, this results in:
|
||||
// [3, 2]
|
||||
// [1, 0]
|
||||
// While this is correct, the ordering is incorrect. It should be
|
||||
// [2, 3]
|
||||
// [0, 1]
|
||||
// TODO: Add support for rtl languages
|
||||
internal fun createSortedArray(range: IntRange, columns: Int): List<Int> {
|
||||
val result = mutableListOf<Int>()
|
||||
val rows = ceil(range.count().toDouble() / columns.toDouble()).toInt()
|
||||
for (row in rows downTo 0) {
|
||||
for (column in 0 until columns) {
|
||||
val index = row * columns + column + range.first
|
||||
if (index <= range.last) {
|
||||
result.add(index)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
@ -0,0 +1,25 @@
|
||||
package app.myzel394.numberhub.feature.converter
|
||||
|
||||
import kotlin.math.ceil
|
||||
|
||||
// So here's the problem. If we just go down from 3 downto 0 with columns 2, this results in:
|
||||
// [3, 2]
|
||||
// [1, 0]
|
||||
// While this is correct, the ordering is incorrect. It should be
|
||||
// [2, 3]
|
||||
// [0, 1]
|
||||
// TODO: Add support for rtl languages
|
||||
internal fun createSortedArray(range: IntRange, columns: Int): List<Int> {
|
||||
val result = mutableListOf<Int>()
|
||||
val rows = ceil(range.count().toDouble() / columns.toDouble()).toInt()
|
||||
for (row in rows downTo 0) {
|
||||
for (column in 0 until columns) {
|
||||
val index = row * columns + column + range.first
|
||||
if (index <= range.last) {
|
||||
result.add(index)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user