Scoop API

scoop:scoop.ui.component:0.1.0

src/resizable/builder.scoop

Selected production source · src/resizable/builder.scoop

1package scoop.ui.component
3import scoop.ui.*
4import scoop.ui.style.*
6public class ResizablePanelBuilder internal constructor() {
7 public var minimum: Double = 0.0
8 public var maximum: Double? = None
9 public var collapsible: Boolean = false
10 public var collapsedSize: Double = 0.0
11 public var style: StyleOverride = styleOverride()
12 public fun style(configure: StyleOverrideBuilder.() -> Unit) {
13 style = style.copy(configure)
14 }
15 internal fun snapshot(key: ViewKey, content: View): ResizablePanelProps =
16 ResizablePanelProps(key, content, minimum, maximum, collapsible, collapsedSize, style)
19public class ResizableHandleBuilder internal constructor() {
20 public var withHandle: Boolean? = None
21 public var enabled: Boolean = true
22 public var focus: FocusOptions = FocusOptions()
23 public var style: StyleOverride = styleOverride()
24 public var hitWidth: Double = 20.0
25 public var semantics: ComponentSemantics = ComponentSemantics()
26 public fun style(configure: StyleOverrideBuilder.() -> Unit) {
27 style = style.copy(configure)
28 }
29 public fun focus(configure: FocusOptionsBuilder.() -> Unit) {
30 focus = focus.copy(configure)
31 }
32 internal fun snapshot(key: ViewKey): ResizableHandleOptions =
33 ResizableHandleOptions(key, withHandle, enabled, focus, style, hitWidth, semantics)
36public class ResizableBuilder internal constructor() {
37 private val panels = ArrayList<ResizablePanelProps>()
38 private val handles = ArrayList<ResizableHandleOptions>()
39 public var orientation: Orientation = Orientation.Horizontal
40 public var enabled: Boolean = true
41 public var withHandle: Boolean = false
42 public var length: Double? = None
43 public var keyboardStep: Double = 10.0
44 public var dragThreshold: Double = 4.0
45 public var theme: ThemeSource? = None
46 public var style: StyleOverride = styleOverride()
47 public var clip: Boolean = false
48 public var onSizesChange: (Array<ResizableSize>) -> Unit = {}
49 public var onSizesCommit: (Array<ResizableSize>) -> Unit = {}
50 public var onSizesCancel: (Array<ResizableSize>, DragCancelReason) -> Unit = { _, _ -> }
51 public var key: ViewKey = ViewKey.Position
52 public fun style(configure: StyleOverrideBuilder.() -> Unit) {
53 style = style.copy(configure)
54 }
55 public fun panel(
56 key: ViewKey,
57 content: View,
58 configure: ResizablePanelBuilder.() -> Unit = {}
59 ) {
60 val builder = ResizablePanelBuilder()
61 builder.configure()
62 add(builder.snapshot(key, content))
63 }
64 public fun add(panel: ResizablePanelProps) {
65 panels.add(panel)
66 }
67 public fun handle(afterKey: ViewKey, configure: ResizableHandleBuilder.() -> Unit = {}) {
68 val builder = ResizableHandleBuilder()
69 builder.configure()
70 handles.add(builder.snapshot(afterKey))
71 }
72 internal fun snapshot(sizes: Binding<Array<ResizableSize>>): ResizableProps =
73 ResizableProps(
74 sizes,
75 panels.toArray(),
76 handles.toArray(),
77 orientation,
78 enabled,
79 withHandle,
80 length,
81 keyboardStep,
82 dragThreshold,
83 theme,
84 style,
85 clip,
86 onSizesChange,
87 onSizesCommit,
88 onSizesCancel
89 )
92public fun resizable(
93 sizes: Binding<Array<ResizableSize>>,
94 configure: ResizableBuilder.() -> Unit = {}
95): View {
96 val builder = ResizableBuilder()
97 builder.configure()
98 return component(
99 builder.snapshot(sizes),
100 { current, mount -> Resizable(current, scope = mount) },
101 builder.key
102 )