scoop:scoop.ui:0.1.0
src/layout/item_scenes.scoop
Selected production source · src/layout/item_scenes.scoop
1
package scoop.ui3
import scoop.collections.HashMap5
/** Indexes only this selected layout, never the source or other trial results. */6
internal class ItemScenes(private val children: Array<LazyLayoutItem>) {7
private val keyed = HashMap<ViewKey, Long>()8
private val presented = MutableArray<Boolean>(children.size) { _ -> false }9
init {10
for (index in 0L..<children.size)11
keyed[children[index].entry.key] = index12
}13
fun take(key: ViewKey): Long {14
requireUi(key != ViewKey.Position, "item presentation requires an explicit key")15
val index = keyed[key] ?:16
throw IllegalArgumentException(Some("item is not in the selected layout"))17
requireUi(children[index].placed, "item was not placed in the selected layout")18
if (presented[index]) throw IllegalStateException(Some("item was already presented"))19
presented[index] = true20
return index21
}22
fun contains(index: Long): Boolean = presented[index]23
}