Scoop API

scoop:scoop.ui.component:0.1.0

src/tree/view_values.scoop

Selected production source · src/tree/view_values.scoop

1package scoop.ui.component
3import scoop.graphics.text.FontCollection
4import scoop.ui.*
5import scoop.ui.style.*
6import scoop.window.KeyEvent
7import scoop.window.PointerState
9public enum TreeExpandAction {
10 Switcher, Click, DoubleClick
13/** Whole ancestor rows share the body's actual height limit. */
14public class TreeSticky public constructor(
15 public val enabled: Boolean = false,
16 public val maxRows: Long = 7L,
17 public val maxHeightRatio: Double = 0.4
18) {
19 init {
20 requireComponent(maxRows >= 0L, "negative sticky tree row limit")
21 requireComponent(
22 maxHeightRatio.isFinite() && maxHeightRatio >= 0.0 && maxHeightRatio <= 1.0,
23 "invalid sticky tree height ratio"
24 )
25 }
28public class TreeStickyBuilder internal constructor(value: TreeSticky) {
29 public var enabled: Boolean = value.enabled
30 public var maxRows: Long = value.maxRows
31 public var maxHeightRatio: Double = value.maxHeightRatio
32 internal fun snapshot(): TreeSticky = TreeSticky(enabled, maxRows, maxHeightRatio)
35/** Activation is independent of whether a controlled selection binding accepted a change. */
36public class TreeActivation<T> internal constructor(
37 public val node: TreeNode<T>,
38 public val origin: TreeChangeOrigin,
39 public val pointer: PointerState? = None,
40 public val keyboard: KeyEvent? = None
43public class TreeProps<T> public constructor(
44 public val state: TreeState<T>,
45 public val width: Double? = None,
46 public val height: Double? = None,
47 public val contentWidth: Double? = None,
48 public val virtualize: Boolean = true,
49 public val itemExtent: ItemExtent = ItemExtent.Fixed(28.0),
50 public val overscan: Double = 56.0,
51 public val sticky: TreeSticky = TreeSticky(),
52 public val indent: Double = 20.0,
53 public val showLines: Boolean = false,
54 public val showIcons: Boolean = false,
55 public val fullRow: Boolean = false,
56 public val directory: Boolean = false,
57 public val expandAction: TreeExpandAction = TreeExpandAction.Switcher,
58 public val enabled: Boolean = true,
59 public val scroll: ScrollState? = None,
60 public val horizontal: ScrollState? = None,
61 public val handle: TreeHandle? = None,
62 public val anchor: VirtualListAnchor = VirtualListAnchor.KeepVisible,
63 public val retention: ItemRetention = ItemRetention.Dispose,
64 public val scrollbars: ScrollbarVisibility = ScrollbarVisibility.Auto,
65 public val scrollbar: ScrollbarOptions = scrollbarOptions(),
66 public val scrollbarBehavior: ScrollbarBehavior = scrollbarBehavior(),
67 public val touchScroll: TouchScrollOptions = TouchScrollOptions(),
68 public val scrollPhysics: ScrollPhysicsOptions = ScrollPhysicsOptions(),
69 public val theme: ThemeSource? = None,
70 public val fonts: FontCollection? = None,
71 public val focus: FocusOptions = FocusOptions(),
72 public val semantics: ComponentSemantics = ComponentSemantics(),
73 public val title: ((TreeRow<T>) -> View)? = None,
74 public val icon: ((TreeRow<T>) -> View?)? = None,
75 public val switcher: ((TreeRow<T>) -> View)? = None,
76 public val onActivate: (TreeActivation<T>) -> Unit = { _ -> },
77 public val onDoubleClick: (TreeActivation<T>) -> Unit = { _ -> },
78 public val onContextMenu: (TreeActivation<T>) -> Unit = { _ -> },
79 public val showHeader: Boolean = true,
80 public val drag: TreeDrag<T>? = None,
81 public val loadingIcon: ((TreeRow<T>) -> View)? = None,
82 public val titleFocusable: Boolean = false
85public class TreeBuilder<T> internal constructor(
86 private val model: TreeState<T>,
87 directory: Boolean
88) {
89 public var width: Double? = None
90 public var height: Double? = None
91 public var contentWidth: Double? = None
92 public var virtualize: Boolean = true
93 public var itemExtent: ItemExtent = ItemExtent.Fixed(28.0)
94 public var overscan: Double = 56.0
95 public var sticky: TreeSticky = TreeSticky(directory)
96 public var indent: Double = 20.0
97 public var showLines: Boolean = false
98 public var showIcons: Boolean = directory
99 public var fullRow: Boolean = directory
100 public var directory: Boolean = directory
101 public var expandAction: TreeExpandAction = if (directory)
102 TreeExpandAction.Click
103 else
104 TreeExpandAction.Switcher
105 public var enabled: Boolean = true
106 public var scroll: ScrollState? = None
107 public var horizontal: ScrollState? = None
108 public var handle: TreeHandle? = None
109 public var anchor: VirtualListAnchor = VirtualListAnchor.KeepVisible
110 public var retention: ItemRetention = ItemRetention.Dispose
111 public var scrollbars: ScrollbarVisibility = ScrollbarVisibility.Auto
112 public var scrollbar: ScrollbarOptions = scrollbarOptions()
113 public var scrollbarBehavior: ScrollbarBehavior = scrollbarBehavior()
114 public var touchScroll: TouchScrollOptions = TouchScrollOptions()
115 public var scrollPhysics: ScrollPhysicsOptions = ScrollPhysicsOptions()
116 public var theme: ThemeSource? = None
117 public var fonts: FontCollection? = None
118 public var focus: FocusOptions = FocusOptions()
119 public var semantics: ComponentSemantics = ComponentSemantics()
120 public var title: ((TreeRow<T>) -> View)? = None
121 public var icon: ((TreeRow<T>) -> View?)? = None
122 public var switcher: ((TreeRow<T>) -> View)? = None
123 public var onActivate: (TreeActivation<T>) -> Unit = { _ -> }
124 public var onDoubleClick: (TreeActivation<T>) -> Unit = { _ -> }
125 public var onContextMenu: (TreeActivation<T>) -> Unit = { _ -> }
126 public var showHeader: Boolean = true
127 public var drag: TreeDrag<T>? = None
128 public var loadingIcon: ((TreeRow<T>) -> View)? = None
129 public var titleFocusable: Boolean = false
130 public var key: ViewKey = ViewKey.Position
131 public fun sticky(configure: TreeStickyBuilder.() -> Unit) {
132 val builder = TreeStickyBuilder(sticky)
133 builder.configure()
134 sticky = builder.snapshot()
135 }
136 internal fun snapshot(): TreeProps<T> = TreeProps(
137 model, width, height, contentWidth, virtualize, itemExtent, overscan, sticky, indent,
138 showLines, showIcons, fullRow, directory, expandAction, enabled, scroll, horizontal,
139 handle, anchor, retention, scrollbars, scrollbar, scrollbarBehavior, touchScroll,
140 scrollPhysics, theme, fonts, focus, semantics, title, icon, switcher, onActivate,
141 onDoubleClick, onContextMenu, showHeader, drag, loadingIcon, titleFocusable
142 )
145public fun <T> tree(state: TreeState<T>, configure: TreeBuilder<T>.() -> Unit = {}): View =
146 makeTree(state, false, configure)
148public fun <T> directoryTree(state: TreeState<T>, configure: TreeBuilder<T>.() -> Unit = {}): View =
149 makeTree(state, true, configure)
151private fun <T> makeTree(
152 state: TreeState<T>,
153 directory: Boolean,
154 configure: TreeBuilder<T>.() -> Unit
155): View {
156 val builder = TreeBuilder(state, directory)
157 builder.configure()
158 return component(builder.snapshot(), { props, scope -> Tree(props, scope) }, builder.key)