Dirk Hoffmann
05/25/2021, 6:41 PMLocalAppWindow.current.(width|height)
are of datatype Int
but represent height|width in Dp
... so if you wanna have e.g. the window width in Float to compare it to a Size
or Offset
you have to do LocalAppWindow.current.width * LocalDensity.current.density
Even more at the "root" of all Apps:
fun main() = Window(title = "Compose for Desktop", size = IntSize(300, 300)) {
The window doesn't have an IntSize of 300, 300 ... in fact it has a DpSize of 300, 300 and an IntSize(600, 600)
(if density == 2.0f)Kirill Grouchnikov
05/25/2021, 8:08 PMBrian G
05/25/2021, 8:25 PMDp
? Everywhere else in the Compose API dimensions are given in Dp
Kirill Grouchnikov
05/25/2021, 8:28 PMsize
parameter in the Window
composable, you'll probably want to make sure that the initial size matches the display size (percentage wise, or at least doesn't overflow the width and / or height). I don't think Compose has APIs to get the dp size of all the available screens, at least not in the desktop edition. So you'd still be doing dp to pixel conversion, just in a different place in your code.Brian G
05/25/2021, 8:32 PMWindow
composable. Since it is treated as dp, why not type it Dp
to make the API more self-documenting?uli
05/25/2021, 8:39 PMInt
but the semantics is Dp
Kirill Grouchnikov
05/25/2021, 9:04 PMIntSize
values are passed directly to java.awt.Window.setSize
in https://github.com/androidx/androidx/blob/androidx-main/compose/ui/ui/src/desktopMain/kotlin/androidx/compose/desktop/AppWindow.desktop.kt#L392 and that is one of the few places that https://openjdk.java.net/jeps/263 covered - the conversion to "real" pixels happens under the hood.uli
05/25/2021, 9:18 PMKirill Grouchnikov
05/25/2021, 9:21 PMfun main() {
SwingUtilities.invokeLater {
val appWindow = AppWindow(
title = "My title",
size = IntSize(400, 300),
location = IntOffset.Zero,
centered = true,
icon = null,
menuBar = null,
undecorated = false,
resizable = true,
events = WindowEvents(),
onDismissRequest = null
)
appWindow.show {
}
println("Requested compose window width was 400")
val composeWindow = appWindow.window
println("On-screen AWT window width is ${composeWindow.size.width}")
}
}
java.awt.Window.getSize()
is 400, even though the window on a 2x retina display is 800x600 pixelsBufferedImage
that you create will need to account for the display density. So you essentially draw a JFrame
that declares itself a 400x300 pixels into a BufferedImage
that is 800x600 pixels. Because otherwise you lose all that detail.Dirk Hoffmann
05/25/2021, 9:32 PMonGloballyPositioned()
callback of the component under which it should appear.
THEN I have to determinine how much space I have for the popup ... that is windowWidth - offset and windowHeight - offset.
And the calculations are just nasty if one of them is in Dp and the other in Float ...
On top that I have to care for how heigh the window title is (which both is oh not so plain to see from when you're "said" that LocalAppWindow.current.height
is your friend 🙂Kirill Grouchnikov
05/25/2021, 9:34 PMDirk Hoffmann
05/25/2021, 9:37 PMWindow
parameter from IntSize to width: Dp, height: Dp (letting height be the content I as a developer will have available (= contentHeight in Dp)
b) introduce additional fields in LocalAppWindow.current for
• contentHeight: Float // height without the title
• contentWidth: FloatBrian G
05/26/2021, 12:57 AMIgor Demin
05/26/2021, 7:46 AMchange theWe done this in the new API (that is not available yet)parameter from IntSize to width: Dp, height: DpWindow
b) introduce additional fields in LocalAppWindow.current forvariants without accessing window directly didn't work? Probably it is better to use them instead of
AppWindow
.
Imagine, you have a "custom" window that is not a window at all, but some Box with shadow 🙂 .Michael Paus
05/26/2021, 12:13 PMDirk Hoffmann
05/26/2021, 12:17 PMMichael Paus
05/26/2021, 12:29 PM