Skip to content

Commit

Permalink
Replace icon paths with keys (#439)
Browse files Browse the repository at this point in the history
* Replace icon paths with keys

* Clean up lint warnings
  • Loading branch information
rock3r authored Jul 9, 2024
1 parent b718ff8 commit 156d3b9
Show file tree
Hide file tree
Showing 30 changed files with 214 additions and 160 deletions.
1 change: 1 addition & 0 deletions ide-laf-bridge/api/ide-laf-bridge.api
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public final class org/jetbrains/jewel/bridge/BridgePainterHintsProvider$Compani

public final class org/jetbrains/jewel/bridge/BridgeResourceResolverKt {
public static final fun bridgePainterProvider (Ljava/lang/String;)Lorg/jetbrains/jewel/ui/painter/ResourcePainterProvider;
public static final fun bridgePainterProvider (Lorg/jetbrains/jewel/ui/icon/IconKey;)Lorg/jetbrains/jewel/ui/painter/ResourcePainterProvider;
}

public final class org/jetbrains/jewel/bridge/BridgeUtilsKt {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
package org.jetbrains.jewel.bridge

import com.intellij.util.ui.DirProvider
import org.jetbrains.jewel.ui.icon.IconKey
import org.jetbrains.jewel.ui.painter.ResourcePainterProvider

/**
* [ResourcePainterProvider] to resolve resource in Intellij Module and
* [ResourcePainterProvider] to resolve resources in Intellij Module and
* Bridge module.
*/
public fun bridgePainterProvider(path: String): ResourcePainterProvider =
ResourcePainterProvider(path, DirProvider::class.java.classLoader, SwingBridgeService::class.java.classLoader)

/**
* [ResourcePainterProvider] to resolve resources in Intellij Module and
* Bridge module.
*/
public fun bridgePainterProvider(iconKey: IconKey): ResourcePainterProvider {
val isNewUi = isNewUiTheme()
return ResourcePainterProvider(
iconKey.path(isNewUi),
DirProvider::class.java.classLoader,
SwingBridgeService::class.java.classLoader,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import com.intellij.ui.JBColor
import com.intellij.util.ui.DirProvider
import com.intellij.util.ui.JBUI
import com.intellij.util.ui.NamedColorUtil
import org.jetbrains.jewel.bridge.bridgePainterProvider
import org.jetbrains.jewel.bridge.createVerticalBrush
import org.jetbrains.jewel.bridge.dp
import org.jetbrains.jewel.bridge.isNewUiTheme
Expand Down Expand Up @@ -118,6 +117,8 @@ import org.jetbrains.jewel.ui.component.styling.TextFieldStyle
import org.jetbrains.jewel.ui.component.styling.TooltipColors
import org.jetbrains.jewel.ui.component.styling.TooltipMetrics
import org.jetbrains.jewel.ui.component.styling.TooltipStyle
import org.jetbrains.jewel.ui.icon.PathIconKey
import org.jetbrains.jewel.ui.icons.AllIconsKeys
import javax.swing.UIManager
import kotlin.time.Duration.Companion.milliseconds

Expand Down Expand Up @@ -378,7 +379,7 @@ private fun readCheckboxStyle(): CheckboxStyle {
outlineSelectedFocusedSize = metrics.outlineSelectedFocusedSize,
iconContentGap = metrics.iconContentGap,
),
icons = CheckboxIcons(checkbox = bridgePainterProvider("${iconsBasePath}checkBox.svg")),
icons = CheckboxIcons(checkbox = PathIconKey("${iconsBasePath}checkBox.svg")),
)
}

Expand Down Expand Up @@ -539,7 +540,7 @@ private fun readDefaultDropdownStyle(
contentPadding = retrieveInsetsAsPaddingValues("ComboBox.padding"),
borderWidth = DarculaUIUtil.LW.dp,
),
icons = DropdownIcons(chevronDown = bridgePainterProvider("general/chevron-down.svg")),
icons = DropdownIcons(chevronDown = AllIconsKeys.General.ChevronDown),
textStyle = dropdownTextStyle,
menuStyle = menuStyle,
)
Expand Down Expand Up @@ -590,7 +591,7 @@ private fun readUndecoratedDropdownStyle(
contentPadding = PaddingValues(3.dp), // from com.intellij.ide.ui.laf.darcula.ui.DarculaComboBoxUI.getDefaultComboBoxInsets
borderWidth = 0.dp,
),
icons = DropdownIcons(chevronDown = bridgePainterProvider("general/chevron-down.svg")),
icons = DropdownIcons(chevronDown = AllIconsKeys.General.ChevronDown),
textStyle = dropdownTextStyle,
menuStyle = menuStyle,
)
Expand Down Expand Up @@ -664,8 +665,8 @@ private fun readLinkStyle(linkTextStyle: TextStyle): LinkStyle {
),
icons =
LinkIcons(
dropdownChevron = bridgePainterProvider("general/chevron-down.svg"),
externalLink = bridgePainterProvider("ide/external_link_arrow.svg"),
dropdownChevron = AllIconsKeys.General.ChevronDown,
externalLink = AllIconsKeys.Ide.External_link_arrow,
),
textStyles =
LinkTextStyles(
Expand Down Expand Up @@ -755,7 +756,7 @@ private fun readMenuStyle(): MenuStyle {
),
submenuMetrics = SubmenuMetrics(offset = DpOffset(0.dp, (-8).dp)),
),
icons = MenuIcons(submenuChevron = bridgePainterProvider("general/chevron-right.svg")),
icons = MenuIcons(submenuChevron = AllIconsKeys.General.ChevronRight),
)
}

