Skip to content

Commit

Permalink
Fix checkbox and radio button style in IDE dark theme
Browse files Browse the repository at this point in the history
  • Loading branch information
devkanro committed Oct 13, 2023
1 parent 4182940 commit f57da0d
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ open class ResourcePainterProvider<T> @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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@ import androidx.compose.ui.res.ResourceLoader
interface ResourcePathPatcher<T> {

@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
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,35 @@ import org.jetbrains.jewel.LocalIsDarkTheme
open class SimpleResourcePathPatcher<T> : ResourcePathPatcher<T> {

@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 = ""
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class StatefulResourcePathPatcher<T : InteractiveComponentState>(
) : SimpleResourcePathPatcher<T>() {

@Composable
override fun injectAdditionalTokens(extraData: T?): String = buildString {
override fun injectVariantTokens(extraData: T?): String = buildString {
if (extraData == null) return@buildString

append(prefixTokensProvider(extraData))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import org.jetbrains.jewel.styling.StatefulResourcePathPatcher
internal class BridgeResourcePainterProvider<T> @InternalJewelApi constructor(
basePath: String,
svgLoader: SvgLoader,
pathPatcher: ResourcePathPatcher<T>,
private val pathPatcher: ResourcePathPatcher<T>,
private val iconMapper: IconMapper,
private val iconData: IntelliJThemeIconData,
) : ResourcePainterProvider<T>(basePath, svgLoader, pathPatcher) {
Expand All @@ -26,8 +26,9 @@ internal class BridgeResourcePainterProvider<T> @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 {
Expand Down

0 comments on commit f57da0d

Please sign in to comment.