Scoop API

scoop:scoop.ui.component:0.1.0

src/builders/pagination.scoop

Selected production source · src/builders/pagination.scoop

1package scoop.ui.component
3import scoop.graphics.text.FontCollection
4import scoop.ui.*
5import scoop.ui.style.*
7public class PaginationBuilder internal constructor() {
8 public var siblings: Long = 1L
9 public var boundaries: Long = 1L
10 public var items: Array<PaginationItem>? = None
11 public var enabled: Boolean = true
12 public var showPrevious: Boolean = true
13 public var showNext: Boolean = true
14 public var compact: Boolean = false
15 public var previousText: String = "Previous"
16 public var nextText: String = "Next"
17 public var pageLabel: (Long) -> String = { value -> f"${value}" }
18 public var pageContent: ((Long, ActionContentStyle) -> View)? = None
19 public var ellipsis: View? = None
20 public var fonts: FontCollection? = None
21 public var theme: ThemeSource? = None
22 public var buttonStyle: ButtonStyle = buttonStyle()
23 public var style: StyleOverride = styleOverride()
24 public var previousFocus: FocusOptions = FocusOptions()
25 public var nextFocus: FocusOptions = FocusOptions()
26 public var pageFocus: (Long) -> FocusOptions = { _ -> FocusOptions() }
27 public var onValueChange: (Long) -> Unit = {}
28 public var semantics: ComponentSemantics = ComponentSemantics()
29 public var pageSemantics: (Long) -> ComponentSemantics = { _ -> ComponentSemantics() }
30 public var key: ViewKey = ViewKey.Position
31 public fun add(item: PaginationItem) {
32 val entries = ArrayList<PaginationItem>()
33 for (entry in items ?: [])
34 entries.add(entry)
35 entries.add(item);
36 items = Some(entries.toArray())
37 }
38 public fun item(page: Long) {
39 add(PaginationItem.Page(page))
40 }
41 public fun ellipsis() {
42 add(PaginationItem.Ellipsis)
43 }
44 public fun ellipsis(content: View) {
45 ellipsis = Some(content)
46 }
47 public fun buttonStyle(configure: ButtonStyleBuilder.() -> Unit) {
48 buttonStyle = buttonStyle.copy(configure)
49 }
50 public fun style(configure: StyleOverrideBuilder.() -> Unit) {
51 style = style.copy(configure)
52 }
53 public fun previousFocus(configure: FocusOptionsBuilder.() -> Unit) {
54 previousFocus = previousFocus.copy(configure)
55 }
56 public fun nextFocus(configure: FocusOptionsBuilder.() -> Unit) {
57 nextFocus = nextFocus.copy(configure)
58 }
59 internal fun snapshot(page: Binding<Long>, pageCount: Long): PaginationProps =
60 PaginationProps(
61 page,
62 pageCount,
63 siblings,
64 boundaries,
65 items,
66 enabled,
67 showPrevious,
68 showNext,
69 compact,
70 previousText,
71 nextText,
72 pageLabel,
73 pageContent,
74 ellipsis,
75 fonts,
76 theme,
77 buttonStyle,
78 style,
79 previousFocus,
80 nextFocus,
81 pageFocus,
82 onValueChange,
83 semantics,
84 pageSemantics
85 )
88public fun pagination(
89 page: Binding<Long>,
90 pageCount: Long,
91 configure: PaginationBuilder.() -> Unit = {}
92): View = makePagination(page, pageCount, configure)
94internal fun makePagination(
95 page: Binding<Long>,
96 pageCount: Long,
97 configure: PaginationBuilder.() -> Unit
98): View {
99 val builder = PaginationBuilder();
100 builder.configure()
101 return component(
102 builder.snapshot(page, pageCount),
103 { current, mount -> Pagination(current, scope = mount) },
104 builder.key
105 )