Expand Down Expand Up @@ -798,7 +799,7 @@ private fun readRadioButtonStyle(): RadioButtonStyle {
retrieveIntAsDpOrUnspecified("RadioButton.textIconGap")
.takeOrElse { metrics.iconContentGap },
),
icons = RadioButtonIcons(radioButton = bridgePainterProvider("${iconsBasePath}radio.svg")),
icons = RadioButtonIcons(radioButton = PathIconKey("${iconsBasePath}radio.svg")),
)
}

Expand Down Expand Up @@ -976,11 +977,9 @@ private fun readLazyTreeStyle(): LazyTreeStyle {
elementBackgroundSelectedFocused = selectedElementBackground,
)

val chevronCollapsed = bridgePainterProvider("general/chevron-right.svg")
val chevronExpanded = bridgePainterProvider("general/chevron-down.svg")

val leftIndent = retrieveIntAsDpOrUnspecified("Tree.leftChildIndent").takeOrElse { 7.dp }
val rightIndent = retrieveIntAsDpOrUnspecified("Tree.rightChildIndent").takeOrElse { 11.dp }

return LazyTreeStyle(
colors = colors,
metrics =
Expand All @@ -994,10 +993,10 @@ private fun readLazyTreeStyle(): LazyTreeStyle {
),
icons =
LazyTreeIcons(
chevronCollapsed = chevronCollapsed,
chevronExpanded = chevronExpanded,
chevronSelectedCollapsed = chevronCollapsed,
chevronSelectedExpanded = chevronExpanded,
chevronCollapsed = AllIconsKeys.General.ChevronRight,
chevronExpanded = AllIconsKeys.General.ChevronDown,
chevronSelectedCollapsed = AllIconsKeys.General.ChevronRight,
chevronSelectedExpanded = AllIconsKeys.General.ChevronDown,
),
)
}
Expand Down Expand Up @@ -1040,7 +1039,7 @@ private fun readDefaultTabStyle(): TabStyle {
tabContentSpacing = 4.dp,
tabHeight = retrieveIntAsDpOrUnspecified("TabbedPane.tabHeight").takeOrElse { 24.dp },
),
icons = TabIcons(close = bridgePainterProvider("expui/general/closeSmall.svg")),
icons = TabIcons(close = AllIconsKeys.General.CloseSmall),
contentAlpha =
TabContentAlpha(
iconNormal = 1f,
Expand Down Expand Up @@ -1096,7 +1095,7 @@ private fun readEditorTabStyle(): TabStyle {
retrieveIntAsDpOrUnspecified("TabbedPane.tabHeight")
.takeOrElse { 24.dp },
),
icons = TabIcons(close = bridgePainterProvider("expui/general/closeSmall.svg")),
icons = TabIcons(close = AllIconsKeys.General.CloseSmall),
contentAlpha =
TabContentAlpha(
iconNormal = .7f,
Expand Down
Loading

0 comments on commit 156d3b9

Please sign in to comment.