diff --git a/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/ComposePanel.kt b/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/ComposePanel.kt index bad0ccbb5..0960dfc98 100644 --- a/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/ComposePanel.kt +++ b/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/ComposePanel.kt @@ -4,25 +4,11 @@ import androidx.compose.runtime.Composable import androidx.compose.ui.awt.ComposePanel import com.intellij.openapi.wm.ToolWindow -fun ToolWindow.addComposePanel( +fun ToolWindow.addComposeTab( tabDisplayName: String, isLockable: Boolean = true, - content: @Composable ComposePanel.() -> Unit, -) = ComposePanel { - content() -}.also { contentManager.addContent(contentManager.factory.createContent(it, tabDisplayName, isLockable)) } + content: @Composable () -> Unit, +) = ComposePanel() + .apply { setContent(content) } + .also { contentManager.addContent(contentManager.factory.createContent(it, tabDisplayName, isLockable)) } -internal fun ComposePanel( - height: Int = 800, - width: Int = 800, - y: Int = 0, - x: Int = 0, - content: @Composable ComposePanel.() -> Unit, -): ComposePanel { - val panel = ComposePanel() - panel.setBounds(x, y, width, height) - panel.setContent { - panel.content() - } - return panel -} diff --git a/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/SwingBridgeTheme.kt b/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/SwingBridgeTheme.kt index c0b52d4fb..5182b5243 100644 --- a/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/SwingBridgeTheme.kt +++ b/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/SwingBridgeTheme.kt @@ -1,10 +1,15 @@ package org.jetbrains.jewel.bridge import androidx.compose.runtime.Composable +import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue +import androidx.compose.ui.res.ResourceLoader import com.intellij.openapi.components.service +import com.intellij.util.ui.DirProvider import org.jetbrains.jewel.ExperimentalJewelApi +import org.jetbrains.jewel.LocalResourceLoader +import org.jetbrains.jewel.themes.intui.standalone.IntUiDefaultResourceLoader import org.jetbrains.jewel.themes.intui.standalone.IntUiTheme private val bridgeService = service() @@ -15,5 +20,19 @@ fun SwingBridgeTheme(content: @Composable () -> Unit) { val themeData by bridgeService.currentBridgeThemeData.collectAsState() // TODO handle non-Int UI themes, too - IntUiTheme(themeData.themeDefinition, themeData.componentStyling, swingCompatMode = true, content) + IntUiTheme(themeData.themeDefinition, themeData.componentStyling, swingCompatMode = true) { + CompositionLocalProvider(LocalResourceLoader provides IntelliJResourceLoader) { + content() + } + } +} + +object IntelliJResourceLoader : ResourceLoader { + + private val dirProvider = DirProvider() + + override fun load(resourcePath: String) = + IntUiDefaultResourceLoader.loadOrNull(resourcePath) + ?: IntUiDefaultResourceLoader.load(resourcePath.removePrefix(dirProvider.dir())) + } diff --git a/samples/ide-plugin/src/main/kotlin/org/jetbrains/jewel/samples/ideplugin/JewelDemoToolWindow.kt b/samples/ide-plugin/src/main/kotlin/org/jetbrains/jewel/samples/ideplugin/JewelDemoToolWindow.kt index cf422b122..9364f52f0 100644 --- a/samples/ide-plugin/src/main/kotlin/org/jetbrains/jewel/samples/ideplugin/JewelDemoToolWindow.kt +++ b/samples/ide-plugin/src/main/kotlin/org/jetbrains/jewel/samples/ideplugin/JewelDemoToolWindow.kt @@ -30,7 +30,7 @@ import org.jetbrains.jewel.OutlinedButton import org.jetbrains.jewel.Text import org.jetbrains.jewel.TextField import org.jetbrains.jewel.bridge.SwingBridgeTheme -import org.jetbrains.jewel.bridge.addComposePanel +import org.jetbrains.jewel.bridge.addComposeTab import org.jetbrains.jewel.bridge.toComposeColor import org.jetbrains.jewel.themes.intui.standalone.IntUiTheme @@ -39,7 +39,7 @@ internal class JewelDemoToolWindow : ToolWindowFactory, DumbAware { @OptIn(ExperimentalJewelApi::class) override fun createToolWindowContent(project: Project, toolWindow: ToolWindow) { - toolWindow.addComposePanel("Jewel") { + toolWindow.addComposeTab("Jewel") { SwingBridgeTheme { val resourceLoader = LocalResourceLoader.current val bgColor by remember(IntUiTheme.isDark) { mutableStateOf(JBColor.PanelBackground.toComposeColor()) }