https://kotlinlang.org logo
#doodle
Title
# doodle
m

M.C. Escher

03/29/2024, 4:56 PM
my code with the modal menu popup now looks like this:
Copy code
class MyApp(
    private val uiDispatcher: CoroutineDispatcher, ...
) : Application, CoroutineScope by CoroutineScope(SupervisorJob() + Dispatchers.Default) {
    init {
        launch {                 // <-- new
            loadFonts()          // <-- new

            val button = ToggleButton().apply {
                font = defaultFont
                pointerChanged += PointerListener.pressed {
                    if (Button2 in it.buttons) {
                        it.consume()
                        val popupLocation = it.location

                        launch(uiDispatcher) {
                            println("show menu")  // <-- never excuted
                            modal {
                               ...
                            }
                        }
                    }
                }
            }
            ...
        }
    }
}
so basically i've moved everything inside that outer`launch`-block and added a
loadFonts()
call which is similar to code in the example projects. however, now the modal is not shown any more, the
show menu
println never gets executed when i right-click on the button. when i move the code below
loadFonts()
outside of the outer
launch
then the popup's working again, but then my font might not yet be loaded
n

Nick

03/29/2024, 7:49 PM
will take a look later tonight
❤️ 1
m

M.C. Escher

03/29/2024, 8:15 PM
thanks, no need. i understand now what i did wrong. when i call the inner
launch
it calls it from the coroutinescope of the outer
launch
, but as soon as the execution returns from that outer scope, kotlin cancels all 'inner' jobs ("structured concurrency")... i must make sure i call the inner launch using
this@MyApp.launch {}