```with(LocalDensity.current) { window.minimum...
# compose-desktop
s
Copy code
with(LocalDensity.current) {
    window.minimumSize = Dimension(400.dp.roundToPx(), 250.dp.roundToPx())
}
Is there a way to subscribe to the local density as state so that if it changes it triggers a re-draw?
d
Short answer is yes.
snapshotFlow { LocalDensity.current }.collectAsState()
is one way but might not be the right one for you. It depends on what the re-draw code looks like.
s
interesting
snapshotFlow
’s lambda isn’t a
@Composable
, so that doesn’t work exactly.
d
Ah, I see. What does the re-draw look like? Is it a canvas?
a
Your code will already recompose when the density changes as
LocalDensity
is a
CompositionLocal
.
s
It doesn’t appear that it does. i.e. here is what I’m doing:
Copy code
with(LocalDensity.current) {
    window.minimumSize = Dimension(400.dp.roundToPx(), 250.dp.roundToPx())
}
The minimum sizes were drastically different when I was moving between my monitors.
a
That means
LocalDensity.current
did change and isn't that what you want?
i
JFrame (ComposeWindow) is already works with scaled pixels, and should automatically react to density changes. You only need to set the minimum size at startup:
Copy code
DisposableEffect(Unit) {
  window.minimumSize = Dimension(400, 250)
  onDispose {}
}