Scoop API

scoop:scoop.ui.component:0.1.0

src/table/values.scoop

Selected production source · src/table/values.scoop

1package scoop.ui.component
3import scoop.ui.*
5public class TableColumnSize public constructor(
6 public val track: GridTrack = GridTrack.Fraction(1.0),
7 public val minimum: Double = 48.0,
8 public val maximum: Double? = None,
9 public val samples: Array<String> = []
10) {
11 init {
12 checkGridTracks([track])
13 nonnegative(minimum, "invalid table minimum column width")
14 when (maximum) {
15 case Some(val value) -> requireComponent(
16 value.isFinite() && value >= minimum,
17 "invalid table maximum column width"
18 )
19 case None -> {}
20 }
21 }
22 public fun constrain(width: Double): Double {
23 nonnegative(width, "invalid table column width")
24 return upperBound(lowerBound(width, minimum), maximum ?: lowerBound(width, minimum))
25 }
28public enum TableSortDirection {
29 Ascending, Descending
32public class TableSort public constructor(
33 public val column: String,
34 public val direction: TableSortDirection = TableSortDirection.Ascending
35): Equals<TableSort> {
36 public override operator fun equals(other: TableSort): Boolean =
37 column == other.column && direction == other.direction
40public class TableFilter public constructor(
41 public val column: String,
42 public val text: String
43): Equals<TableFilter> {
44 public override operator fun equals(other: TableFilter): Boolean =
45 column == other.column && text == other.text
48public class TableQuery public constructor(
49 public val sorting: Array<TableSort> = [],
50 public val filters: Array<TableFilter> = [],
51 public val pageIndex: Long = 0L,
52 public val pageSize: Long = 10L
53): Equals<TableQuery> {
54 init {
55 requireComponent(pageIndex >= 0L && pageSize > 0L, "invalid table page")
56 }
57 public override operator fun equals(other: TableQuery): Boolean =
58 pageIndex ==
59 other.pageIndex &&
60 pageSize ==
61 other.pageSize &&
62 tableCriteriaEqual(this, other)
65public class TableColumn<Row> public constructor(
66 public val id: String,
67 public val header: String,
68 public val cell: (Row) -> View,
69 public val size: TableColumnSize = TableColumnSize(),
70 public val alignment: AxisAlignment = AxisAlignment.Start,
71 public val compare: ((Row, Row) -> Int)? = None,
72 public val filter: ((Row, String) -> Boolean)? = None,
73 public val remoteSort: Boolean = false,
74 public val hideable: Boolean = true,
75 public val resizable: Boolean = true,
76 /** Reads data without constructing the cell view. None means its text is unknown. */
77 public val semanticText: ((Row) -> String)? = None
78) {
79 init {
80 requireComponent(id != "", "table column id must not be empty")
81 }
82 public val sortable: Boolean get() =
83 remoteSort ||
84 when (compare) {
85 case Some(_) -> true;
86 case None -> false
87 }
90public class TableColumnWidth public constructor(
91 public val column: String,
92 public val width: Double
95internal fun tableCriteriaEqual(left: TableQuery, right: TableQuery): Boolean {
96 if (left.sorting.size != right.sorting.size || left.filters.size != right.filters.size)
97 return false
98 for (index in 0L ..< left.sorting.size)
99 if (left.sorting[index] != right.sorting[index])
100 return false
101 for (index in 0L ..< left.filters.size)
102 if (left.filters[index] != right.filters[index])
103 return false
104 return true