Scoop API

scoop:scoop.ui.component:0.1.0

src/table/data_builder.scoop

Selected production source · src/table/data_builder.scoop

1package scoop.ui.component
3import scoop.graphics.text.FontCollection
4import scoop.ui.*
5import scoop.ui.style.ThemeSource
7public 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 }
43public class DataTableBuilder internal constructor() {
44 public var bodyHeight: Double = 320.0
45 public var itemExtent: ItemExtent = ItemExtent.Variable(48.0)
46 public var selection: Boolean = true
47 public var pagination: Boolean = true
48 public var columnMenu: Boolean = true
49 public var additiveSort: Boolean = false
50 public var pageSizes: Array<Long> = [10L, 20L, 50L, 100L]
51 public var toolbar: View? = None
52 public var footer: View? = None
53 public var empty: PanelContent =
54 PanelContent.Label(LabelProps(LabelText.Plain("No results.", None)))
55 public var horizontal: ScrollState? = None
56 public var vertical: ScrollState? = None
57 public var handle: VirtualListHandle? = None
58 public var width: Double? = None
59 public var enabled: Boolean = true
60 public var fonts: FontCollection? = None
61 public var theme: ThemeSource? = None
62 public var semantics: ComponentSemantics = ComponentSemantics()
63 public var key: ViewKey = ViewKey.Position
64 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 semantics
97 )
100public 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.key
110 )