Skip to content

Commit

Permalink
Only apply workaround to CMP-5856 in toolwindows (#516)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rock3r authored Aug 5, 2024
1 parent 124f1bf commit 68721cf
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions ide-laf-bridge/api/ide-laf-bridge.api
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -37,9 +51,9 @@ public val LocalComponent: ProvidableCompositionLocal<JComponent> =
}

/**
* 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public fun ToolWindow.addComposeTab(

val tabContent =
contentManager.factory.createContent(
JewelComposePanel {
JewelToolWindowComposePanel {
val scope =
object : ToolWindowScope {
override val toolWindow: ToolWindow
Expand Down

0 comments on commit 68721cf

Please sign in to comment.