scoop:scoop.window:0.1.0
src/accessibility/grid.scoop
Selected production source · src/accessibility/grid.scoop
1
package scoop.window.accessibility3
import scoop.collections.HashMap4
import scoop.window.requireWindow6
public struct SemanticGridColumn(7
val key: SemanticItemKey,8
val name: String? = None,9
val header: SemanticNodeId? = None10
)12
/** Explicit operations address one stable row and column, independently of their positions. */13
public struct SemanticGridActions(14
val realize: ((SemanticItemKey, SemanticItemKey) -> SemanticActionResult)? = None,15
val reveal: ((SemanticItemKey, SemanticItemKey) -> SemanticActionResult)? = None,16
val focus: ((SemanticItemKey, SemanticItemKey, Boolean) -> SemanticActionResult)? = None17
)19
/** Describes cells from the collection's immutable data snapshot, without building views. */20
public class SemanticGrid public constructor(21
public val columns: Array<SemanticGridColumn>,22
public val describe: (SemanticItemKey, Long) -> SemanticItemProperties?,23
public val span: ((SemanticItemKey, Long) -> SemanticGridSpan)? = None,24
/** False for full-row content that is outside this grid's column space. */25
public val hasCells: ((SemanticItemKey) -> Boolean)? = None26
) {27
private val indices = HashMap<SemanticItemKey, Long>()28
init {29
for (index in 0L ..< columns.size) {30
requireWindow(indices[columns[index].key] == None, "duplicate semantic column key")31
indices[columns[index].key] = index32
}33
}34
public fun indexOf(key: SemanticItemKey): Long? = indices[key]35
internal fun resolveSpan(row: SemanticItemKey, column: Long): SemanticGridSpan {36
val value = span?.invoke(row, column) ?: SemanticGridSpan(column)37
value.check()38
requireWindow(39
value.column <=40
column &&41
column -42
value.column <43
value.columnSpan &&44
value.column +45
value.columnSpan <=46
columns.size,47
"semantic grid span does not contain the column or exceeds the grid"48
)49
return value50
}51
}53
/** One logical cell covers this continuous column range in the current grid snapshot. */54
public struct SemanticGridSpan(val column: Long, val columnSpan: Long = 1L) {55
internal fun check() {56
requireWindow(column >= 0L && columnSpan > 0L, "invalid semantic grid span")57
requireWindow(column <= Long.MAX_VALUE - columnSpan, "semantic grid span overflow")58
}59
}61
public struct SemanticTableSize(val rows: Long, val columns: Long) {62
internal fun check() {63
requireWindow(rows >= 0L && columns >= 0L, "negative semantic table size")64
}65
}67
public struct SemanticTableCell(68
val row: Long,69
val column: Long,70
val rowSpan: Long = 1L,71
val columnSpan: Long = 1L,72
val columnKey: SemanticItemKey? = None73
) {74
internal fun check() {75
requireWindow(76
row >= 0L && column >= 0L && rowSpan > 0L && columnSpan > 0L,77
"invalid semantic cell position"78
)79
requireWindow(80
row <= Long.MAX_VALUE - rowSpan && column <= Long.MAX_VALUE - columnSpan,81
"semantic cell span overflow"82
)83
}84
}