From 68721cfbd1657b2a70108bdcc21d0c28756edd93 Mon Sep 17 00:00:00 2001 From: Sebastiano Poggi Date: Mon, 5 Aug 2024 12:49:07 +0200 Subject: [PATCH] Only apply workaround to CMP-5856 in toolwindows (#516) This workaround should not be applied to _all_ JewelComposePanels, since it breaks auto-sizing for the panels based on their contents. This change creates a separate JewelToolWindowComposePanel that can be used for ToolWindows only, and removes the workaround from all other panels. --- ide-laf-bridge/api/ide-laf-bridge.api | 1 + .../jewel/bridge/JewelComposePanel.kt | 20 ++++++++++++++++--- .../jewel/bridge/ToolWindowExtensions.kt | 2 +- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/ide-laf-bridge/api/ide-laf-bridge.api b/ide-laf-bridge/api/ide-laf-bridge.api index f9567c2ef..471e5622e 100644 --- a/ide-laf-bridge/api/ide-laf-bridge.api +++ b/ide-laf-bridge/api/ide-laf-bridge.api @@ -65,6 +65,7 @@ public final class org/jetbrains/jewel/bridge/JewelBridgeException$KeysNotFoundE public final class org/jetbrains/jewel/bridge/JewelComposePanelKt { public static final fun JewelComposePanel (Lkotlin/jvm/functions/Function2;)Ljavax/swing/JComponent; + public static final fun JewelToolWindowComposePanel (Lkotlin/jvm/functions/Function2;)Ljavax/swing/JComponent; public static final fun getLocalComponent ()Landroidx/compose/runtime/ProvidableCompositionLocal; } diff --git a/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/JewelComposePanel.kt b/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/JewelComposePanel.kt index 674337e04..7963a226d 100644 --- a/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/JewelComposePanel.kt +++ b/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/JewelComposePanel.kt @@ -14,10 +14,24 @@ import androidx.compose.ui.unit.toSize import org.jetbrains.jewel.bridge.actionSystem.ComponentDataProviderBridge import org.jetbrains.jewel.bridge.theme.SwingBridgeTheme import org.jetbrains.jewel.foundation.ExperimentalJewelApi +import org.jetbrains.jewel.foundation.InternalJewelApi import javax.swing.JComponent @Suppress("ktlint:standard:function-naming", "FunctionName") // Swing to Compose bridge API public fun JewelComposePanel(content: @Composable () -> Unit): JComponent = + ComposePanel().apply { + setContent { + SwingBridgeTheme { + CompositionLocalProvider(LocalComponent provides this@apply) { + ComponentDataProviderBridge(this@apply, content = content) + } + } + } + } + +@InternalJewelApi +@Suppress("ktlint:standard:function-naming", "FunctionName") // Swing to Compose bridge API +public fun JewelToolWindowComposePanel(content: @Composable () -> Unit): JComponent = ComposePanel().apply { setContent { Compose17IJSizeBugWorkaround { @@ -37,9 +51,9 @@ public val LocalComponent: ProvidableCompositionLocal = } /** - * Workaround until the issue with Compose 1.7 + fillMax__ + IntelliJ Panels is fixed: - * https://github.com/JetBrains/jewel/issues/504 - * https://youtrack.jetbrains.com/issue/CMP-5856 + * Workaround until the issue with Compose 1.7 + fillMax__ + IntelliJ + * Panels is fixed: https://github.com/JetBrains/jewel/issues/504 + * https://youtrack.jetbrains.com/issue/CMP-5856. */ @Composable private fun Compose17IJSizeBugWorkaround(content: @Composable () -> Unit) { diff --git a/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/ToolWindowExtensions.kt b/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/ToolWindowExtensions.kt index e29c0e52c..ef38d6192 100644 --- a/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/ToolWindowExtensions.kt +++ b/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/ToolWindowExtensions.kt @@ -17,7 +17,7 @@ public fun ToolWindow.addComposeTab( val tabContent = contentManager.factory.createContent( - JewelComposePanel { + JewelToolWindowComposePanel { val scope = object : ToolWindowScope { override val toolWindow: ToolWindow