scoop:scoop.ui.component:0.1.0
src/tree/view_values.scoop
Selected production source · src/tree/view_values.scoop
1
package scoop.ui.component3
import scoop.graphics.text.FontCollection4
import scoop.ui.*5
import scoop.ui.style.*6
import scoop.window.KeyEvent7
import scoop.window.PointerState9
public enum TreeExpandAction {10
Switcher, Click, DoubleClick11
}13
/** Whole ancestor rows share the body's actual height limit. */14
public class TreeSticky public constructor(15
public val enabled: Boolean = false,16
public val maxRows: Long = 7L,17
public val maxHeightRatio: Double = 0.418
) {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
}26
}28
public class TreeStickyBuilder internal constructor(value: TreeSticky) {29
public var enabled: Boolean = value.enabled30
public var maxRows: Long = value.maxRows31
public var maxHeightRatio: Double = value.maxHeightRatio32
internal fun snapshot(): TreeSticky = TreeSticky(enabled, maxRows, maxHeightRatio)33
}35
/** Activation is independent of whether a controlled selection binding accepted a change. */36
public 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? = None41
)43
public 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 = false83
)85
public class TreeBuilder<T> internal constructor(86
private val model: TreeState<T>,87
directory: Boolean88
) {89
public var width: Double? = None90
public var height: Double? = None91
public var contentWidth: Double? = None92
public var virtualize: Boolean = true93
public var itemExtent: ItemExtent = ItemExtent.Fixed(28.0)94
public var overscan: Double = 56.095
public var sticky: TreeSticky = TreeSticky(directory)96
public var indent: Double = 20.097
public var showLines: Boolean = false98
public var showIcons: Boolean = directory99
public var fullRow: Boolean = directory100
public var directory: Boolean = directory101
public var expandAction: TreeExpandAction = if (directory)102
TreeExpandAction.Click103
else104
TreeExpandAction.Switcher105
public var enabled: Boolean = true106
public var scroll: ScrollState? = None107
public var horizontal: ScrollState? = None108
public var handle: TreeHandle? = None109
public var anchor: VirtualListAnchor = VirtualListAnchor.KeepVisible110
public var retention: ItemRetention = ItemRetention.Dispose111
public var scrollbars: ScrollbarVisibility = ScrollbarVisibility.Auto112
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? = None117
public var fonts: FontCollection? = None118
public var focus: FocusOptions = FocusOptions()119
public var semantics: ComponentSemantics = ComponentSemantics()120
public var title: ((TreeRow<T>) -> View)? = None121
public var icon: ((TreeRow<T>) -> View?)? = None122
public var switcher: ((TreeRow<T>) -> View)? = None123
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 = true127
public var drag: TreeDrag<T>? = None128
public var loadingIcon: ((TreeRow<T>) -> View)? = None129
public var titleFocusable: Boolean = false130
public var key: ViewKey = ViewKey.Position131
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, titleFocusable142
)143
}145
public fun <T> tree(state: TreeState<T>, configure: TreeBuilder<T>.() -> Unit = {}): View =146
makeTree(state, false, configure)148
public fun <T> directoryTree(state: TreeState<T>, configure: TreeBuilder<T>.() -> Unit = {}): View =149
makeTree(state, true, configure)151
private fun <T> makeTree(152
state: TreeState<T>,153
directory: Boolean,154
configure: TreeBuilder<T>.() -> Unit155
): View {156
val builder = TreeBuilder(state, directory)157
builder.configure()158
return component(builder.snapshot(), { props, scope -> Tree(props, scope) }, builder.key)159
}