Skip to content

Commit

Permalink
Rename palette entry grey -> gray (#486)
Browse files Browse the repository at this point in the history
The name was changed in 242 to reflect the fact that everything else is
named in en-US, and for consistency with the Int UI specs. This change
aligns us to that, leaving a deprecated grey accessor in
ThemeColorPalette for backwards compat. The lookup function also accepts
both spellings for the time being.

This also bumps the theme generator to target IJP 242.

Note that some of these changes will not be ported to earlier releases —
only the ThemeColorPalette property name changes and lookup behaviour —
since in 233 and 241 the keys are still named in en-GB in the theme json
  • Loading branch information
rock3r authored Jul 24, 2024
1 parent 6eb85eb commit 3f24aca
Show file tree
Hide file tree
Showing 30 changed files with 257 additions and 266 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@ import com.squareup.kotlinpoet.ClassName
import com.squareup.kotlinpoet.CodeBlock
import com.squareup.kotlinpoet.FileSpec
import com.squareup.kotlinpoet.KModifier
import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy
import com.squareup.kotlinpoet.PropertySpec
import com.squareup.kotlinpoet.TypeSpec
import com.squareup.kotlinpoet.asTypeName
import com.squareup.kotlinpoet.joinToCode
import kotlinx.serialization.json.JsonObject
import kotlinx.serialization.json.JsonPrimitive

internal object IntUiThemeDescriptorReader {

private val colorGroups =
setOf("Grey", "Blue", "Green", "Red", "Yellow", "Orange", "Purple", "Teal")
setOf("Gray", "Blue", "Green", "Red", "Yellow", "Orange", "Purple", "Teal")
private val colorClassName = ClassName("androidx.compose.ui.graphics", "Color")

fun readThemeFrom(
Expand Down Expand Up @@ -136,20 +134,4 @@ internal object IntUiThemeDescriptorReader {
private inline fun <reified K, reified V> Map<K, V>.toMapCodeBlock() =
entries.map { (key, value) -> CodeBlock.of("\"%L\" to \"%L\"", key, value) }
.joinToCode(prefix = "mapOf(", separator = ",\n", suffix = ")")

private inline fun <reified K, reified V> createOverrideStringMapProperty(
name: String,
values: Map<K, V>,
) =
PropertySpec.builder(
name = name,
type = Map::class.asTypeName().parameterizedBy(K::class.asTypeName(), V::class.asTypeName()),
KModifier.OVERRIDE
)
.initializer(
values.entries
.map { (key, value) -> CodeBlock.of("\"%L\" to \"%L\"", key, value) }
.joinToCode(prefix = "mapOf(", separator = ",\n", suffix = ")")
)
.build()
}
4 changes: 3 additions & 1 deletion foundation/api/foundation.api
Original file line number Diff line number Diff line change
Expand Up @@ -806,14 +806,16 @@ public final class org/jetbrains/jewel/foundation/theme/ThemeColorPalette {
public final fun blueOrNull-ijrfgN4 (I)Landroidx/compose/ui/graphics/Color;
public fun equals (Ljava/lang/Object;)Z
public final fun getBlue ()Ljava/util/List;
public final fun getGray ()Ljava/util/List;
public final fun getGreen ()Ljava/util/List;
public final fun getGrey ()Ljava/util/List;
public final fun getOrange ()Ljava/util/List;
public final fun getPurple ()Ljava/util/List;
public final fun getRawMap ()Ljava/util/Map;
public final fun getRed ()Ljava/util/List;
public final fun getTeal ()Ljava/util/List;
public final fun getYellow ()Ljava/util/List;
public final fun gray-vNxB06k (I)J
public final fun grayOrNull-ijrfgN4 (I)Landroidx/compose/ui/graphics/Color;
public final fun green-vNxB06k (I)J
public final fun greenOrNull-ijrfgN4 (I)Landroidx/compose/ui/graphics/Color;
public final fun grey-vNxB06k (I)J
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import org.jetbrains.jewel.foundation.GenerateDataFunctions
private val colorKeyRegex: Regex
get() = "([a-z]+)(\\d+)".toRegex(RegexOption.IGNORE_CASE)

@Suppress("MemberVisibilityCanBePrivate")
@Immutable
@GenerateDataFunctions
public class ThemeColorPalette(
public val grey: List<Color>,
public val gray: List<Color>,
public val blue: List<Color>,
public val green: List<Color>,
public val red: List<Color>,
Expand All @@ -20,9 +21,15 @@ public class ThemeColorPalette(
public val teal: List<Color>,
public val rawMap: Map<String, Color>,
) {
public fun grey(index: Int): Color = grey[index - 1]
@Deprecated("Use gray() instead", ReplaceWith("gray(index)"))
public fun grey(index: Int): Color = gray(index)

public fun greyOrNull(index: Int): Color? = grey.getOrNull(index - 1)
@Deprecated("Use grayOrNull() instead", ReplaceWith("grayOrNull(index)"))
public fun greyOrNull(index: Int): Color? = grayOrNull(index)

public fun gray(index: Int): Color = gray[index - 1]

public fun grayOrNull(index: Int): Color? = gray.getOrNull(index - 1)

public fun blue(index: Int): Color = blue[index - 1]

Expand Down Expand Up @@ -62,7 +69,7 @@ public class ThemeColorPalette(
}

return when (colorGroup) {
"grey" -> grey(colorIndex)
"grey", "gray" -> gray(colorIndex)
"blue" -> blue(colorIndex)
"green" -> green(colorIndex)
"red" -> red(colorIndex)
Expand All @@ -77,7 +84,7 @@ public class ThemeColorPalette(
public companion object {
public val Empty: ThemeColorPalette =
ThemeColorPalette(
grey = emptyList(),
gray = emptyList(),
blue = emptyList(),
green = emptyList(),
red = emptyList(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public val ThemeColorPalette.windowsPopupBorder: Color?
get() = lookup("windowsPopupBorder")

public fun ThemeColorPalette.Companion.readFromLaF(): ThemeColorPalette {
val grey = readPaletteColors("Grey")
val gray = readPaletteColors("Grey")
val blue = readPaletteColors("Blue")
val green = readPaletteColors("Green")
val red = readPaletteColors("Red")
Expand All @@ -25,7 +25,7 @@ public fun ThemeColorPalette.Companion.readFromLaF(): ThemeColorPalette {

val rawMap =
buildMap {
putAll(grey)
putAll(gray)
putAll(blue)
putAll(green)
putAll(red)
Expand All @@ -37,7 +37,7 @@ public fun ThemeColorPalette.Companion.readFromLaF(): ThemeColorPalette {
}

return ThemeColorPalette(
grey = grey.values.toList(),
gray = gray.values.toList(),
blue = blue.values.toList(),
green = green.values.toList(),
red = red.values.toList(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,10 @@ private fun titleBarIconButtonStyle(

@Composable
public fun TitleBarColors.Companion.light(
backgroundColor: Color = IntUiLightTheme.colors.grey(2),
inactiveBackground: Color = IntUiLightTheme.colors.grey(3),
contentColor: Color = IntUiLightTheme.colors.grey(12),
borderColor: Color = IntUiLightTheme.colors.grey(4),
backgroundColor: Color = IntUiLightTheme.colors.gray(2),
inactiveBackground: Color = IntUiLightTheme.colors.gray(3),
contentColor: Color = IntUiLightTheme.colors.gray(12),
borderColor: Color = IntUiLightTheme.colors.gray(4),
fullscreenControlButtonsBackground: Color = Color(0xFF7A7B80),
// Color hex from
// com.intellij.util.ui.JBUI.CurrentTheme.CustomFrameDecorations.titlePaneButtonHoveredBackground
Expand All @@ -220,8 +220,8 @@ public fun TitleBarColors.Companion.light(
// com.intellij.openapi.wm.impl.customFrameDecorations.CustomFrameTitleButtons.closeStyleBuilder
titlePaneCloseButtonHoveredBackground: Color = Color(0xFFE81123),
titlePaneCloseButtonPressedBackground: Color = Color(0xFFF1707A),
iconButtonHoveredBackground: Color = IntUiLightTheme.colors.grey(3),
iconButtonPressedBackground: Color = IntUiLightTheme.colors.grey(3),
iconButtonHoveredBackground: Color = IntUiLightTheme.colors.gray(3),
iconButtonPressedBackground: Color = IntUiLightTheme.colors.gray(3),
// There are two fields in theme.json: transparentHoveredBackground and hoveredBackground,
// but in com.intellij.ide.ui.laf.darcula.ui.ToolbarComboWidgetUI#paintBackground,
// transparentHoveredBackground is used first, which is guessed to be due to the gradient
Expand Down Expand Up @@ -251,17 +251,17 @@ public fun TitleBarColors.Companion.light(

@Composable
public fun TitleBarColors.Companion.lightWithLightHeader(
backgroundColor: Color = IntUiLightTheme.colors.grey(13),
inactiveBackground: Color = IntUiLightTheme.colors.grey(12),
backgroundColor: Color = IntUiLightTheme.colors.gray(13),
inactiveBackground: Color = IntUiLightTheme.colors.gray(12),
fullscreenControlButtonsBackground: Color = Color(0xFF7A7B80),
contentColor: Color = IntUiLightTheme.colors.grey(1),
borderColor: Color = IntUiLightTheme.colors.grey(11),
contentColor: Color = IntUiLightTheme.colors.gray(1),
borderColor: Color = IntUiLightTheme.colors.gray(11),
titlePaneButtonHoveredBackground: Color = Color(0x1A000000),
titlePaneButtonPressedBackground: Color = titlePaneButtonHoveredBackground,
titlePaneCloseButtonHoveredBackground: Color = Color(0xFFE81123),
titlePaneCloseButtonPressedBackground: Color = Color(0xFFF1707A),
iconButtonHoveredBackground: Color = IntUiLightTheme.colors.grey(12),
iconButtonPressedBackground: Color = IntUiLightTheme.colors.grey(11),
iconButtonHoveredBackground: Color = IntUiLightTheme.colors.gray(12),
iconButtonPressedBackground: Color = IntUiLightTheme.colors.gray(11),
dropdownHoveredBackground: Color = Color(0x0D000000),
dropdownPressedBackground: Color = dropdownHoveredBackground,
): TitleBarColors =
Expand All @@ -283,17 +283,17 @@ public fun TitleBarColors.Companion.lightWithLightHeader(

@Composable
public fun TitleBarColors.Companion.dark(
backgroundColor: Color = IntUiDarkTheme.colors.grey(2),
inactiveBackground: Color = IntUiDarkTheme.colors.grey(3),
backgroundColor: Color = IntUiDarkTheme.colors.gray(2),
inactiveBackground: Color = IntUiDarkTheme.colors.gray(3),
fullscreenControlButtonsBackground: Color = Color(0xFF575A5C),
contentColor: Color = IntUiDarkTheme.colors.grey(12),
borderColor: Color = IntUiDarkTheme.colors.grey(4),
contentColor: Color = IntUiDarkTheme.colors.gray(12),
borderColor: Color = IntUiDarkTheme.colors.gray(4),
titlePaneButtonHoveredBackground: Color = Color(0x1AFFFFFF),
titlePaneButtonPressedBackground: Color = titlePaneButtonHoveredBackground,
titlePaneCloseButtonHoveredBackground: Color = Color(0xFFE81123),
titlePaneCloseButtonPressedBackground: Color = Color(0xFFF1707A),
iconButtonHoveredBackground: Color = IntUiLightTheme.colors.grey(3),
iconButtonPressedBackground: Color = IntUiLightTheme.colors.grey(3),
iconButtonHoveredBackground: Color = IntUiLightTheme.colors.gray(3),
iconButtonPressedBackground: Color = IntUiLightTheme.colors.gray(3),
dropdownHoveredBackground: Color = Color(0x1AFFFFFF),
dropdownPressedBackground: Color = dropdownHoveredBackground,
): TitleBarColors =
Expand Down
2 changes: 1 addition & 1 deletion int-ui/int-ui-standalone/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
dependencies { api(projects.ui) }

intelliJThemeGenerator {
val targetIdeaVersion = "241.9959"
val targetIdeaVersion = "idea/242.20224.91"
register("intUiLight") {
themeClassName = "org.jetbrains.jewel.intui.core.theme.IntUiLightTheme"
themeFile = "platform/platform-resources/src/themes/expUI/expUI_light.theme.json"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,18 @@ public object IntUiDefaultButtonColorFactory {
@Composable
public fun light(
background: Brush = SolidColor(IntUiLightTheme.colors.blue(4)),
backgroundDisabled: Brush = SolidColor(IntUiLightTheme.colors.grey(12)),
backgroundDisabled: Brush = SolidColor(IntUiLightTheme.colors.gray(12)),
backgroundFocused: Brush = SolidColor(IntUiLightTheme.colors.blue(4)),
backgroundPressed: Brush = SolidColor(IntUiLightTheme.colors.blue(2)),
backgroundHovered: Brush = SolidColor(IntUiLightTheme.colors.blue(3)),
content: Color = IntUiLightTheme.colors.grey(14),
contentDisabled: Color = IntUiLightTheme.colors.grey(8),
contentFocused: Color = IntUiLightTheme.colors.grey(14),
contentPressed: Color = IntUiLightTheme.colors.grey(14),
contentHovered: Color = IntUiLightTheme.colors.grey(14),
content: Color = IntUiLightTheme.colors.gray(14),
contentDisabled: Color = IntUiLightTheme.colors.gray(8),
contentFocused: Color = IntUiLightTheme.colors.gray(14),
contentPressed: Color = IntUiLightTheme.colors.gray(14),
contentHovered: Color = IntUiLightTheme.colors.gray(14),
border: Brush = SolidColor(IntUiLightTheme.colors.blue(4)),
borderDisabled: Brush = SolidColor(IntUiLightTheme.colors.grey(12)),
borderFocused: Brush = SolidColor(IntUiLightTheme.colors.grey(14)),
borderDisabled: Brush = SolidColor(IntUiLightTheme.colors.gray(12)),
borderFocused: Brush = SolidColor(IntUiLightTheme.colors.gray(14)),
borderPressed: Brush = borderFocused,
borderHovered: Brush = border,
): ButtonColors =
Expand All @@ -97,18 +97,18 @@ public object IntUiDefaultButtonColorFactory {
@Composable
public fun dark(
background: Brush = SolidColor(IntUiDarkTheme.colors.blue(6)),
backgroundDisabled: Brush = SolidColor(IntUiDarkTheme.colors.grey(5)),
backgroundDisabled: Brush = SolidColor(IntUiDarkTheme.colors.gray(5)),
backgroundFocused: Brush = SolidColor(IntUiDarkTheme.colors.blue(6)),
backgroundPressed: Brush = SolidColor(IntUiDarkTheme.colors.blue(4)),
backgroundHovered: Brush = SolidColor(IntUiDarkTheme.colors.blue(5)),
content: Color = IntUiDarkTheme.colors.grey(14),
contentDisabled: Color = IntUiDarkTheme.colors.grey(8),
contentFocused: Color = IntUiDarkTheme.colors.grey(14),
contentPressed: Color = IntUiDarkTheme.colors.grey(14),
contentHovered: Color = IntUiDarkTheme.colors.grey(14),
content: Color = IntUiDarkTheme.colors.gray(14),
contentDisabled: Color = IntUiDarkTheme.colors.gray(8),
contentFocused: Color = IntUiDarkTheme.colors.gray(14),
contentPressed: Color = IntUiDarkTheme.colors.gray(14),
contentHovered: Color = IntUiDarkTheme.colors.gray(14),
border: Brush = SolidColor(IntUiDarkTheme.colors.blue(6)),
borderDisabled: Brush = SolidColor(IntUiDarkTheme.colors.grey(5)),
borderFocused: Brush = SolidColor(IntUiDarkTheme.colors.grey(1)),
borderDisabled: Brush = SolidColor(IntUiDarkTheme.colors.gray(5)),
borderFocused: Brush = SolidColor(IntUiDarkTheme.colors.gray(1)),
borderPressed: Brush = borderFocused,
borderHovered: Brush = border,
): ButtonColors =
Expand Down Expand Up @@ -137,21 +137,21 @@ public val ButtonColors.Companion.Outlined: IntUiOutlinedButtonColorFactory
public object IntUiOutlinedButtonColorFactory {
@Composable
public fun light(
background: Brush = SolidColor(IntUiLightTheme.colors.grey(14)),
backgroundDisabled: Brush = SolidColor(IntUiLightTheme.colors.grey(12)),
background: Brush = SolidColor(IntUiLightTheme.colors.gray(14)),
backgroundDisabled: Brush = SolidColor(IntUiLightTheme.colors.gray(12)),
backgroundFocused: Brush = background,
backgroundPressed: Brush = SolidColor(IntUiLightTheme.colors.grey(13)),
backgroundPressed: Brush = SolidColor(IntUiLightTheme.colors.gray(13)),
backgroundHovered: Brush = background,
content: Color = IntUiLightTheme.colors.grey(1),
contentDisabled: Color = IntUiLightTheme.colors.grey(8),
content: Color = IntUiLightTheme.colors.gray(1),
contentDisabled: Color = IntUiLightTheme.colors.gray(8),
contentFocused: Color = content,
contentPressed: Color = content,
contentHovered: Color = content,
border: Brush = SolidColor(IntUiLightTheme.colors.grey(9)),
borderDisabled: Brush = SolidColor(IntUiLightTheme.colors.grey(12)),
border: Brush = SolidColor(IntUiLightTheme.colors.gray(9)),
borderDisabled: Brush = SolidColor(IntUiLightTheme.colors.gray(12)),
borderFocused: Brush = SolidColor(IntUiLightTheme.colors.blue(4)),
borderPressed: Brush = SolidColor(IntUiLightTheme.colors.grey(7)),
borderHovered: Brush = SolidColor(IntUiLightTheme.colors.grey(8)),
borderPressed: Brush = SolidColor(IntUiLightTheme.colors.gray(7)),
borderHovered: Brush = SolidColor(IntUiLightTheme.colors.gray(8)),
): ButtonColors =
ButtonColors(
background = background,
Expand All @@ -174,20 +174,20 @@ public object IntUiOutlinedButtonColorFactory {
@Composable
public fun dark(
background: Brush = SolidColor(Color.Transparent),
backgroundDisabled: Brush = SolidColor(IntUiDarkTheme.colors.grey(5)),
backgroundDisabled: Brush = SolidColor(IntUiDarkTheme.colors.gray(5)),
backgroundFocused: Brush = background,
backgroundPressed: Brush = SolidColor(IntUiDarkTheme.colors.grey(2)),
backgroundPressed: Brush = SolidColor(IntUiDarkTheme.colors.gray(2)),
backgroundHovered: Brush = SolidColor(Color.Unspecified),
content: Color = IntUiDarkTheme.colors.grey(12),
contentDisabled: Color = IntUiDarkTheme.colors.grey(8),
contentFocused: Color = IntUiDarkTheme.colors.grey(12),
contentPressed: Color = IntUiDarkTheme.colors.grey(12),
contentHovered: Color = IntUiDarkTheme.colors.grey(12),
border: Brush = SolidColor(IntUiDarkTheme.colors.grey(5)),
borderDisabled: Brush = SolidColor(IntUiDarkTheme.colors.grey(5)),
borderFocused: Brush = SolidColor(IntUiDarkTheme.colors.grey(2)),
borderPressed: Brush = SolidColor(IntUiDarkTheme.colors.grey(7)),
borderHovered: Brush = SolidColor(IntUiDarkTheme.colors.grey(7)),
content: Color = IntUiDarkTheme.colors.gray(12),
contentDisabled: Color = IntUiDarkTheme.colors.gray(8),
contentFocused: Color = IntUiDarkTheme.colors.gray(12),
contentPressed: Color = IntUiDarkTheme.colors.gray(12),
contentHovered: Color = IntUiDarkTheme.colors.gray(12),
border: Brush = SolidColor(IntUiDarkTheme.colors.gray(5)),
borderDisabled: Brush = SolidColor(IntUiDarkTheme.colors.gray(5)),
borderFocused: Brush = SolidColor(IntUiDarkTheme.colors.gray(2)),
borderPressed: Brush = SolidColor(IntUiDarkTheme.colors.gray(7)),
borderHovered: Brush = SolidColor(IntUiDarkTheme.colors.gray(7)),
): ButtonColors =
ButtonColors(
background = background,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ public fun CheckboxStyle.Companion.dark(
@Composable
public fun CheckboxColors.Companion.light(
content: Color = Color.Unspecified,
contentDisabled: Color = IntUiLightTheme.colors.grey(8),
contentDisabled: Color = IntUiLightTheme.colors.gray(8),
contentSelected: Color = content,
): CheckboxColors = CheckboxColors(content, contentDisabled, contentSelected)

@Composable
public fun CheckboxColors.Companion.dark(
content: Color = Color.Unspecified,
contentDisabled: Color = IntUiDarkTheme.colors.grey(7),
contentDisabled: Color = IntUiDarkTheme.colors.gray(7),
contentSelected: Color = content,
): CheckboxColors = CheckboxColors(content, contentDisabled, contentSelected)

Expand Down
Loading

0 comments on commit 3f24aca

Please sign in to comment.