Piotr Prus
07/28/2022, 8:02 PMorangy
Arrangement
that would do what you need. It’s not hard. This looks like justified
arrangement I wrote recently. It’s not perfect for RTL/LTR and maybe something else, but it could give you an idea
fun Arrangement.justified(minSpace: Dp): Arrangement.HorizontalOrVertical = object : Arrangement.HorizontalOrVertical {
override val spacing: Dp
get() = minSpace
override fun Density.arrange(totalSize: Int, sizes: IntArray, layoutDirection: LayoutDirection, outPositions: IntArray) {
if (sizes.isEmpty()) return
val minSpacePx = minSpace.roundToPx()
val measuredSize = sizes.sum()
val spacePx = if (sizes.size > 1)
kotlin.math.max((totalSize - measuredSize) / (sizes.size - 1), minSpacePx)
else
minSpacePx
var occupied = 0
var lastSpace = 0
val reversed = layoutDirection == LayoutDirection.Rtl
sizes.forEachIndexed(reversed) { index, it ->
outPositions[index] = kotlin.math.min(occupied, totalSize - it)
lastSpace = kotlin.math.min(spacePx, totalSize - outPositions[index] - it)
occupied = outPositions[index] + it + lastSpace
}
}
override fun Density.arrange(totalSize: Int, sizes: IntArray, outPositions: IntArray) =
arrange(totalSize, sizes, LayoutDirection.Ltr, outPositions)
override fun toString() = "Arrangement#justified($minSpace)"
}
dewildte
07/28/2022, 9:09 PMIt’s not hardDisplays hard math. (Math, also known as an esoteric language embedded in the fabric of reality by what most men would call aliens.)
dewildte
07/28/2022, 9:14 PM