scoop:scoop.ui.component:0.1.0
src/toast/clock.scoop
Selected production source · src/toast/clock.scoop
1
package scoop.ui.component3
import scoop.platform.time.MonotonicInstant4
import scoop.time.*6
/** A paused clock retains the unused portion, independent of host mounting. */7
internal class ToastClock(duration: Duration?) {8
var remaining: Duration? = duration9
private var started: MonotonicInstant? = None10
val deadline: MonotonicInstant? get() =11
when ((started, remaining)) {12
case(Some(val time), Some(val value)) -> Some(time + value)13
else -> None14
}15
fun reset(duration: Duration?) {16
remaining = duration;17
started = None18
}19
fun pause(now: MonotonicInstant) {20
when (deadline) {21
case Some(val end) -> remaining =22
Some(23
if (end > now)24
end - now25
else26
Duration.ZERO27
)28
case None -> {}29
}30
started = None31
}32
fun resume(now: MonotonicInstant) {33
if (started == None && panelPresent(remaining))34
started = Some(now)35
}36
}