xetra11
11/24/2020, 11:58 AM@Composable
fun CharacterModuleView() {
Button(
onClick = {
LOG().info("clicked")
}
){
Text("Import Characters")
}
}
When clicking the button I'd like to open a new window like a dialog-popup to ask the user for a file path. I tried to put a "Window" in there which did not work. However there is a way to do that I assume eh?ckloss
11/24/2020, 12:00 PMIgor Demin
11/24/2020, 12:40 PMimport androidx.compose.desktop.AppWindowAmbient
import androidx.compose.desktop.Window
import androidx.compose.material.Button
import androidx.compose.material.Text
fun main() = Window {
val window = AppWindowAmbient.current!!
Button(onClick = {
java.awt.FileDialog(window.window).isVisible = true
}) {
Text("Button")
}
}
xetra11
11/24/2020, 1:23 PMxetra11
11/24/2020, 1:28 PM@Composable
fun CharacterModuleView() {
Button(
onClick = {
FileDialog(AppWindowAmbient.current!!.window).isVisible = true
}
){
Text("Import Characters")
}
}
Renders the following error:
e: /home/xetra11/Development/projects/CK3-Workbench/src/main/kotlin/com/github/xetra11/ck3workbench/module/character/view/CharacterModuleView.kt: (32, 41): @Composable invocations can only happen from the context of a @Composable function
Is soemthing missing?Igor Demin
11/24/2020, 1:29 PMAppWindowAmbient.current
Should be called outside of onClick callback