Skip to content
This repository was archived by the owner on Apr 22, 2025. It is now read-only.

Commit 5a060a3

Browse files
committed
Make BridgeUtils public APIs
1 parent c438a8e commit 5a060a3

File tree

1 file changed

+16
-27
lines changed
  • ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge

1 file changed

+16
-27
lines changed

ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/BridgeUtils.kt

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,22 @@ fun java.awt.Color.toComposeColor() = Color(
3838
fun java.awt.Color?.toComposeColorOrUnspecified() = this?.toComposeColor() ?: Color.Unspecified
3939

4040
@Suppress("UnstableApiUsage")
41-
internal fun retrieveColorOrNull(key: String) =
41+
fun retrieveColorOrNull(key: String) =
4242
JBColor.namedColor(key)
4343
.takeUnless { it.name == "NAMED_COLOR_FALLBACK_MARKER" }
4444
?.toComposeColor()
4545

46-
internal fun retrieveColorOrUnspecified(key: String): Color {
46+
fun retrieveColorOrUnspecified(key: String): Color {
4747
val color = retrieveColorOrNull(key)
4848
if (color == null) {
4949
logger.warn("Color with key \"$key\" not found, fallback to 'Color.Unspecified'")
5050
}
5151
return color ?: Color.Unspecified
5252
}
5353

54-
internal fun retrieveColorsOrUnspecified(vararg keys: String) = keys.map { retrieveColorOrUnspecified(it) }
54+
fun retrieveColorsOrUnspecified(vararg keys: String) = keys.map { retrieveColorOrUnspecified(it) }
5555

56-
internal fun List<Color>.createVerticalBrush(
56+
fun List<Color>.createVerticalBrush(
5757
startY: Float = 0.0f,
5858
endY: Float = Float.POSITIVE_INFINITY,
5959
tileMode: TileMode = TileMode.Clamp,
@@ -67,29 +67,29 @@ internal fun List<Color>.createVerticalBrush(
6767
return Brush.verticalGradient(this, startY, endY, tileMode)
6868
}
6969

70-
internal fun retrieveIntAsDp(key: String): Dp {
70+
fun retrieveIntAsDp(key: String): Dp {
7171
val rawValue = UIManager.get(key)
7272
if (rawValue is Int) rawValue.dp
7373

7474
keyNotFound(key, "Int")
7575
}
7676

77-
internal fun retrieveIntAsDpOrUnspecified(key: String) =
77+
fun retrieveIntAsDpOrUnspecified(key: String) =
7878
try {
7979
retrieveIntAsDp(key)
8080
} catch (ignored: JewelBridgeException) {
8181
Dp.Unspecified
8282
}
8383

84-
internal fun retrieveInsetsAsPaddingValues(key: String) =
84+
fun retrieveInsetsAsPaddingValues(key: String) =
8585
UIManager.getInsets(key)
8686
?.let { PaddingValues(it.left.dp, it.top.dp, it.right.dp, it.bottom.dp) }
8787
?: keyNotFound(key, "Insets")
8888

89-
internal fun retrieveArcAsCornerSize(key: String) =
89+
fun retrieveArcAsCornerSize(key: String) =
9090
CornerSize(retrieveIntAsDp(key) / 2)
9191

92-
internal fun retrieveArcAsCornerSizeWithFallbacks(vararg keys: String): CornerSize {
92+
fun retrieveArcAsCornerSizeWithFallbacks(vararg keys: String): CornerSize {
9393
for (key in keys) {
9494
val rawValue = UIManager.get(key)
9595
if (rawValue is Int) {
@@ -106,13 +106,14 @@ internal fun retrieveArcAsCornerSizeWithFallbacks(vararg keys: String): CornerSi
106106
@OptIn(DependsOnJBR::class)
107107
private val awtFontManager = AwtFontManager()
108108

109-
internal suspend fun retrieveTextStyle(fontKey: String, colorKey: String? = null): TextStyle {
109+
@DependsOnJBR
110+
suspend fun retrieveTextStyle(fontKey: String, colorKey: String? = null): TextStyle {
110111
val baseColor = colorKey?.let { retrieveColorOrUnspecified(colorKey) } ?: Color.Unspecified
111112
return retrieveTextStyle(fontKey, color = baseColor)
112113
}
113114

114-
@OptIn(DependsOnJBR::class)
115-
internal suspend fun retrieveTextStyle(
115+
@DependsOnJBR
116+
suspend fun retrieveTextStyle(
116117
key: String,
117118
color: Color = Color.Unspecified,
118119
lineHeight: TextUnit = TextUnit.Unspecified,
@@ -140,22 +141,10 @@ internal suspend fun retrieveTextStyle(
140141
}
141142
}
142143

143-
internal val JBValue.dp
144+
val JBValue.dp
144145
get() = unscaled.dp
145146

146-
internal fun TextStyle.derive(sizeDelta: Float, weight: FontWeight? = fontWeight, color: Color = toSpanStyle().color) =
147-
copy(fontSize = fontSize - sizeDelta, fontWeight = weight, color = color)
148-
149-
internal operator fun TextUnit.minus(delta: Float) = plus(-delta)
150-
151-
internal operator fun TextUnit.plus(delta: Float) =
152-
when {
153-
isSp -> TextUnit(value + delta, type)
154-
isEm -> TextUnit(value + delta, type)
155-
else -> this
156-
}
157-
158-
internal fun <T : InteractiveComponentState> retrieveStatefulIcon(
147+
fun <T : InteractiveComponentState> retrieveStatefulIcon(
159148
iconPath: String,
160149
svgLoader: SvgLoader,
161150
iconData: IntelliJThemeIconData,
@@ -170,7 +159,7 @@ internal fun <T : InteractiveComponentState> retrieveStatefulIcon(
170159
suffixTokensProvider,
171160
)
172161

173-
internal fun retrieveStatelessIcon(
162+
fun retrieveStatelessIcon(
174163
iconPath: String,
175164
svgLoader: SvgLoader,
176165
iconData: IntelliJThemeIconData,

0 commit comments

Comments
 (0)