azeDevs
04/11/2019, 2:38 AMprivate val apiThread = Worker.start()
private fun startUiLoop() {
apiThread.execute(TransferMode.SAFE, { Unit }) {
sleep(2000)
updateUi()
}.consume { startUiLoop() }
}
I'm stumped on the syntax here (or a K/N solution in general) for a simple timed interval loop. I have Windows C libraries implemented, if that changes things.kpgalligan
04/11/2019, 3:01 AMkpgalligan
04/11/2019, 3:04 AMazeDevs
04/11/2019, 3:10 AMprivate fun displayAppWindow() = appWindow("gearNet", 640, 480) {
val xrdApi: ClashBountyApi = ClashBountyImpl()
vbox {
hbox {
connectBtn = button(text = "Connect to GGXrd") {
action {
statusText.value = "Xrd is not connected."
if (xrdApi.connectToXrd()) {
statusText.value = "Xrd Connected!"
refreshBtn.enabled = true
}
}
}
statusText = textfield { readonly = true; value = "..." }
}
hbox {
vbox {
consoleText = textarea { readonly = true; stretchy = true; value = ""; }
refreshBtn = button(text = "Get lobby data") {
action {
logXrdData()
}
}
refreshBtn.enabled = false
}
vbox {
for (i in 0..7) {
guiApi.get(i).playerForm = group("") {
vbox {
hbox {
guiApi.get(i).playerCharacter = textfield { readonly = true; value = ""; enabled = false }
guiApi.get(i).playerMatchesPlayed = textfield { readonly = true; value = "- / -"; enabled = false }
textfield { readonly = true; value = "- W$"; enabled = false }
}
hbox {
guiApi.get(i).playerLoadPercent = progressbar { value = 0; enabled = false; visible = true }
}
}
}
}
}
}
}
startUiLoop()
}
I'm using this library to create my GUI: https://github.com/msink/kotlin-libui
the full startUiLoop()
function does a bit more, but for the sake of simplicity I figured ask something more specific. private fun startUiLoop() {
apiThread.execute(TransferMode.SAFE, { Unit }) {
logInfo("UI UPDATED")
if (xrdApi.isXrdRunning()) {
setAppStatus("Xrd is running.")
connectBtn.enabled = true
} else {
setAppStatus("Xrd is not running.")
connectBtn.enabled = false
}
sleep(2000)
startUiLoop()
}
}
olonho
04/11/2019, 6:44 AMazeDevs
04/11/2019, 6:59 AMmsink
04/11/2019, 7:24 AMfun onTimer(milliseconds: Int, block: () -> Boolean): Unit
import kotlinx.cinterop.*
import platform.posix.*
import libui.ktx.*
fun main(args: Array<String>) = appWindow(
title = "Hello",
width = 320,
height = 240
) {
vbox {
lateinit var scroll: TextArea
button("Say Something") {
action {
scroll.append("Saying something\n")
}
}
scroll = textarea {
readonly = true
stretchy = true
}
onTimer(1000) {
memScoped {
val now = alloc<time_tVar>().apply { value = time(null) }
val str = ctime(now.ptr)!!.toKString()
if (!scroll.disposed) scroll.append(str)
}
true
}
}
}
msink
04/11/2019, 7:29 AMtrue
to repeat and false
to stop.olonho
04/11/2019, 8:46 AM