scoop:scoop.ui.component:0.1.0
src/table/data_builder.scoop
Selected production source · src/table/data_builder.scoop
1
package scoop.ui.component3
import scoop.graphics.text.FontCollection4
import scoop.ui.*5
import scoop.ui.style.ThemeSource7
public class DataTableProps<Row> public constructor(8
public val state: DataTableState<Row>,9
public val bodyHeight: Double = 320.0,10
public val itemExtent: ItemExtent = ItemExtent.Variable(48.0),11
public val selection: Boolean = true,12
public val pagination: Boolean = true,13
public val columnMenu: Boolean = true,14
public val additiveSort: Boolean = false,15
public val pageSizes: Array<Long> = [10L, 20L, 50L, 100L],16
public val toolbar: View? = None,17
public val footer: View? = None,18
public val empty: PanelContent =19
PanelContent.Label(LabelProps(LabelText.Plain("No results.", None))),20
public val horizontal: ScrollState? = None,21
public val vertical: ScrollState? = None,22
public val handle: VirtualListHandle? = None,23
public val width: Double? = None,24
public val enabled: Boolean = true,25
public val fonts: FontCollection? = None,26
public val theme: ThemeSource? = None,27
public val semantics: ComponentSemantics = ComponentSemantics()28
) {29
init {30
nonnegative(bodyHeight, "invalid data table height")31
itemEstimate(itemExtent)32
for (index in 0L ..< pageSizes.size) {33
requireComponent(pageSizes[index] > 0L, "invalid table page size option")34
for (previous in 0L ..< index)35
requireComponent(36
pageSizes[index] != pageSizes[previous],37
"duplicate table page size option"38
)39
}40
}41
}43
public class DataTableBuilder internal constructor() {44
public var bodyHeight: Double = 320.045
public var itemExtent: ItemExtent = ItemExtent.Variable(48.0)46
public var selection: Boolean = true47
public var pagination: Boolean = true48
public var columnMenu: Boolean = true49
public var additiveSort: Boolean = false50
public var pageSizes: Array<Long> = [10L, 20L, 50L, 100L]51
public var toolbar: View? = None52
public var footer: View? = None53
public var empty: PanelContent =54
PanelContent.Label(LabelProps(LabelText.Plain("No results.", None)))55
public var horizontal: ScrollState? = None56
public var vertical: ScrollState? = None57
public var handle: VirtualListHandle? = None58
public var width: Double? = None59
public var enabled: Boolean = true60
public var fonts: FontCollection? = None61
public var theme: ThemeSource? = None62
public var semantics: ComponentSemantics = ComponentSemantics()63
public var key: ViewKey = ViewKey.Position64
public fun toolbar(view: View) {65
toolbar = Some(view)66
}67
public fun footer(view: View) {68
footer = Some(view)69
}70
public fun empty(text: String) {71
empty = tableText(text)72
}73
public fun empty(view: View) {74
empty = PanelContent.Custom(view)75
}76
internal fun <Row> snapshot(state: DataTableState<Row>): DataTableProps<Row> =77
DataTableProps(78
state,79
bodyHeight,80
itemExtent,81
selection,82
pagination,83
columnMenu,84
additiveSort,85
pageSizes,86
toolbar,87
footer,88
empty,89
horizontal,90
vertical,91
handle,92
width,93
enabled,94
fonts,95
theme,96
semantics97
)98
}100
public fun <Row> dataTable(101
state: DataTableState<Row>,102
configure: DataTableBuilder.() -> Unit = {}103
): View {104
val builder = DataTableBuilder()105
builder.configure()106
return component(107
builder.snapshot(state),108
{ props, scope -> DataTable(props, scope) },109
builder.key110
)111
}