From afe24b95bc7a2a09030939c75954dd835d8c6dc6 Mon Sep 17 00:00:00 2001 From: Francisco N <4259909+francisconoriega@users.noreply.github.com> Date: Fri, 2 Aug 2024 15:10:51 -0600 Subject: [PATCH] Compose 1.7 FillMaxSize+Jpanels Workaround (#509) * Compose 1.7 FillMaxSize+Jpanels Workaround * Fix klint formatting * Fix detektmain issue --------- Co-authored-by: Francisco Noriega --- .../jewel/bridge/JewelComposePanel.kt | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) 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 958bee223e..674337e048 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 @@ -1,10 +1,16 @@ package org.jetbrains.jewel.bridge +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.requiredSize import androidx.compose.runtime.Composable import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.runtime.ProvidableCompositionLocal import androidx.compose.runtime.staticCompositionLocalOf +import androidx.compose.ui.Modifier import androidx.compose.ui.awt.ComposePanel +import androidx.compose.ui.platform.LocalDensity +import androidx.compose.ui.platform.LocalWindowInfo +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 @@ -14,9 +20,11 @@ import javax.swing.JComponent public fun JewelComposePanel(content: @Composable () -> Unit): JComponent = ComposePanel().apply { setContent { - SwingBridgeTheme { - CompositionLocalProvider(LocalComponent provides this@apply) { - ComponentDataProviderBridge(this@apply, content = content) + Compose17IJSizeBugWorkaround { + SwingBridgeTheme { + CompositionLocalProvider(LocalComponent provides this@apply) { + ComponentDataProviderBridge(this@apply, content = content) + } } } } @@ -27,3 +35,17 @@ public val LocalComponent: ProvidableCompositionLocal = staticCompositionLocalOf { error("CompositionLocal LocalComponent not provided") } + +/** + * 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) { + with(LocalDensity.current) { + Box(modifier = Modifier.requiredSize(LocalWindowInfo.current.containerSize.toSize().toDpSize())) { + content() + } + } +}