My post will need some more time, so here is the c...
# compose-desktop
t
My post will need some more time, so here is the code I use in my app TKDupeFinder to create the movable
AlertDialog
. As you can see the code makes a couple of assumptions, that's why I call it a hack. 🙂 For example: will
AppManager.windows.last().window
really always refer to the dialog? Also, upon recompositions we may get unwanted double listener registrations, so I need to make sure the listeners are set only if needed (will likely use client properties). Finally, clicking and dragging inteferes with normal Compose behavior. So, again, in this version it's a hack, yet a cool one.
if (isConfirmDialogVisible.value) {
AlertDialog(onDismissRequest = {
isConfirmDialogVisible.value = false
},
properties = DesktopDialogProperties(undecorated = true),
modifier = Modifier.border(width = 1.dp,
MaterialTheme.colors.primary),
title = {
Text(RESOURCE_BUNDLE.getString("confirm_deletion"))
},
text = {
ScrollableColumn {
val sb = StringBuilder()
selectedFiles.forEach {
sb.append(checksums[currentPos], it.name).appendLine()
}
Text(sb.toString())
}
},
dismissButton = {
Button(onClick = {
isConfirmDialogVisible.value = false
}) {
Text(RESOURCE_BUNDLE.getString("cancel"))
}
},
confirmButton = {
Button(onClick = {
isConfirmDialogVisible.value = false
selectedFiles.forEach {
df.deleteFile(checksums[currentPos], it)
}
selected.clear()
}) {
Text(RESOURCE_BUNDLE.getString("delete"))
}
})
val window = AppManager.windows.last().window
val component = window.contentPane.getComponent(0)
val adapter = object : MouseInputAdapter() {
private lateinit var initialClick: Point
override fun mousePressed(e: MouseEvent) {
initialClick = e.point
}
override fun mouseDragged(e: MouseEvent) {
val dx = e.x - initialClick.x
val dy = e.y - initialClick.y
window.setLocation(window.location.x + dx,
window.location.y + dy)
}
}
component.addMouseMotionListener(adapter)
component.addMouseListener(adapter)
}