Skip to content

Commit

Permalink
Fix icon loading and errors in bridge for 241
Browse files Browse the repository at this point in the history
  • Loading branch information
rock3r committed Feb 1, 2024
1 parent eb0ed11 commit 925b885
Show file tree
Hide file tree
Showing 37 changed files with 426 additions and 222 deletions.
4 changes: 2 additions & 2 deletions ide-laf-bridge/api/ide-laf-bridge.api
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ public final class org/jetbrains/jewel/bridge/BridgeIconDataKt {
public static final fun readFromLaF (Lorg/jetbrains/jewel/foundation/theme/ThemeIconData$Companion;)Lorg/jetbrains/jewel/foundation/theme/ThemeIconData;
}

public final class org/jetbrains/jewel/bridge/BridgePainterHintsProvider : org/jetbrains/jewel/ui/painter/BasePainterHintsProvider {
public final class org/jetbrains/jewel/bridge/BridgePainterHintsProvider : org/jetbrains/jewel/ui/painter/PalettePainterHintsProvider {
public static final field $stable I
public static final field Companion Lorg/jetbrains/jewel/bridge/BridgePainterHintsProvider$Companion;
public synthetic fun <init> (ZLjava/util/Map;Ljava/util/Map;Ljava/util/Map;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun hints (Ljava/lang/String;Landroidx/compose/runtime/Composer;I)Ljava/util/List;
}

public final class org/jetbrains/jewel/bridge/BridgePainterHintsProvider$Companion {
public final fun invoke (Z)Lorg/jetbrains/jewel/ui/painter/BasePainterHintsProvider;
public final fun invoke (Z)Lorg/jetbrains/jewel/ui/painter/PalettePainterHintsProvider;
}

public final class org/jetbrains/jewel/bridge/BridgeResourceResolverKt {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import com.intellij.ide.ui.UITheme
import com.intellij.openapi.diagnostic.thisLogger
import org.jetbrains.jewel.foundation.InternalJewelApi
import org.jetbrains.jewel.foundation.theme.JewelTheme
import org.jetbrains.jewel.ui.painter.BasePainterHintsProvider
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

Expand All @@ -17,7 +18,47 @@ public class BridgePainterHintsProvider private constructor(
intellijIconPalette: Map<String, String?> = emptyMap(),
themeIconPalette: Map<String, String?> = emptyMap(),
themeColorPalette: Map<String, Color?> = emptyMap(),
) : BasePainterHintsProvider(isDark, intellijIconPalette, themeIconPalette, themeColorPalette) {
) : PalettePainterHintsProvider(isDark, intellijIconPalette, themeIconPalette, themeColorPalette) {

override val checkBoxPaletteHint: PainterHint
override val treePaletteHint: PainterHint
override val uiPaletteHint: PainterHint

init {
val ui = mutableMapOf<Color, Color>()
val checkBoxes = mutableMapOf<Color, Color>()
val trees = mutableMapOf<Color, Color>()

@Suppress("LoopWithTooManyJumpStatements")
for ((key, value) in themeIconPalette) {
if (value == null) continue
val map = selectMap(key, checkBoxes, trees, ui) ?: continue

// If either the key or the resolved value aren't valid colors, ignore the entry
val keyAsColor = resolveKeyColor(key, intellijIconPalette, isDark) ?: continue
val resolvedColor = resolveColor(value) ?: continue

// Save the new entry (oldColor -> newColor) in the map
map[keyAsColor] = resolvedColor
}

checkBoxPaletteHint = ColorBasedPaletteReplacement(checkBoxes)
treePaletteHint = ColorBasedPaletteReplacement(trees)
uiPaletteHint = ColorBasedPaletteReplacement(ui)
}

private fun selectMap(
key: String,
checkBoxes: MutableMap<Color, Color>,
trees: MutableMap<Color, Color>,
ui: MutableMap<Color, Color>,
) =
when {
key.startsWith("Checkbox.") -> checkBoxes
key.startsWith("Tree.iconColor.") -> trees
key.startsWith("Objects.") || key.startsWith("Actions.") || key.startsWith("#") -> ui
else -> null
}

@Composable
override fun hints(path: String): List<PainterHint> = buildList {
Expand All @@ -32,7 +73,7 @@ public class BridgePainterHintsProvider private constructor(
private val logger = thisLogger()

@Suppress("UnstableApiUsage") // We need to call @Internal APIs
public operator fun invoke(isDark: Boolean): BasePainterHintsProvider {
public operator fun invoke(isDark: Boolean): PalettePainterHintsProvider {
val uiTheme = currentUiThemeOrNull() ?: return BridgePainterHintsProvider(isDark)
logger.info("Parsing theme info from theme ${uiTheme.name} (id: ${uiTheme.id}, isDark: ${uiTheme.isDark})")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,13 @@ private fun readDefaultButtonStyle(): ButtonStyle {
borderHovered = normalBorder,
)

val minimumSize = JBUI.CurrentTheme.Button.minimumSize()
return ButtonStyle(
colors = colors,
metrics = ButtonMetrics(
cornerSize = retrieveArcAsCornerSizeWithFallbacks("Button.default.arc", "Button.arc"),
padding = PaddingValues(horizontal = 14.dp), // see DarculaButtonUI.HORIZONTAL_PADDING
minSize = DpSize(DarculaUIUtil.MINIMUM_WIDTH.dp, DarculaUIUtil.MINIMUM_HEIGHT.dp),
minSize = DpSize(minimumSize.width.dp, minimumSize.height.dp),
borderWidth = DarculaUIUtil.LW.dp,
),
)
Expand Down Expand Up @@ -264,13 +265,14 @@ private fun readOutlinedButtonStyle(): ButtonStyle {
borderHovered = normalBorder,
)

val minimumSize = JBUI.CurrentTheme.Button.minimumSize()
return ButtonStyle(
colors = colors,
metrics =
ButtonMetrics(
cornerSize = CornerSize(DarculaUIUtil.BUTTON_ARC.dp / 2),
padding = PaddingValues(horizontal = 14.dp), // see DarculaButtonUI.HORIZONTAL_PADDING
minSize = DpSize(DarculaUIUtil.MINIMUM_WIDTH.dp, DarculaUIUtil.MINIMUM_HEIGHT.dp),
minSize = DpSize(minimumSize.width.dp, minimumSize.height.dp),
borderWidth = DarculaUIUtil.LW.dp,
),
)
Expand All @@ -288,9 +290,10 @@ private fun readCheckboxStyle(): CheckboxStyle {
colors = colors,
metrics = CheckboxMetrics(
checkboxSize = DarculaCheckBoxUI().defaultIcon.let { DpSize(it.iconWidth.dp, it.iconHeight.dp) },
checkboxCornerSize = CornerSize(3.dp), // See DarculaCheckBoxUI#drawCheckIcon
outlineCornerSize = CornerSize(3.dp), // See DarculaCheckBoxUI#drawCheckIcon
outlineSelectedCornerSize = CornerSize(3.dp),
outlineSize = DpSize(15.dp, 15.dp), // Extrapolated from SVG
outlineOffset = DpOffset(2.5.dp, 1.5.dp), // Extrapolated from SVG
outlineSelectedSize = DpSize(16.dp, 16.dp), // Extrapolated from SVG
iconContentGap = 5.dp, // See DarculaCheckBoxUI#textIconGap
),
icons = CheckboxIcons(checkbox = bridgePainterProvider("${iconsBasePath}checkBox.svg")),
Expand Down Expand Up @@ -394,12 +397,13 @@ private fun readDefaultDropdownStyle(
iconTintHovered = Color.Unspecified,
)

val arrowWidth = DarculaUIUtil.ARROW_BUTTON_WIDTH.dp
val minimumSize = JBUI.CurrentTheme.ComboBox.minimumSize()
val arrowWidth = JBUI.CurrentTheme.Component.ARROW_AREA_WIDTH.dp
return DropdownStyle(
colors = colors,
metrics = DropdownMetrics(
arrowMinSize = DpSize(arrowWidth, DarculaUIUtil.MINIMUM_HEIGHT.dp),
minSize = DpSize(DarculaUIUtil.MINIMUM_WIDTH.dp + arrowWidth, DarculaUIUtil.MINIMUM_HEIGHT.dp),
arrowMinSize = DpSize(arrowWidth, minimumSize.height.dp),
minSize = DpSize(minimumSize.width.dp + arrowWidth, minimumSize.height.dp),
cornerSize = CornerSize(DarculaUIUtil.COMPONENT_ARC.dp),
contentPadding = retrieveInsetsAsPaddingValues("ComboBox.padding"),
borderWidth = DarculaUIUtil.BW.dp,
Expand Down Expand Up @@ -441,12 +445,14 @@ private fun readUndecoratedDropdownStyle(
iconTintHovered = Color.Unspecified,
)

val arrowWidth = DarculaUIUtil.ARROW_BUTTON_WIDTH.dp
val arrowWidth = JBUI.CurrentTheme.Component.ARROW_AREA_WIDTH.dp
val minimumSize = JBUI.CurrentTheme.Button.minimumSize()

return DropdownStyle(
colors = colors,
metrics = DropdownMetrics(
arrowMinSize = DpSize(arrowWidth, DarculaUIUtil.MINIMUM_HEIGHT.dp),
minSize = DpSize(DarculaUIUtil.MINIMUM_WIDTH.dp + arrowWidth, DarculaUIUtil.MINIMUM_HEIGHT.dp),
arrowMinSize = DpSize(arrowWidth, minimumSize.height.dp),
minSize = DpSize(minimumSize.width.dp + arrowWidth, minimumSize.height.dp),
cornerSize = CornerSize(JBUI.CurrentTheme.MainToolbar.Dropdown.hoverArc().dp),
contentPadding = JBUI.CurrentTheme.MainToolbar.Dropdown.borderInsets().toPaddingValues(),
borderWidth = 0.dp,
Expand Down Expand Up @@ -612,7 +618,9 @@ private fun readRadioButtonStyle(): RadioButtonStyle {
return RadioButtonStyle(
colors = colors,
metrics = RadioButtonMetrics(
radioButtonSize = DpSize(19.dp, 19.dp),
radioButtonSize = DpSize(24.dp, 24.dp), // Extrapolated from SVG
outlineSize = DpSize(17.dp, 17.dp), // Extrapolated from SVG
outlineSelectedSize = DpSize(22.dp, 22.dp), // Extrapolated from SVG
iconContentGap = retrieveIntAsDpOrUnspecified("RadioButton.textIconGap")
.takeOrElse { 4.dp },
),
Expand Down Expand Up @@ -723,12 +731,13 @@ private fun readTextFieldStyle(textFieldStyle: TextStyle): TextFieldStyle {
placeholder = NamedColorUtil.getInactiveTextColor().toComposeColor(),
)

val minimumSize = JBUI.CurrentTheme.TextField.minimumSize()
return TextFieldStyle(
colors = colors,
metrics = TextFieldMetrics(
cornerSize = CornerSize(DarculaUIUtil.COMPONENT_ARC.dp),
contentPadding = PaddingValues(horizontal = 9.dp, vertical = 2.dp),
minSize = DpSize(DarculaUIUtil.MINIMUM_WIDTH.dp, DarculaUIUtil.MINIMUM_HEIGHT.dp),
minSize = DpSize(minimumSize.width.dp, minimumSize.height.dp),
borderWidth = DarculaUIUtil.LW.dp,
),
textStyle = textFieldStyle,
Expand Down
10 changes: 5 additions & 5 deletions int-ui/int-ui-standalone/api/int-ui-standalone.api
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public final class org/jetbrains/jewel/intui/standalone/PainterProviderKt {
public static final fun standalonePainterProvider (Ljava/lang/String;)Lorg/jetbrains/jewel/ui/painter/ResourcePainterProvider;
}

public final class org/jetbrains/jewel/intui/standalone/StandalonePainterHintsProvider : org/jetbrains/jewel/ui/painter/BasePainterHintsProvider {
public final class org/jetbrains/jewel/intui/standalone/StandalonePainterHintsProvider : org/jetbrains/jewel/ui/painter/PalettePainterHintsProvider {
public static final field $stable I
public static final field Companion Lorg/jetbrains/jewel/intui/standalone/StandalonePainterHintsProvider$Companion;
public fun <init> (Lorg/jetbrains/jewel/foundation/theme/ThemeDefinition;)V
Expand All @@ -49,8 +49,8 @@ public final class org/jetbrains/jewel/intui/standalone/styling/IntUiCheckboxSty
public static final fun dark (Lorg/jetbrains/jewel/ui/component/styling/CheckboxIcons$Companion;Lorg/jetbrains/jewel/ui/painter/PainterProvider;Landroidx/compose/runtime/Composer;II)Lorg/jetbrains/jewel/ui/component/styling/CheckboxIcons;
public static final fun dark (Lorg/jetbrains/jewel/ui/component/styling/CheckboxStyle$Companion;Lorg/jetbrains/jewel/ui/component/styling/CheckboxColors;Lorg/jetbrains/jewel/ui/component/styling/CheckboxMetrics;Lorg/jetbrains/jewel/ui/component/styling/CheckboxIcons;Landroidx/compose/runtime/Composer;II)Lorg/jetbrains/jewel/ui/component/styling/CheckboxStyle;
public static final fun dark-GyCwops (Lorg/jetbrains/jewel/ui/component/styling/CheckboxColors$Companion;JJJLandroidx/compose/runtime/Composer;II)Lorg/jetbrains/jewel/ui/component/styling/CheckboxColors;
public static final fun defaults-RRvNTYw (Lorg/jetbrains/jewel/ui/component/styling/CheckboxMetrics$Companion;JLandroidx/compose/foundation/shape/CornerSize;JJF)Lorg/jetbrains/jewel/ui/component/styling/CheckboxMetrics;
public static synthetic fun defaults-RRvNTYw$default (Lorg/jetbrains/jewel/ui/component/styling/CheckboxMetrics$Companion;JLandroidx/compose/foundation/shape/CornerSize;JJFILjava/lang/Object;)Lorg/jetbrains/jewel/ui/component/styling/CheckboxMetrics;
public static final fun defaults-XIZ8g8E (Lorg/jetbrains/jewel/ui/component/styling/CheckboxMetrics$Companion;JLandroidx/compose/foundation/shape/CornerSize;Landroidx/compose/foundation/shape/CornerSize;JJF)Lorg/jetbrains/jewel/ui/component/styling/CheckboxMetrics;
public static synthetic fun defaults-XIZ8g8E$default (Lorg/jetbrains/jewel/ui/component/styling/CheckboxMetrics$Companion;JLandroidx/compose/foundation/shape/CornerSize;Landroidx/compose/foundation/shape/CornerSize;JJFILjava/lang/Object;)Lorg/jetbrains/jewel/ui/component/styling/CheckboxMetrics;
public static final fun light (Lorg/jetbrains/jewel/ui/component/styling/CheckboxIcons$Companion;Lorg/jetbrains/jewel/ui/painter/PainterProvider;Landroidx/compose/runtime/Composer;II)Lorg/jetbrains/jewel/ui/component/styling/CheckboxIcons;
public static final fun light (Lorg/jetbrains/jewel/ui/component/styling/CheckboxStyle$Companion;Lorg/jetbrains/jewel/ui/component/styling/CheckboxColors;Lorg/jetbrains/jewel/ui/component/styling/CheckboxMetrics;Lorg/jetbrains/jewel/ui/component/styling/CheckboxIcons;Landroidx/compose/runtime/Composer;II)Lorg/jetbrains/jewel/ui/component/styling/CheckboxStyle;
public static final fun light-GyCwops (Lorg/jetbrains/jewel/ui/component/styling/CheckboxColors$Companion;JJJLandroidx/compose/runtime/Composer;II)Lorg/jetbrains/jewel/ui/component/styling/CheckboxColors;
Expand Down Expand Up @@ -237,8 +237,8 @@ public final class org/jetbrains/jewel/intui/standalone/styling/IntUiRadioButton
public static final fun dark (Lorg/jetbrains/jewel/ui/component/styling/RadioButtonStyle$Companion;Lorg/jetbrains/jewel/ui/component/styling/RadioButtonColors;Lorg/jetbrains/jewel/ui/component/styling/RadioButtonMetrics;Lorg/jetbrains/jewel/ui/component/styling/RadioButtonIcons;Landroidx/compose/runtime/Composer;II)Lorg/jetbrains/jewel/ui/component/styling/RadioButtonStyle;
public static synthetic fun dark$default (Lorg/jetbrains/jewel/ui/component/styling/RadioButtonIcons$Companion;Lorg/jetbrains/jewel/ui/painter/PainterProvider;ILjava/lang/Object;)Lorg/jetbrains/jewel/ui/component/styling/RadioButtonIcons;
public static final fun dark-dPtIKUs (Lorg/jetbrains/jewel/ui/component/styling/RadioButtonColors$Companion;JJJJJJLandroidx/compose/runtime/Composer;II)Lorg/jetbrains/jewel/ui/component/styling/RadioButtonColors;
public static final fun defaults-Q6CdCac (Lorg/jetbrains/jewel/ui/component/styling/RadioButtonMetrics$Companion;JF)Lorg/jetbrains/jewel/ui/component/styling/RadioButtonMetrics;
public static synthetic fun defaults-Q6CdCac$default (Lorg/jetbrains/jewel/ui/component/styling/RadioButtonMetrics$Companion;JFILjava/lang/Object;)Lorg/jetbrains/jewel/ui/component/styling/RadioButtonMetrics;
public static final fun defaults-eb3e7j0 (Lorg/jetbrains/jewel/ui/component/styling/RadioButtonMetrics$Companion;JJJF)Lorg/jetbrains/jewel/ui/component/styling/RadioButtonMetrics;
public static synthetic fun defaults-eb3e7j0$default (Lorg/jetbrains/jewel/ui/component/styling/RadioButtonMetrics$Companion;JJJFILjava/lang/Object;)Lorg/jetbrains/jewel/ui/component/styling/RadioButtonMetrics;
public static final fun light (Lorg/jetbrains/jewel/ui/component/styling/RadioButtonIcons$Companion;Lorg/jetbrains/jewel/ui/painter/PainterProvider;)Lorg/jetbrains/jewel/ui/component/styling/RadioButtonIcons;
public static final fun light (Lorg/jetbrains/jewel/ui/component/styling/RadioButtonStyle$Companion;Lorg/jetbrains/jewel/ui/component/styling/RadioButtonColors;Lorg/jetbrains/jewel/ui/component/styling/RadioButtonMetrics;Lorg/jetbrains/jewel/ui/component/styling/RadioButtonIcons;Landroidx/compose/runtime/Composer;II)Lorg/jetbrains/jewel/ui/component/styling/RadioButtonStyle;
public static synthetic fun light$default (Lorg/jetbrains/jewel/ui/component/styling/RadioButtonIcons$Companion;Lorg/jetbrains/jewel/ui/painter/PainterProvider;ILjava/lang/Object;)Lorg/jetbrains/jewel/ui/component/styling/RadioButtonIcons;
Expand Down
Loading

0 comments on commit 925b885

Please sign in to comment.