diff --git a/core/src/main/kotlin/org/jetbrains/jewel/styling/ResourcePainterProvider.kt b/core/src/main/kotlin/org/jetbrains/jewel/styling/ResourcePainterProvider.kt index 60c8e720c..0ba415ec1 100644 --- a/core/src/main/kotlin/org/jetbrains/jewel/styling/ResourcePainterProvider.kt +++ b/core/src/main/kotlin/org/jetbrains/jewel/styling/ResourcePainterProvider.kt @@ -36,8 +36,10 @@ open class ResourcePainterProvider @InternalJewelApi constructor( basePath: String, resourceLoader: ResourceLoader, extraData: T?, - ): String = - pathPatcher.patchPath(basePath, resourceLoader, extraData) + ): String { + val patched = pathPatcher.patchVariant(basePath, resourceLoader, extraData) + return pathPatcher.patchTheme(patched, resourceLoader) + } override fun equals(other: Any?): Boolean { if (this === other) return true diff --git a/core/src/main/kotlin/org/jetbrains/jewel/styling/ResourcePathPatcher.kt b/core/src/main/kotlin/org/jetbrains/jewel/styling/ResourcePathPatcher.kt index 14a91ccf2..1974a9b92 100644 --- a/core/src/main/kotlin/org/jetbrains/jewel/styling/ResourcePathPatcher.kt +++ b/core/src/main/kotlin/org/jetbrains/jewel/styling/ResourcePathPatcher.kt @@ -6,5 +6,8 @@ import androidx.compose.ui.res.ResourceLoader interface ResourcePathPatcher { @Composable - fun patchPath(basePath: String, resourceLoader: ResourceLoader, extraData: T?): String + fun patchVariant(basePath: String, resourceLoader: ResourceLoader, extraData: T?): String + + @Composable + fun patchTheme(basePath: String, resourceLoader: ResourceLoader): String } diff --git a/core/src/main/kotlin/org/jetbrains/jewel/styling/SimpleResourcePathPatcher.kt b/core/src/main/kotlin/org/jetbrains/jewel/styling/SimpleResourcePathPatcher.kt index 83ea93361..072f81164 100644 --- a/core/src/main/kotlin/org/jetbrains/jewel/styling/SimpleResourcePathPatcher.kt +++ b/core/src/main/kotlin/org/jetbrains/jewel/styling/SimpleResourcePathPatcher.kt @@ -7,24 +7,35 @@ import org.jetbrains.jewel.LocalIsDarkTheme open class SimpleResourcePathPatcher : ResourcePathPatcher { @Composable - final override fun patchPath(basePath: String, resourceLoader: ResourceLoader, extraData: T?) = + final override fun patchVariant(basePath: String, resourceLoader: ResourceLoader, extraData: T?) = buildString { append(basePath.substringBeforeLast('/', "")) append('/') append(basePath.substringBeforeLast('.').substringAfterLast('/')) - append(injectAdditionalTokens(extraData)) + append(injectVariantTokens(extraData)) - // TODO load HiDPI rasterized images ("@2x") - // TODO load sized SVG images (e.g., "@20x20") - - if (LocalIsDarkTheme.current) { - append("_dark") - } append('.') append(basePath.substringAfterLast('.')) } @Composable - protected open fun injectAdditionalTokens(extraData: T? = null): String = "" + final override fun patchTheme(basePath: String, resourceLoader: ResourceLoader): String = buildString { + append(basePath.substringBeforeLast('/', "")) + append('/') + append(basePath.substringBeforeLast('.').substringAfterLast('/')) + + // TODO load HiDPI rasterized images ("@2x") + // TODO load sized SVG images (e.g., "@20x20") + + if (LocalIsDarkTheme.current) { + append("_dark") + } + + append('.') + append(basePath.substringAfterLast('.')) + } + + @Composable + protected open fun injectVariantTokens(extraData: T? = null): String = "" } diff --git a/core/src/main/kotlin/org/jetbrains/jewel/styling/StatefulResourcePathPatcher.kt b/core/src/main/kotlin/org/jetbrains/jewel/styling/StatefulResourcePathPatcher.kt index 3786914c7..6291d40cc 100644 --- a/core/src/main/kotlin/org/jetbrains/jewel/styling/StatefulResourcePathPatcher.kt +++ b/core/src/main/kotlin/org/jetbrains/jewel/styling/StatefulResourcePathPatcher.kt @@ -12,7 +12,7 @@ class StatefulResourcePathPatcher( ) : SimpleResourcePathPatcher() { @Composable - override fun injectAdditionalTokens(extraData: T?): String = buildString { + override fun injectVariantTokens(extraData: T?): String = buildString { if (extraData == null) return@buildString append(prefixTokensProvider(extraData)) diff --git a/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/BridgeResourcePainterProvider.kt b/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/BridgeResourcePainterProvider.kt index 82c271645..973a42404 100644 --- a/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/BridgeResourcePainterProvider.kt +++ b/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/BridgeResourcePainterProvider.kt @@ -15,7 +15,7 @@ import org.jetbrains.jewel.styling.StatefulResourcePathPatcher internal class BridgeResourcePainterProvider @InternalJewelApi constructor( basePath: String, svgLoader: SvgLoader, - pathPatcher: ResourcePathPatcher, + private val pathPatcher: ResourcePathPatcher, private val iconMapper: IconMapper, private val iconData: IntelliJThemeIconData, ) : ResourcePainterProvider(basePath, svgLoader, pathPatcher) { @@ -26,8 +26,9 @@ internal class BridgeResourcePainterProvider @InternalJewelApi constructor( resourceLoader: ResourceLoader, extraData: T?, ): String { - val patchedPath = super.patchPath(basePath, resourceLoader, extraData) - return iconMapper.mapPath(patchedPath, iconData, resourceLoader) + val patched = pathPatcher.patchVariant(basePath, resourceLoader, extraData) + val override = iconMapper.mapPath(patched, iconData, resourceLoader) + return pathPatcher.patchTheme(override, resourceLoader) } companion object Factory {