ckloss
12/01/2020, 9:11 PMIgor Demin
12/02/2020, 4:53 PMimport androidx.compose.desktop.AppWindowAmbient
import androidx.compose.desktop.Window
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.sizeIn
import androidx.compose.material.Text
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.onSizeChanged
import androidx.compose.ui.platform.AmbientDensity
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.unit.sp
import androidx.compose.ui.window.DesktopDialogProperties
import androidx.compose.ui.window.Dialog
fun main() = Window {
Dialog(
onDismissRequest = { },
properties = DesktopDialogProperties(
undecorated = true,
size = IntSize.Zero
),
) {
val window = AppWindowAmbient.current!!
val density = AmbientDensity.current
Box(
Modifier
.sizeIn(maxWidth = Dp.Infinity, maxHeight = Dp.Infinity)
.onSizeChanged {
with(density) {
window.setSize(
it.width.toDp().value.toInt(),
it.height.toDp().value.toInt()
)
window.window.isResizable = false
}
}
) {
Text("Text", style = TextStyle(fontSize = 300.sp))
}
}
}
For main Window we use something similar:
https://kotlinlang.slack.com/archives/C01D6HTPATV/p1605028146409100?thread_ts=1605021187.408600&cid=C01D6HTPATVckloss
12/02/2020, 10:45 PMckloss
12/02/2020, 10:52 PMIgor Demin
12/03/2020, 8:11 AMshould I open an issueIt will be better to open an issue, so people can track a progress.
this hack won't work with AlertDialog as we don't have an compose lambda where to use the hack, rightProbably yes, it isn't working, because we don't have access to the whole content.
all the others Window or Dialog opened after that continues to show in the main monitor.It looks like a bug. We can bypass it though:
val parentWindow = AppWindowAmbient.current!!.window
Dialog(
onDismissRequest = { },
) {
onActive {
AppWindowAmbient.current!!.window.setLocationRelativeTo(parentWindow)
}
}