From 25e5fdb279e3d0bc65cf248ba5183226074ceea5 Mon Sep 17 00:00:00 2001 From: Sebastiano Poggi Date: Wed, 6 Nov 2024 10:01:01 +0100 Subject: [PATCH] Allow configuring the ComposePanel via JewelComposePanel APIs (#673) This way one can do things like setting up manual disposing, etc. The change is binary-compatible as the default config is an empty block. --- ide-laf-bridge/api/ide-laf-bridge.api | 12 +++-- .../jewel/bridge/JewelComposePanel.kt | 53 +++++++++++-------- 2 files changed, 39 insertions(+), 26 deletions(-) diff --git a/ide-laf-bridge/api/ide-laf-bridge.api b/ide-laf-bridge/api/ide-laf-bridge.api index fcc54437f4..b9976a0525 100644 --- a/ide-laf-bridge/api/ide-laf-bridge.api +++ b/ide-laf-bridge/api/ide-laf-bridge.api @@ -65,10 +65,14 @@ public final class org/jetbrains/jewel/bridge/JewelBridgeException$KeysNotFoundE } public final class org/jetbrains/jewel/bridge/JewelComposePanelKt { - public static final fun JewelComposeNoThemePanel (Lkotlin/jvm/functions/Function2;)Ljavax/swing/JComponent; - 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 JewelToolWindowNoThemeComposePanel (Lkotlin/jvm/functions/Function2;)Ljavax/swing/JComponent; + public static final fun JewelComposeNoThemePanel (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljavax/swing/JComponent; + public static synthetic fun JewelComposeNoThemePanel$default (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)Ljavax/swing/JComponent; + public static final fun JewelComposePanel (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljavax/swing/JComponent; + public static synthetic fun JewelComposePanel$default (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)Ljavax/swing/JComponent; + public static final fun JewelToolWindowComposePanel (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljavax/swing/JComponent; + public static synthetic fun JewelToolWindowComposePanel$default (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)Ljavax/swing/JComponent; + public static final fun JewelToolWindowNoThemeComposePanel (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Ljavax/swing/JComponent; + public static synthetic fun JewelToolWindowNoThemeComposePanel$default (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)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 b5d05c3c75..82e31e9935 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 @@ -22,35 +22,41 @@ import org.jetbrains.jewel.foundation.ExperimentalJewelApi import org.jetbrains.jewel.foundation.InternalJewelApi @Suppress("ktlint:standard:function-naming", "FunctionName") // Swing to Compose bridge API -public fun JewelComposePanel(content: @Composable () -> Unit): JComponent = createJewelComposePanel { jewelPanel -> - setContent { - SwingBridgeTheme { - CompositionLocalProvider(LocalComponent provides this@createJewelComposePanel) { - ComponentDataProviderBridge(jewelPanel, content = content) +public fun JewelComposePanel(config: ComposePanel.() -> Unit = {}, content: @Composable () -> Unit): JComponent = + createJewelComposePanel { jewelPanel -> + config() + setContent { + SwingBridgeTheme { + CompositionLocalProvider(LocalComponent provides this@createJewelComposePanel) { + ComponentDataProviderBridge(jewelPanel, content = content) + } } } } -} @InternalJewelApi @Suppress("ktlint:standard:function-naming", "FunctionName") // Swing to Compose bridge API -public fun JewelToolWindowComposePanel(content: @Composable () -> Unit): JComponent = - createJewelComposePanel { jewelPanel -> - setContent { - Compose17IJSizeBugWorkaround { - SwingBridgeTheme { - CompositionLocalProvider(LocalComponent provides this@createJewelComposePanel) { - ComponentDataProviderBridge(jewelPanel, content = content) - } +public fun JewelToolWindowComposePanel( + config: ComposePanel.() -> Unit = {}, + content: @Composable () -> Unit, +): JComponent = createJewelComposePanel { jewelPanel -> + config() + setContent { + Compose17IJSizeBugWorkaround { + SwingBridgeTheme { + CompositionLocalProvider(LocalComponent provides this@createJewelComposePanel) { + ComponentDataProviderBridge(jewelPanel, content = content) } } } } +} @ExperimentalJewelApi @Suppress("ktlint:standard:function-naming", "FunctionName") // Swing to Compose bridge API -public fun JewelComposeNoThemePanel(content: @Composable () -> Unit): JComponent = +public fun JewelComposeNoThemePanel(config: ComposePanel.() -> Unit = {}, content: @Composable () -> Unit): JComponent = createJewelComposePanel { jewelPanel -> + config() setContent { CompositionLocalProvider(LocalComponent provides this@createJewelComposePanel) { ComponentDataProviderBridge(jewelPanel, content = content) @@ -60,16 +66,19 @@ public fun JewelComposeNoThemePanel(content: @Composable () -> Unit): JComponent @ExperimentalJewelApi @Suppress("ktlint:standard:function-naming", "FunctionName") // Swing to Compose bridge API -public fun JewelToolWindowNoThemeComposePanel(content: @Composable () -> Unit): JComponent = - createJewelComposePanel { jewelPanel -> - setContent { - Compose17IJSizeBugWorkaround { - CompositionLocalProvider(LocalComponent provides this@createJewelComposePanel) { - ComponentDataProviderBridge(jewelPanel, content = content) - } +public fun JewelToolWindowNoThemeComposePanel( + config: ComposePanel.() -> Unit = {}, + content: @Composable () -> Unit, +): JComponent = createJewelComposePanel { jewelPanel -> + config() + setContent { + Compose17IJSizeBugWorkaround { + CompositionLocalProvider(LocalComponent provides this@createJewelComposePanel) { + ComponentDataProviderBridge(jewelPanel, content = content) } } } +} private fun createJewelComposePanel(config: ComposePanel.(JewelComposePanel) -> Unit): JewelComposePanel { val jewelPanel = JewelComposePanel()