From 499c624ec268efa69559e84305cedca98043f895 Mon Sep 17 00:00:00 2001 From: higan Date: Sat, 21 Oct 2023 01:36:33 +0800 Subject: [PATCH 1/5] Fix dropdown menu and fallback rule --- core/api/core.api | 6 ++++ .../jewel/painter/PainterHintsProvider.kt | 9 +++++ .../jewel/painter/ResourcePainterProvider.kt | 34 ++++++++++--------- .../org/jetbrains/jewel/bridge/IntUiBridge.kt | 22 ++++++------ int-ui/int-ui-core/api/int-ui-core.api | 1 + 5 files changed, 45 insertions(+), 27 deletions(-) diff --git a/core/api/core.api b/core/api/core.api index 9dae76767..ab0ce833b 100644 --- a/core/api/core.api +++ b/core/api/core.api @@ -1486,6 +1486,7 @@ public final class org/jetbrains/jewel/painter/CommonPainterHintsProvider : org/ public static final field $stable I public static final field INSTANCE Lorg/jetbrains/jewel/painter/CommonPainterHintsProvider; public fun hints (Ljava/lang/String;Landroidx/compose/runtime/Composer;I)Ljava/util/List; + public fun priorityHints (Ljava/lang/String;Landroidx/compose/runtime/Composer;I)Ljava/util/List; } public abstract interface class org/jetbrains/jewel/painter/PainterHint { @@ -1504,6 +1505,11 @@ public final class org/jetbrains/jewel/painter/PainterHint$None : org/jetbrains/ public abstract interface class org/jetbrains/jewel/painter/PainterHintsProvider { public abstract fun hints (Ljava/lang/String;Landroidx/compose/runtime/Composer;I)Ljava/util/List; + public abstract fun priorityHints (Ljava/lang/String;Landroidx/compose/runtime/Composer;I)Ljava/util/List; +} + +public final class org/jetbrains/jewel/painter/PainterHintsProvider$DefaultImpls { + public static fun priorityHints (Lorg/jetbrains/jewel/painter/PainterHintsProvider;Ljava/lang/String;Landroidx/compose/runtime/Composer;I)Ljava/util/List; } public final class org/jetbrains/jewel/painter/PainterHintsProviderKt { diff --git a/core/src/main/kotlin/org/jetbrains/jewel/painter/PainterHintsProvider.kt b/core/src/main/kotlin/org/jetbrains/jewel/painter/PainterHintsProvider.kt index a97fff26c..5cdca4b95 100644 --- a/core/src/main/kotlin/org/jetbrains/jewel/painter/PainterHintsProvider.kt +++ b/core/src/main/kotlin/org/jetbrains/jewel/painter/PainterHintsProvider.kt @@ -18,6 +18,15 @@ import org.jetbrains.jewel.painter.hints.HiDpi @Immutable interface PainterHintsProvider { + /** + * Those hints will be added before the [hints][PainterProvider.getPainter] that passed in [PainterProvider.getPainter]. + */ + @Composable + fun priorityHints(path: String): List = emptyList() + + /** + * Those hints will be added after the [hints][PainterProvider.getPainter] that passed in [PainterProvider.getPainter]. + */ @Composable fun hints(path: String): List } diff --git a/core/src/main/kotlin/org/jetbrains/jewel/painter/ResourcePainterProvider.kt b/core/src/main/kotlin/org/jetbrains/jewel/painter/ResourcePainterProvider.kt index aeee86d2c..857ba34fb 100644 --- a/core/src/main/kotlin/org/jetbrains/jewel/painter/ResourcePainterProvider.kt +++ b/core/src/main/kotlin/org/jetbrains/jewel/painter/ResourcePainterProvider.kt @@ -60,8 +60,10 @@ class ResourcePainterProvider( @Composable override fun getPainter(vararg hints: PainterHint): State { - val resolvedHints = (hints.toList() + LocalPainterHintsProvider.current.hints(basePath)) - .filter { it.canApplyTo(basePath) } + val currentHintsProvider = LocalPainterHintsProvider.current + val providedHints = + currentHintsProvider.priorityHints(basePath) + hints.toList() + currentHintsProvider.hints(basePath) + val resolvedHints = providedHints.filter { it.canApplyTo(basePath) } val cacheKey = resolvedHints.hashCode() @@ -81,22 +83,22 @@ class ResourcePainterProvider( @Composable private fun loadPainter(hints: List): Painter { - val pathStack = buildSet { - var path = basePath - - add(path) - - for (hint in hints) { - path = when (hint) { - is PainterResourcePathHint -> hint.patch(path, contextClassLoaders) - is PainterPathHint -> hint.patch(path) - else -> continue + var paths = setOf(basePath) + + for (hint in hints) { + if (hint !is PainterResourcePathHint && hint !is PainterPathHint) continue + paths = paths.flatMap { + val patched = when (hint) { + is PainterResourcePathHint -> hint.patch(it, contextClassLoaders) + is PainterPathHint -> hint.patch(it) + else -> return@flatMap listOf(it) } - add(path) - } - }.reversed() - val url = pathStack.firstNotNullOfOrNull { resolveResource(it) } + setOf(patched, it) + }.toSet() + } + + val url = paths.firstNotNullOfOrNull { resolveResource(it) } @Suppress("UrlHashCode") // It's ok when comparing a URL to null if (url == null) { diff --git a/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/IntUiBridge.kt b/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/IntUiBridge.kt index 1dcb6a44f..860b0d62c 100644 --- a/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/IntUiBridge.kt +++ b/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/IntUiBridge.kt @@ -388,7 +388,7 @@ private fun readDefaultDropdownStyle( borderWidth = DarculaUIUtil.BW.dp, ), icons = DropdownIcons( - chevronDown = bridgePainterProvider("${iconsBasePath}general/chevron-down.svg"), + chevronDown = bridgePainterProvider("general/chevron-down.svg"), ), textStyle = dropdownTextStyle, menuStyle = menuStyle, @@ -440,7 +440,7 @@ private fun readUndecoratedDropdownStyle( borderWidth = 0.dp, ), icons = DropdownIcons( - chevronDown = bridgePainterProvider("${iconsBasePath}general/chevron-down.svg"), + chevronDown = bridgePainterProvider("general/chevron-down.svg"), ), textStyle = dropdownTextStyle, menuStyle = menuStyle, @@ -547,11 +547,11 @@ private fun readLinkStyle( metrics = LinkMetrics( focusHaloCornerSize = CornerSize(Registry.intValue("ide.link.button.focus.round.arc", 4).dp), textIconGap = 4.dp, - iconSize = DpSize.Unspecified, + iconSize = DpSize(16.dp, 16.dp), ), icons = LinkIcons( - dropdownChevron = bridgePainterProvider("${iconsBasePath}general/chevron-down.svg"), - externalLink = bridgePainterProvider("${iconsBasePath}ide/external_link_arrow.svg"), + dropdownChevron = bridgePainterProvider("general/chevron-down.svg"), + externalLink = bridgePainterProvider("ide/external_link_arrow.svg"), ), textStyles = LinkTextStyles( normal = linkTextStyle, @@ -604,7 +604,7 @@ private fun readMenuStyle(): MenuStyle { itemMetrics = MenuItemMetrics( selectionCornerSize = CornerSize(JBUI.CurrentTheme.PopupMenu.Selection.ARC.dp), outerPadding = PaddingValues(horizontal = 6.dp), - contentPadding = PaddingValues(horizontal = 10.dp, vertical = 1.dp), + contentPadding = PaddingValues(horizontal = 10.dp, vertical = 4.dp), separatorPadding = PaddingValues( horizontal = retrieveIntAsDpOrUnspecified("PopupMenuSeparator.withToEdge").takeOrElse { 0.dp }, vertical = retrieveIntAsDpOrUnspecified("PopupMenuSeparator.stripeIndent").takeOrElse { 0.dp }, @@ -616,7 +616,7 @@ private fun readMenuStyle(): MenuStyle { ), ), icons = MenuIcons( - submenuChevron = bridgePainterProvider("${iconsBasePath}general/chevron-down.svg"), + submenuChevron = bridgePainterProvider("general/chevron-right.svg"), ), ) } @@ -766,8 +766,8 @@ private fun readLazyTreeStyle(): LazyTreeStyle { elementBackgroundSelectedFocused = selectedElementBackground, ) - val chevronCollapsed = bridgePainterProvider("${iconsBasePath}general/chevron-right.svg") - val chevronExpanded = bridgePainterProvider("${iconsBasePath}general/chevron-down.svg") + val chevronCollapsed = bridgePainterProvider("general/chevron-right.svg") + val chevronExpanded = bridgePainterProvider("general/chevron-down.svg") return LazyTreeStyle( colors = colors, @@ -826,7 +826,7 @@ private fun readDefaultTabStyle(): TabStyle { tabHeight = retrieveIntAsDpOrUnspecified("TabbedPane.tabHeight").takeOrElse { 24.dp }, ), icons = TabIcons( - close = bridgePainterProvider("${iconsBasePath}expui/general/closeSmall.svg"), + close = bridgePainterProvider("expui/general/closeSmall.svg"), ), contentAlpha = TabContentAlpha( iconNormal = 1f, @@ -881,7 +881,7 @@ private fun readEditorTabStyle(): TabStyle { tabHeight = retrieveIntAsDpOrUnspecified("TabbedPane.tabHeight").takeOrElse { 24.dp }, ), icons = TabIcons( - close = bridgePainterProvider("${iconsBasePath}expui/general/closeSmall.svg"), + close = bridgePainterProvider("expui/general/closeSmall.svg"), ), contentAlpha = TabContentAlpha( iconNormal = .7f, diff --git a/int-ui/int-ui-core/api/int-ui-core.api b/int-ui/int-ui-core/api/int-ui-core.api index bab021b3a..d153570ec 100644 --- a/int-ui/int-ui-core/api/int-ui-core.api +++ b/int-ui/int-ui-core/api/int-ui-core.api @@ -67,6 +67,7 @@ public abstract class org/jetbrains/jewel/intui/core/IntUiPainterHintsProvider : public static final field $stable I public fun (ZLjava/util/Map;Ljava/util/Map;Ljava/util/Map;)V protected final fun getPaletteHint (Ljava/lang/String;)Lorg/jetbrains/jewel/painter/PainterHint; + public fun priorityHints (Ljava/lang/String;Landroidx/compose/runtime/Composer;I)Ljava/util/List; } public abstract interface class org/jetbrains/jewel/intui/core/IntUiThemeColorPalette : org/jetbrains/jewel/IntelliJThemeColorPalette { From 0befdd1e0e223479405f2953fe0a603469dfa121 Mon Sep 17 00:00:00 2001 From: higan Date: Sat, 21 Oct 2023 01:56:31 +0800 Subject: [PATCH 2/5] Fix tooltip --- .../jewel/intui/standalone/styling/IntUiTooltipStyling.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiTooltipStyling.kt b/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiTooltipStyling.kt index 22c78a469..63a327e10 100644 --- a/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiTooltipStyling.kt +++ b/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiTooltipStyling.kt @@ -40,15 +40,15 @@ fun TooltipColors.Companion.light( backgroundColor: Color = IntUiLightTheme.colors.grey(2), borderColor: Color = backgroundColor, shadow: Color = Color(0x78919191), // Not a palette color -) = TooltipColors(contentColor, backgroundColor, borderColor, shadow) +) = TooltipColors(backgroundColor, contentColor, borderColor, shadow) @Composable fun TooltipColors.Companion.dark( contentColor: Color = IntUiDarkTheme.colors.grey(12), backgroundColor: Color = IntUiDarkTheme.colors.grey(2), - shadow: Color = Color(0x66000000), // Not a palette color borderColor: Color = IntUiDarkTheme.colors.grey(3), -) = TooltipColors(contentColor, backgroundColor, borderColor, shadow) + shadow: Color = Color(0x66000000), // Not a palette color +) = TooltipColors(backgroundColor, contentColor, borderColor, shadow) fun TooltipMetrics.Companion.defaults( contentPadding: PaddingValues = PaddingValues(vertical = 9.dp, horizontal = 12.dp), From 1ed461b665aea29ad2f3d0b50fe1c115aa34179d Mon Sep 17 00:00:00 2001 From: higan Date: Sat, 21 Oct 2023 01:57:52 +0800 Subject: [PATCH 3/5] Fix tooltip --- .../jewel/intui/standalone/styling/IntUiTooltipStyling.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiTooltipStyling.kt b/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiTooltipStyling.kt index 63a327e10..a8c396637 100644 --- a/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiTooltipStyling.kt +++ b/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiTooltipStyling.kt @@ -36,16 +36,16 @@ fun TooltipStyle.Companion.dark( @Composable fun TooltipColors.Companion.light( - contentColor: Color = IntUiLightTheme.colors.grey(12), backgroundColor: Color = IntUiLightTheme.colors.grey(2), + contentColor: Color = IntUiLightTheme.colors.grey(12), borderColor: Color = backgroundColor, shadow: Color = Color(0x78919191), // Not a palette color ) = TooltipColors(backgroundColor, contentColor, borderColor, shadow) @Composable fun TooltipColors.Companion.dark( - contentColor: Color = IntUiDarkTheme.colors.grey(12), backgroundColor: Color = IntUiDarkTheme.colors.grey(2), + contentColor: Color = IntUiDarkTheme.colors.grey(12), borderColor: Color = IntUiDarkTheme.colors.grey(3), shadow: Color = Color(0x66000000), // Not a palette color ) = TooltipColors(backgroundColor, contentColor, borderColor, shadow) From ba0145edefa66296c0d169ce48074f3a3e485010 Mon Sep 17 00:00:00 2001 From: Kanro Date: Sat, 21 Oct 2023 02:03:27 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=F0=9F=94=80=20Apply=20suggestions=20from?= =?UTF-8?q?=20code=20review?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Sebastiano Poggi --- .../org/jetbrains/jewel/painter/PainterHintsProvider.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/kotlin/org/jetbrains/jewel/painter/PainterHintsProvider.kt b/core/src/main/kotlin/org/jetbrains/jewel/painter/PainterHintsProvider.kt index 5cdca4b95..675118c7c 100644 --- a/core/src/main/kotlin/org/jetbrains/jewel/painter/PainterHintsProvider.kt +++ b/core/src/main/kotlin/org/jetbrains/jewel/painter/PainterHintsProvider.kt @@ -19,13 +19,13 @@ import org.jetbrains.jewel.painter.hints.HiDpi interface PainterHintsProvider { /** - * Those hints will be added before the [hints][PainterProvider.getPainter] that passed in [PainterProvider.getPainter]. + * These hints will be consumed before the [hints] when [PainterProvider.getPainter] is called. */ @Composable fun priorityHints(path: String): List = emptyList() /** - * Those hints will be added after the [hints][PainterProvider.getPainter] that passed in [PainterProvider.getPainter]. + * These hints will be consumed after the [priorityHints] when [PainterProvider.getPainter] is called. */ @Composable fun hints(path: String): List From 4e4d25f5e44247b95de3bd3933482e32e0382744 Mon Sep 17 00:00:00 2001 From: Kanro Date: Sat, 21 Oct 2023 02:16:22 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=F0=9F=94=80=20Apply=20suggestions=20from?= =?UTF-8?q?=20code=20review?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/jetbrains/jewel/painter/PainterHintsProvider.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/kotlin/org/jetbrains/jewel/painter/PainterHintsProvider.kt b/core/src/main/kotlin/org/jetbrains/jewel/painter/PainterHintsProvider.kt index 675118c7c..fb6b363ee 100644 --- a/core/src/main/kotlin/org/jetbrains/jewel/painter/PainterHintsProvider.kt +++ b/core/src/main/kotlin/org/jetbrains/jewel/painter/PainterHintsProvider.kt @@ -19,13 +19,13 @@ import org.jetbrains.jewel.painter.hints.HiDpi interface PainterHintsProvider { /** - * These hints will be consumed before the [hints] when [PainterProvider.getPainter] is called. + * These hints will be consumed before the hints which are passed as a parameter to [PainterProvider.getPainter]. */ @Composable fun priorityHints(path: String): List = emptyList() /** - * These hints will be consumed after the [priorityHints] when [PainterProvider.getPainter] is called. + * These hints will be consumed after the hints which are passed as a parameter to [PainterProvider.getPainter]. */ @Composable fun hints(path: String): List