From 0e039d8dc6e45246e276c00f0dd1a5c911ecbeae Mon Sep 17 00:00:00 2001 From: caixuan Date: Sat, 17 Feb 2024 19:20:03 +0800 Subject: [PATCH 1/2] Fix remembers painter twice to break the cache --- foundation/api/foundation.api | 4 ++++ .../org/jetbrains/jewel/foundation}/util/Debug.kt | 2 +- .../jewel/foundation/{utils => util}/Logger.kt | 2 +- .../jewel/bridge/BridgePainterHintsProvider.kt | 2 +- .../standalone/StandalonePainterHintsProvider.kt | 2 +- .../standalone/view/component/ChipsAndTree.kt | 2 +- .../src/main/resources/icons/showAsTree.svg | 6 ++++++ .../src/main/resources/icons/showAsTree_dark.svg | 6 ++++++ ui/api/ui.api | 4 ---- .../jewel/ui/painter/ResourcePainterProvider.kt | 12 ++++++------ .../jewel/ui/painter/hints/DarkAndStroke.kt | 13 +++++++++++++ 11 files changed, 40 insertions(+), 15 deletions(-) rename {ui/src/main/kotlin/org/jetbrains/jewel/ui => foundation/src/main/kotlin/org/jetbrains/jewel/foundation}/util/Debug.kt (88%) rename foundation/src/main/kotlin/org/jetbrains/jewel/foundation/{utils => util}/Logger.kt (95%) create mode 100644 samples/standalone/src/main/resources/icons/showAsTree.svg create mode 100644 samples/standalone/src/main/resources/icons/showAsTree_dark.svg diff --git a/foundation/api/foundation.api b/foundation/api/foundation.api index c63df0506..d32e6e671 100644 --- a/foundation/api/foundation.api +++ b/foundation/api/foundation.api @@ -843,3 +843,7 @@ public final class org/jetbrains/jewel/foundation/theme/ThemeIconData$Companion public final fun getEmpty ()Lorg/jetbrains/jewel/foundation/theme/ThemeIconData; } +public final class org/jetbrains/jewel/foundation/util/DebugKt { + public static final fun getInDebugMode ()Z +} + diff --git a/ui/src/main/kotlin/org/jetbrains/jewel/ui/util/Debug.kt b/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/util/Debug.kt similarity index 88% rename from ui/src/main/kotlin/org/jetbrains/jewel/ui/util/Debug.kt rename to foundation/src/main/kotlin/org/jetbrains/jewel/foundation/util/Debug.kt index 1dd91b0cd..c487b3bdc 100644 --- a/ui/src/main/kotlin/org/jetbrains/jewel/ui/util/Debug.kt +++ b/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/util/Debug.kt @@ -1,4 +1,4 @@ -package org.jetbrains.jewel.ui.util +package org.jetbrains.jewel.foundation.util import org.jetbrains.jewel.foundation.InternalJewelApi diff --git a/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/utils/Logger.kt b/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/util/Logger.kt similarity index 95% rename from foundation/src/main/kotlin/org/jetbrains/jewel/foundation/utils/Logger.kt rename to foundation/src/main/kotlin/org/jetbrains/jewel/foundation/util/Logger.kt index 5b9dda14a..44dbe0230 100644 --- a/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/utils/Logger.kt +++ b/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/util/Logger.kt @@ -1,4 +1,4 @@ -package org.jetbrains.jewel.foundation.utils +package org.jetbrains.jewel.foundation.util internal enum class LogLevel(val color: String) { Trace("\u001b[38;5;33m"), diff --git a/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/BridgePainterHintsProvider.kt b/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/BridgePainterHintsProvider.kt index d87425c58..9c2f2a750 100644 --- a/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/BridgePainterHintsProvider.kt +++ b/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/BridgePainterHintsProvider.kt @@ -14,7 +14,7 @@ import org.jetbrains.jewel.ui.painter.hints.ColorBasedPaletteReplacement import org.jetbrains.jewel.ui.painter.hints.Dark import org.jetbrains.jewel.ui.painter.hints.HiDpi import org.jetbrains.jewel.ui.painter.hints.KeyBasedPaletteReplacement -import org.jetbrains.jewel.ui.util.inDebugMode +import org.jetbrains.jewel.foundation.util.inDebugMode import org.jetbrains.jewel.ui.util.toRgbaHexString /** diff --git a/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/StandalonePainterHintsProvider.kt b/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/StandalonePainterHintsProvider.kt index 141afaadd..6c6204d58 100644 --- a/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/StandalonePainterHintsProvider.kt +++ b/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/StandalonePainterHintsProvider.kt @@ -11,7 +11,7 @@ import org.jetbrains.jewel.ui.painter.hints.Dark import org.jetbrains.jewel.ui.painter.hints.HiDpi import org.jetbrains.jewel.ui.painter.hints.KeyBasedPaletteReplacement import org.jetbrains.jewel.ui.painter.hints.PathOverride -import org.jetbrains.jewel.ui.util.inDebugMode +import org.jetbrains.jewel.foundation.util.inDebugMode /** Provides the default [PainterHint]s to use to load images. */ public class StandalonePainterHintsProvider( diff --git a/samples/standalone/src/main/kotlin/org/jetbrains/jewel/samples/standalone/view/component/ChipsAndTree.kt b/samples/standalone/src/main/kotlin/org/jetbrains/jewel/samples/standalone/view/component/ChipsAndTree.kt index 8786b915b..9fddfb5e1 100644 --- a/samples/standalone/src/main/kotlin/org/jetbrains/jewel/samples/standalone/view/component/ChipsAndTree.kt +++ b/samples/standalone/src/main/kotlin/org/jetbrains/jewel/samples/standalone/view/component/ChipsAndTree.kt @@ -44,7 +44,7 @@ import org.jetbrains.jewel.ui.component.ToggleableChip import org.jetbrains.jewel.ui.theme.colorPalette @Composable -@View(title = "ChipsAndTree", position = 11) +@View(title = "ChipsAndTree", position = 11, icon = "icons/showAsTree.svg") fun ChipsAndTree() { Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(16.dp)) { Column(Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(8.dp)) { diff --git a/samples/standalone/src/main/resources/icons/showAsTree.svg b/samples/standalone/src/main/resources/icons/showAsTree.svg new file mode 100644 index 000000000..4d949713e --- /dev/null +++ b/samples/standalone/src/main/resources/icons/showAsTree.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/samples/standalone/src/main/resources/icons/showAsTree_dark.svg b/samples/standalone/src/main/resources/icons/showAsTree_dark.svg new file mode 100644 index 000000000..0ff8904a5 --- /dev/null +++ b/samples/standalone/src/main/resources/icons/showAsTree_dark.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/ui/api/ui.api b/ui/api/ui.api index e39190711..462ae6a42 100644 --- a/ui/api/ui.api +++ b/ui/api/ui.api @@ -2378,10 +2378,6 @@ public final class org/jetbrains/jewel/ui/util/ColorExtensionsKt { public static final fun toRgbaHexString-8_81llA (J)Ljava/lang/String; } -public final class org/jetbrains/jewel/ui/util/DebugKt { - public static final fun getInDebugMode ()Z -} - public final class org/jetbrains/jewel/ui/util/ModifierExtensionsKt { public static final fun thenIf (Landroidx/compose/ui/Modifier;ZLkotlin/jvm/functions/Function1;)Landroidx/compose/ui/Modifier; } diff --git a/ui/src/main/kotlin/org/jetbrains/jewel/ui/painter/ResourcePainterProvider.kt b/ui/src/main/kotlin/org/jetbrains/jewel/ui/painter/ResourcePainterProvider.kt index 9a01b3cfa..77a427985 100644 --- a/ui/src/main/kotlin/org/jetbrains/jewel/ui/painter/ResourcePainterProvider.kt +++ b/ui/src/main/kotlin/org/jetbrains/jewel/ui/painter/ResourcePainterProvider.kt @@ -15,7 +15,7 @@ import androidx.compose.ui.res.loadImageBitmap import androidx.compose.ui.res.loadSvgPainter import androidx.compose.ui.res.loadXmlImageVector import androidx.compose.ui.unit.Density -import org.jetbrains.jewel.ui.util.inDebugMode +import org.jetbrains.jewel.foundation.util.inDebugMode import org.w3c.dom.Document import org.xml.sax.InputSource import java.io.IOException @@ -166,7 +166,7 @@ public class ResourcePainterProvider( loadSvgPainter(inputStream, scope) } }, - rememberAction = { remember(url, scope.density) { it } }, + paintAction = { it }, ) private fun patchSvg( @@ -205,7 +205,7 @@ public class ResourcePainterProvider( loadingAction = { resourceUrl -> resourceUrl.openStream().use { loadXmlImageVector(InputSource(it), scope) } }, - rememberAction = { rememberVectorPainter(it) }, + paintAction = { rememberVectorPainter(it) }, ) @Composable @@ -218,14 +218,14 @@ public class ResourcePainterProvider( val bitmap = resourceUrl.openStream().use { loadImageBitmap(it) } BitmapPainter(bitmap) }, - rememberAction = { remember(url, scope.density) { it } }, + paintAction = { it }, ) @Composable private fun tryLoadingResource( url: URL, loadingAction: (URL) -> T, - rememberAction: @Composable (T) -> Painter, + paintAction: @Composable (T) -> Painter, ): Painter { @Suppress("TooGenericExceptionCaught") // This is a last-resort fallback when icons fail to load val painter = @@ -241,7 +241,7 @@ public class ResourcePainterProvider( return errorPainter } - return rememberAction(painter) + return paintAction(painter) } private class Scope( diff --git a/ui/src/main/kotlin/org/jetbrains/jewel/ui/painter/hints/DarkAndStroke.kt b/ui/src/main/kotlin/org/jetbrains/jewel/ui/painter/hints/DarkAndStroke.kt index d1c179703..4d0bb83fb 100644 --- a/ui/src/main/kotlin/org/jetbrains/jewel/ui/painter/hints/DarkAndStroke.kt +++ b/ui/src/main/kotlin/org/jetbrains/jewel/ui/painter/hints/DarkAndStroke.kt @@ -60,6 +60,19 @@ private class StrokeImpl(private val color: Color) : PainterSuffixHint(), Painte Color(0xFFF28C35), Color(0xFF955AE0), ) + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (other !is StrokeImpl) return false + + if (color != other.color) return false + + return true + } + + override fun toString(): String = "Stroke(color=$color)" + + override fun hashCode(): Int = color.hashCode() } /** From fef62a98e5e70b6b91f58baa26eacd7d7c1c6bfa Mon Sep 17 00:00:00 2001 From: caixuan Date: Sat, 17 Feb 2024 19:47:20 +0800 Subject: [PATCH 2/2] Make hints happy --- .../org/jetbrains/jewel/bridge/BridgePainterHintsProvider.kt | 2 +- .../jewel/intui/standalone/StandalonePainterHintsProvider.kt | 2 +- .../org/jetbrains/jewel/ui/painter/ResourcePainterProvider.kt | 3 +-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/BridgePainterHintsProvider.kt b/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/BridgePainterHintsProvider.kt index 9c2f2a750..47782dd82 100644 --- a/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/BridgePainterHintsProvider.kt +++ b/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/BridgePainterHintsProvider.kt @@ -8,13 +8,13 @@ import com.intellij.ui.NewUI import org.jetbrains.jewel.bridge.theme.isNewUiTheme import org.jetbrains.jewel.foundation.InternalJewelApi import org.jetbrains.jewel.foundation.theme.JewelTheme +import org.jetbrains.jewel.foundation.util.inDebugMode import org.jetbrains.jewel.ui.painter.PainterHint import org.jetbrains.jewel.ui.painter.PalettePainterHintsProvider import org.jetbrains.jewel.ui.painter.hints.ColorBasedPaletteReplacement import org.jetbrains.jewel.ui.painter.hints.Dark import org.jetbrains.jewel.ui.painter.hints.HiDpi import org.jetbrains.jewel.ui.painter.hints.KeyBasedPaletteReplacement -import org.jetbrains.jewel.foundation.util.inDebugMode import org.jetbrains.jewel.ui.util.toRgbaHexString /** diff --git a/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/StandalonePainterHintsProvider.kt b/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/StandalonePainterHintsProvider.kt index 6c6204d58..4ad55ca5a 100644 --- a/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/StandalonePainterHintsProvider.kt +++ b/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/StandalonePainterHintsProvider.kt @@ -4,6 +4,7 @@ import androidx.compose.runtime.Composable import androidx.compose.ui.graphics.Color import org.jetbrains.jewel.foundation.theme.JewelTheme import org.jetbrains.jewel.foundation.theme.ThemeDefinition +import org.jetbrains.jewel.foundation.util.inDebugMode import org.jetbrains.jewel.ui.painter.PainterHint import org.jetbrains.jewel.ui.painter.PalettePainterHintsProvider import org.jetbrains.jewel.ui.painter.hints.ColorBasedPaletteReplacement @@ -11,7 +12,6 @@ import org.jetbrains.jewel.ui.painter.hints.Dark import org.jetbrains.jewel.ui.painter.hints.HiDpi import org.jetbrains.jewel.ui.painter.hints.KeyBasedPaletteReplacement import org.jetbrains.jewel.ui.painter.hints.PathOverride -import org.jetbrains.jewel.foundation.util.inDebugMode /** Provides the default [PainterHint]s to use to load images. */ public class StandalonePainterHintsProvider( diff --git a/ui/src/main/kotlin/org/jetbrains/jewel/ui/painter/ResourcePainterProvider.kt b/ui/src/main/kotlin/org/jetbrains/jewel/ui/painter/ResourcePainterProvider.kt index 77a427985..0c4a5c535 100644 --- a/ui/src/main/kotlin/org/jetbrains/jewel/ui/painter/ResourcePainterProvider.kt +++ b/ui/src/main/kotlin/org/jetbrains/jewel/ui/painter/ResourcePainterProvider.kt @@ -126,7 +126,7 @@ public class ResourcePainterProvider( when (extension) { "svg" -> createSvgPainter(chosenScope, url) "xml" -> createVectorDrawablePainter(chosenScope, url) - else -> createBitmapPainter(chosenScope, url) + else -> createBitmapPainter(url) } for (hint in scope.acceptedHints) { @@ -210,7 +210,6 @@ public class ResourcePainterProvider( @Composable private fun createBitmapPainter( - scope: Scope, url: URL, ) = tryLoadingResource( url = url,