Hi All, Is there any way to set minimum window siz...
# compose-desktop
b
Hi All, Is there any way to set minimum window size ?
j
You should be able to hoist the window size state up, and then you are in full control of the window size. You can thus programmatically manage the size (minimums, maximums, maintain an aspect ratio, or whatever you want to do).
i
Actually, we can't be in full control of the windows size, only window manager can. So even if we programmatically coerce size, user will see some visual glitches (see the video, in the first frame - the window manager changes the size, and in the second frame - we restore it) If you need to set the minimum size, you have to switch to the Swing API (we haven't yet Swing-independent API for a minimum size)
Copy code
import androidx.compose.desktop.ComposeWindow
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.application
import java.awt.Dimension
import java.awt.event.WindowAdapter
import java.awt.event.WindowEvent

@OptIn(ExperimentalComposeUiApi::class)
fun main() = application {
    var isOpen by remember { mutableStateOf(true) }

    if (isOpen) {
        Window(
            create = {
                ComposeWindow().apply {
                    size = Dimension(600, 600)
                    minimumSize = Dimension(400, 400)
                    addWindowListener(object : WindowAdapter() {
                        override fun windowClosing(e: WindowEvent?) {
                            isOpen = false
                        }
                    })
                }
            },
            dispose = ComposeWindow::dispose
        ) {

        }
    }
}
(not sure if it will work on all platforms). Another approach - is to implement a window with your own decorations (undecorated = true)
👍 1
b
Its working in windows but I found the minimum window size is not correct with the given minimum size. The minimum window size is much lesser than given min size.
s
Oh, not so good news 😕
j
If this is still true, please file a bug
s
@jim Why is it a bug? Should it work now? I see no API to define that... https://github.com/JetBrains/compose-jb/tree/master/tutorials/Window_API_new
j
Oh, nevermind, maybe not. Maybe I misunderstood, let me sync with some folks and get their thoughts here.
👍 1