Scoop API

scoop:scoop.ui.component:0.1.0

src/layout/wrap_lines.scoop

Selected production source · src/layout/wrap_lines.scoop

1package scoop.ui.component
3internal struct WrapLine(val start: Long, val count: Long)
5internal fun wrapLines(bases: Array<Double>, gap: Double, maximum: Double?): Array<WrapLine> {
6 val lines = ArrayList<WrapLine>()
7 var start = 0L
8 var extent = 0.0
9 for (index in 0L ..< bases.size) {
10 val candidate =
11 if (index == start)
12 bases[index]
13 else
14 extent + gap + bases[index]
15 val wraps =
16 when (maximum) {
17 case Some(val limit) -> index > start && candidate > limit
18 case None -> false
19 }
20 if (wraps) {
21 lines.add(WrapLine(start, index - start))
22 start = index
23 extent = bases[index]
24 } else
25 extent = candidate
26 nonnegative(extent, "wrap line extent overflow")
27 }
28 if (start < bases.size)
29 lines.add(WrapLine(start, bases.size - start))
30 return lines.toArray()