scoop:scoop.ui.component:0.1.0
src/layout/wrap_lines.scoop
Selected production source · src/layout/wrap_lines.scoop
1
package scoop.ui.component3
internal struct WrapLine(val start: Long, val count: Long)5
internal fun wrapLines(bases: Array<Double>, gap: Double, maximum: Double?): Array<WrapLine> {6
val lines = ArrayList<WrapLine>()7
var start = 0L8
var extent = 0.09
for (index in 0L ..< bases.size) {10
val candidate =11
if (index == start)12
bases[index]13
else14
extent + gap + bases[index]15
val wraps =16
when (maximum) {17
case Some(val limit) -> index > start && candidate > limit18
case None -> false19
}20
if (wraps) {21
lines.add(WrapLine(start, index - start))22
start = index23
extent = bases[index]24
} else25
extent = candidate26
nonnegative(extent, "wrap line extent overflow")27
}28
if (start < bases.size)29
lines.add(WrapLine(start, bases.size - start))30
return lines.toArray()31
}