Scoop API

scoop:scoop.ui.component:0.1.0

platform/desktop/native/popup/handle.scoop

Selected production source · platform/desktop/native/popup/handle.scoop

1package scoop.ui.component
3import scoop.ui.state
4import scoop.window.LogicalPosition
6/** One mounted trigger, with explicit requests instead of a persistent open value. */
7public class NativePopupHandle public constructor() {
8 private var owner: NativePopupPresentation? = None
9 private val pending = state(false)
11 public val isPending: Boolean get() = pending.value
12 public fun requestOpen(): Boolean = owner?.open(None) ?: false
13 public fun cancel() {
14 owner?.cancel()
15 }
17 internal fun bind(value: NativePopupPresentation) {
18 when (owner) {
19 case Some(val current) -> requireComponent(
20 current === value,
21 "native popup handle is already mounted"
22 )
23 case None -> {}
24 }
25 owner = Some(value)
26 pending.value = value.isPending
27 }
28 internal fun unbind(value: NativePopupPresentation) {
29 when (owner) {
30 case Some(val current) -> if (current === value) {
31 owner = None
32 pending.value = false
33 }
34 case None -> {}
35 }
36 }
37 internal fun changed(value: Boolean) {
38 pending.value = value
39 }