From 87379de4b6d6b94b2206eb04f5e920760b13d99d Mon Sep 17 00:00:00 2001 From: Ivan Matkov Date: Wed, 17 Jan 2024 19:10:21 +0100 Subject: [PATCH] Fix tests --- .../kotlin/androidx/compose/ui/awt/ComposePanel.desktop.kt | 2 +- .../androidx/compose/ui/awt/ComposeWindowPanel.desktop.kt | 2 +- .../androidx/compose/ui/scene/ComposeContainer.desktop.kt | 7 ++++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/awt/ComposePanel.desktop.kt b/compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/awt/ComposePanel.desktop.kt index 198be4444c081..62cf0c469ac59 100644 --- a/compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/awt/ComposePanel.desktop.kt +++ b/compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/awt/ComposePanel.desktop.kt @@ -121,8 +121,8 @@ class ComposePanel @ExperimentalComposeUiApi constructor( } override fun setBounds(x: Int, y: Int, width: Int, height: Int) { - _composeContainer?.setBounds(0, 0, width, height) super.setBounds(x, y, width, height) + _composeContainer?.setBounds(0, 0, width, height) } override fun getPreferredSize(): Dimension? = if (isPreferredSizeSet) { diff --git a/compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/awt/ComposeWindowPanel.desktop.kt b/compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/awt/ComposeWindowPanel.desktop.kt index f3fde982c3625..c628730259471 100644 --- a/compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/awt/ComposeWindowPanel.desktop.kt +++ b/compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/awt/ComposeWindowPanel.desktop.kt @@ -128,8 +128,8 @@ internal class ComposeWindowPanel( } override fun setBounds(x: Int, y: Int, width: Int, height: Int) { - composeContainer.setBounds(0, 0, width, height) super.setBounds(x, y, width, height) + composeContainer.setBounds(0, 0, width, height) } override fun add(component: Component): Component { diff --git a/compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/scene/ComposeContainer.desktop.kt b/compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/scene/ComposeContainer.desktop.kt index b717caf29c487..3db1aa9fd10ed 100644 --- a/compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/scene/ComposeContainer.desktop.kt +++ b/compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/scene/ComposeContainer.desktop.kt @@ -161,6 +161,8 @@ internal class ComposeContainer( } private fun onChangeWindowBounds() { + if (!container.isDisplayable) return + windowContext.setContainerSize(windowContainer.sizeInPx) layers.fastForEach(DesktopComposeSceneLayer::onChangeWindowBounds) } @@ -183,6 +185,9 @@ internal class ComposeContainer( fun addNotify() { mediator.onComponentAttached() setWindow(SwingUtilities.getWindowAncestor(container)) + + // Re-checking the actual size if it wasn't available during init. + onChangeWindowBounds() } fun removeNotify() { @@ -207,7 +212,7 @@ internal class ComposeContainer( } this.window?.removeWindowFocusListener(this) - window?.addComponentListener(this) + window?.addWindowFocusListener(this) this.window = window onChangeWindowFocus()