Hello, is there a way in jetpack compose to adjust...
# compose-desktop
n
Hello, is there a way in jetpack compose to adjust the window size to the content size? I tried the onGloballyPosionated modifier, but it only works when the window is already visible. If the window is too small from the start, it takes these values in the modifier. I plan to calculate the window size and adjust the position according to the content size. Unfortunately, it doesn't look nice when the window is already visible and then adjusts itself.
Copy code
Box(modifier = Modifier.fillMaxWidth().onGloballyPositioned { layoutCoordinates ->
    val manager = AppWindowAmbient.current //AppManager.focusedWindow
    windowSize = IntSize(
        layoutCoordinates.size.width,
        layoutCoordinates.size.height
    )
    manager?.setSize(windowSize.width, windowSize.height)
}) { ... }
Thank you!
t
You can specify the window size and location in the WIndow function. But of course this is before the UI is rendered. Maybe you could start with a Window with size 0,0 and than draw the content into a box with modifier Modifier.wrapContentSize().onGloballyPositioned { .... The wrapContentSize modifier allow the content to be drawn at desired size. So you are able to measure the content size
i
Maybe you could start with a Window with size 0,0
Probably macOs will not call composition at all with this size, so we should use size (1,1) 😄 . Setting size of the window by its content is a known problem. We will figure something out in the future, how we can support this. Probably we will provide a special window parameter and will start composition before starting the window.
n
Many Thanks! It seems to work. I look forward to the future of Jetpack Compose for the desktop. it's just great. Thanks for your hard work! 😃