scoop:scoop.ui.component:0.1.0
src/scroll/idle.scoop
Selected production source · src/scroll/idle.scoop
1
package scoop.ui.component3
import scoop.platform.time.MonotonicInstant4
import scoop.time.*6
/** One idle interval, suspended by actual input ownership rather than periodic sampling. */7
internal class ScrollbarIdle {8
var visible = false9
private var available = false10
private var automatic = false11
private var busy = false12
private var delay = Duration.ZERO13
private var idleSince: MonotonicInstant? = None14
val deadline: MonotonicInstant? get() =15
when (idleSince) {16
case Some(val time) -> Some(time + delay)17
case None -> None18
}20
fun configure(21
available: Boolean,22
automatic: Boolean,23
delay: Duration,24
busy: Boolean,25
now: MonotonicInstant26
) {27
this.available = available28
this.automatic = automatic29
this.delay = delay30
this.busy = busy31
if (!available) {32
visible = false33
idleSince = None34
} else35
if (!automatic) {36
visible = true37
idleSince = None38
} else39
if (busy) {40
idleSince = None41
} else42
if (visible && idleSince == None) {43
idleSince = Some(now)44
}45
}47
fun wake(now: MonotonicInstant) {48
if (!available)49
return50
visible = true51
idleSince =52
if (automatic && !busy)53
Some(now)54
else55
None56
}58
fun expire(now: MonotonicInstant) {59
when (deadline) {60
case Some(val end) -> if (now >= end) {61
visible = false62
idleSince = None63
}64
case None -> {}65
}66
}67
}