Scoop API

scoop:scoop.ui.component:0.1.0

src/conversation/scroll_options.scoop

Selected production source · src/conversation/scroll_options.scoop

1package scoop.ui.component
3import scoop.ui.*
4import scoop.ui.style.*
6public enum MessageInitialPosition {
7 Start, End, LastAnchor
8}
10public enum MessageScrollMode {
11 Holding, Anchoring, Following
14public enum MessageScrollDirection {
15 Start, End
18public class MessageScrollOptions public constructor(
19 public val autoScroll: Boolean = false,
20 public val initialPosition: MessageInitialPosition = MessageInitialPosition.End,
21 public val edgeThreshold: Double = 8.0,
22 public val scrollMargin: Double = 0.0,
23 public val previousItemPeek: Double = 64.0,
24 public val preserveOnPrepend: Boolean = true
25) {
26 init {
27 nonnegative(edgeThreshold, "invalid message edge threshold")
28 nonnegative(scrollMargin, "invalid message scroll margin")
29 nonnegative(previousItemPeek, "invalid message previous item peek")
30 }
33public class MessageReadingSnapshot public constructor(
34 public val visibleKeys: Array<ViewKey>,
35 public val anchor: VirtualReadingAnchor?,
36 public val currentAnchor: ViewKey?,
37 public val atStart: Boolean,
38 public val atEnd: Boolean
41public class MessageScrollerProps public constructor(
42 public val source: TranscriptSource,
43 public val state: MessageScrollState,
44 public val itemExtent: ItemExtent = ItemExtent.Variable(160.0),
45 public val spacing: Double = 24.0,
46 public val overscan: Double = 160.0,
47 public val width: Double? = None,
48 public val height: Double? = Some(480.0),
49 public val scrollbars: ScrollbarVisibility = ScrollbarVisibility.Auto,
50 public val scrollbar: ScrollbarOptions = scrollbarOptions(),
51 public val enabled: Boolean = true,
52 public val focus: FocusOptions = FocusOptions(),
53 public val theme: ThemeSource? = None,
54 public val controls: View? = None,
55 public val showControls: Boolean = true,
56 public val placeholder: View? = None,
57 public val scrollbarBehavior: ScrollbarBehavior = scrollbarBehavior(),
58 public val scrollPhysics: ScrollPhysicsOptions = ScrollPhysicsOptions(),
59 public val itemSemantics: ItemSemantics? = None,
60 public val semantics: ComponentSemantics = ComponentSemantics(),
61 public val collectionSemantics: ComponentSemantics = ComponentSemantics()
62) {
63 init {
64 nonnegative(spacing, "invalid message spacing")
65 nonnegative(overscan, "invalid message overscan")
66 when (width) {
67 case Some(val value) -> nonnegative(value, "invalid message width");
68 case None -> {}
69 }
70 when (height) {
71 case Some(val value) -> nonnegative(value, "invalid message height");
72 case None -> {}
73 }
74 itemEstimate(itemExtent)
75 when (itemSemantics) {
76 case Some(val items) -> requireComponent(
77 items.source === source,
78 "message semantics must describe the same transcript snapshot"
79 )
80 case None -> {}
81 }
82 }
85public class MessageScrollerBuilder internal constructor() {
86 public var itemExtent: ItemExtent = ItemExtent.Variable(160.0)
87 public var spacing: Double = 24.0
88 public var overscan: Double = 160.0
89 public var width: Double? = None
90 public var height: Double? = Some(480.0)
91 public var scrollbars: ScrollbarVisibility = ScrollbarVisibility.Auto
92 public var scrollbar: ScrollbarOptions = scrollbarOptions()
93 public var enabled: Boolean = true
94 public var focus: FocusOptions = FocusOptions()
95 public var theme: ThemeSource? = None
96 public var controls: View? = None
97 public var showControls: Boolean = true
98 public var placeholder: View? = None
99 public var scrollbarBehavior: ScrollbarBehavior = scrollbarBehavior()
100 public var scrollPhysics: ScrollPhysicsOptions = ScrollPhysicsOptions()
101 public var key: ViewKey = ViewKey.Position
102 public var itemSemantics: ItemSemantics? = None
103 public var semantics: ComponentSemantics = ComponentSemantics()
104 public var collectionSemantics: ComponentSemantics = ComponentSemantics()
105 public fun scrollbar(configure: ScrollbarOptionsBuilder.() -> Unit) {
106 scrollbar = scrollbar.copy(configure)
107 }
108 public fun scrollbarBehavior(configure: ScrollbarBehaviorBuilder.() -> Unit): Unit {
109 scrollbarBehavior = scrollbarBehavior.copy(configure)
110 }
111 public fun focus(configure: FocusOptionsBuilder.() -> Unit) {
112 focus = focus.copy(configure)
113 }
114 internal fun snapshot(
115 source: TranscriptSource,
116 state: MessageScrollState
117 ): MessageScrollerProps =
118 MessageScrollerProps(
119 source,
120 state,
121 itemExtent,
122 spacing,
123 overscan,
124 width,
125 height,
126 scrollbars,
127 scrollbar,
128 enabled,
129 focus,
130 theme,
131 controls,
132 showControls,
133 placeholder,
134 scrollbarBehavior,
135 scrollPhysics,
136 itemSemantics,
137 semantics,
138 collectionSemantics
139 )