``` private fun showImagePopup(photo: Photo) { ...
# tornadofx
r
Copy code
private fun showImagePopup(photo: Photo) {
        runAsync {
            ImageView(Image(photo.toURL().toExternalForm()))
        } ui {

            var height: Double
            var width: Double

            val visualBounds = Screen.getPrimary().visualBounds
            val screenRatio = visualBounds.width / visualBounds.height
            if (it.image.ratio() <= screenRatio) {
                // The scaled size is based on the height
                height = Math.min(visualBounds.height, it.image.height)
                width = height * it.image.ratio()
            } else {
                // The scaled size is based on the width
                width = Math.min(visualBounds.width, it.image.width)
                height = width / it.image.ratio()
            }

            builderWindow {
                stackpane {
                    prefWidth = width
                    prefHeight = height
                    it.apply {
                        fitHeightProperty().bind(this@stackpane.heightProperty())
                        fitWidthProperty().bind(this@stackpane.widthProperty())
                    }
                    add(it)
                }
            }
        }
    }
👍 1