Scoop API

scoop:scoop.ui:0.1.0

src/interaction/drag_source_values.scoop

Selected production source · src/interaction/drag_source_values.scoop

1package scoop.ui
3import scoop.graphics.Point
4import scoop.math.abs
5import scoop.window.*
7public class DragSourceOptions public constructor(
8 public val threshold: Double = 4.0,
9 public val enabled: Boolean = true,
10 public val mouse: Boolean = true,
11 public val contacts: Boolean = true
12) {
13 init {
14 requireUi(
15 threshold.isFinite() && threshold >= 0.0,
16 "drag threshold must be finite and nonnegative"
17 )
18 }
21/** Local points share the accepted geometry; input snapshots retain window coordinates. */
22public struct DragSourceStart(
23 val start: Point,
24 val position: Point,
25 val press: PointerState,
26 val pointer: PointerState,
27 val input: DragInput
30/** The completion belongs to this prepared source, even when later renders replace prepare. */
31public struct DragSourceData(
32 val content: DragContent,
33 val effects: DragEffects = DragEffects(true, false, false),
34 val localData: Any? = None,
35 val preview: DragPreview? = None,
36 val onCompleted: (DragResult) -> Unit = {}
39internal fun dragSourceThreshold(
40 press: PointerState,
41 pointer: PointerState,
42 threshold: Double
43): Boolean {
44 val dx = pointer.logicalPosition.x - press.logicalPosition.x
45 val dy = pointer.logicalPosition.y - press.logicalPosition.y
46 return dx.isFinite() && dy.isFinite() && (abs(dx) >= threshold || abs(dy) >= threshold)