diff --git a/core/src/main/kotlin/org/jetbrains/jewel/Chip.kt b/core/src/main/kotlin/org/jetbrains/jewel/Chip.kt index 6ebc64ba45..82871deef4 100644 --- a/core/src/main/kotlin/org/jetbrains/jewel/Chip.kt +++ b/core/src/main/kotlin/org/jetbrains/jewel/Chip.kt @@ -148,10 +148,16 @@ private fun ChipImpl( val colors = style.colors val borderColor by colors.borderFor(chipState) + val borderWidth = if (chipState.isSelected) { + style.metrics.borderWidthSelected + } else { + style.metrics.borderWidth + } + Row( modifier = modifier .background(colors.backgroundFor(chipState).value, shape) - .border(Stroke.Alignment.Center, style.metrics.borderWidth, borderColor, shape) + .border(Stroke.Alignment.Center, borderWidth, borderColor, shape) .focusOutline(chipState, shape) .padding(style.metrics.padding), verticalAlignment = Alignment.CenterVertically, diff --git a/core/src/main/kotlin/org/jetbrains/jewel/styling/ChipStyling.kt b/core/src/main/kotlin/org/jetbrains/jewel/styling/ChipStyling.kt index 7297998e26..5706cf8f1e 100644 --- a/core/src/main/kotlin/org/jetbrains/jewel/styling/ChipStyling.kt +++ b/core/src/main/kotlin/org/jetbrains/jewel/styling/ChipStyling.kt @@ -11,28 +11,53 @@ import androidx.compose.ui.graphics.Brush import androidx.compose.ui.graphics.Color import androidx.compose.ui.unit.Dp import org.jetbrains.jewel.ChipState +import org.jetbrains.jewel.GenerateDataFunctions import org.jetbrains.jewel.IntelliJTheme @Stable -interface ChipStyle { +@GenerateDataFunctions +class ChipStyle( + val colors: ChipColors, + val metrics: ChipMetrics, +) { - val colors: ChipColors - val metrics: ChipMetrics + companion object } @Immutable -interface ChipColors { - - val background: Brush - val backgroundDisabled: Brush - val backgroundFocused: Brush - val backgroundPressed: Brush - val backgroundHovered: Brush - val backgroundSelected: Brush - val backgroundSelectedDisabled: Brush - val backgroundSelectedPressed: Brush - val backgroundSelectedFocused: Brush - val backgroundSelectedHovered: Brush +@GenerateDataFunctions +class ChipColors( + val background: Brush, + val backgroundDisabled: Brush, + val backgroundFocused: Brush, + val backgroundPressed: Brush, + val backgroundHovered: Brush, + val backgroundSelected: Brush, + val backgroundSelectedDisabled: Brush, + val backgroundSelectedPressed: Brush, + val backgroundSelectedFocused: Brush, + val backgroundSelectedHovered: Brush, + val content: Color, + val contentDisabled: Color, + val contentFocused: Color, + val contentPressed: Color, + val contentHovered: Color, + val contentSelected: Color, + val contentSelectedDisabled: Color, + val contentSelectedPressed: Color, + val contentSelectedFocused: Color, + val contentSelectedHovered: Color, + val border: Color, + val borderDisabled: Color, + val borderFocused: Color, + val borderPressed: Color, + val borderHovered: Color, + val borderSelected: Color, + val borderSelectedDisabled: Color, + val borderSelectedPressed: Color, + val borderSelectedFocused: Color, + val borderSelectedHovered: Color, +) { @Composable fun backgroundFor(state: ChipState) = rememberUpdatedState( @@ -55,17 +80,6 @@ interface ChipColors { }, ) - val content: Color - val contentDisabled: Color - val contentFocused: Color - val contentPressed: Color - val contentHovered: Color - val contentSelected: Color - val contentSelectedDisabled: Color - val contentSelectedPressed: Color - val contentSelectedFocused: Color - val contentSelectedHovered: Color - @Composable fun contentFor(state: ChipState) = rememberUpdatedState( if (state.isSelected) { @@ -87,17 +101,6 @@ interface ChipColors { }, ) - val border: Color - val borderDisabled: Color - val borderFocused: Color - val borderPressed: Color - val borderHovered: Color - val borderSelected: Color - val borderSelectedDisabled: Color - val borderSelectedPressed: Color - val borderSelectedFocused: Color - val borderSelectedHovered: Color - @Composable fun borderFor(state: ChipState) = rememberUpdatedState( if (state.isSelected) { @@ -118,15 +121,20 @@ interface ChipColors { } }, ) + + companion object } @Stable -interface ChipMetrics { +@GenerateDataFunctions +class ChipMetrics( + val cornerSize: CornerSize, + val padding: PaddingValues, + val borderWidth: Dp, + val borderWidthSelected: Dp, +) { - val cornerSize: CornerSize - val padding: PaddingValues - val borderWidth: Dp - val borderWidthSelected: Dp + companion object } val LocalChipStyle = staticCompositionLocalOf { 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 6071a92206..2af5f4fd8a 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 @@ -23,9 +23,6 @@ import com.intellij.util.ui.NamedColorUtil import com.intellij.util.ui.StatusText import org.jetbrains.jewel.IntelliJComponentStyling import org.jetbrains.jewel.intui.core.IntUiThemeDefinition -import org.jetbrains.jewel.intui.standalone.styling.IntUiChipColors -import org.jetbrains.jewel.intui.standalone.styling.IntUiChipMetrics -import org.jetbrains.jewel.intui.standalone.styling.IntUiChipStyle import org.jetbrains.jewel.intui.standalone.styling.IntUiCircularProgressStyle import org.jetbrains.jewel.intui.standalone.styling.IntUiDividerMetrics import org.jetbrains.jewel.intui.standalone.styling.IntUiDividerStyle @@ -90,6 +87,9 @@ import org.jetbrains.jewel.styling.CheckboxColors import org.jetbrains.jewel.styling.CheckboxIcons import org.jetbrains.jewel.styling.CheckboxMetrics import org.jetbrains.jewel.styling.CheckboxStyle +import org.jetbrains.jewel.styling.ChipColors +import org.jetbrains.jewel.styling.ChipMetrics +import org.jetbrains.jewel.styling.ChipStyle import org.jetbrains.jewel.styling.InputFieldStyle import org.jetbrains.skiko.DependsOnJBR import javax.swing.UIManager @@ -282,7 +282,7 @@ private fun readCheckboxStyle(): CheckboxStyle { // 1. There is no real disabled state, we're making it sort of up // 2. Chips can be used as buttons (see run configs) or as radio buttons (see MeetNewUi) // 3. We also have a toggleable version because why not -private fun readChipStyle(): IntUiChipStyle { +private fun readChipStyle(): ChipStyle { val normalBackground = retrieveColorsOrUnspecified("Button.startBackground", "Button.endBackground") .createVerticalBrush() @@ -291,7 +291,7 @@ private fun readChipStyle(): IntUiChipStyle { val disabledBorder = retrieveColorOrUnspecified("Button.disabledBorderColor") val selectedBorder = retrieveColorOrUnspecified("Component.focusColor") - val colors = IntUiChipColors( + val colors = ChipColors( background = normalBackground, backgroundDisabled = normalBackground, backgroundFocused = normalBackground, @@ -323,9 +323,9 @@ private fun readChipStyle(): IntUiChipStyle { borderSelectedFocused = selectedBorder, borderSelectedHovered = selectedBorder, ) - return IntUiChipStyle( + return ChipStyle( colors = colors, - metrics = IntUiChipMetrics( + metrics = ChipMetrics( cornerSize = CornerSize(6.dp), padding = PaddingValues(horizontal = 12.dp, vertical = 8.dp), borderWidth = 1.dp, diff --git a/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/IntUiTheme.kt b/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/IntUiTheme.kt index 78eb9d3588..5dc6483373 100644 --- a/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/IntUiTheme.kt +++ b/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/IntUiTheme.kt @@ -21,7 +21,6 @@ import org.jetbrains.jewel.intui.core.theme.IntUiLightTheme import org.jetbrains.jewel.intui.standalone.IntUiTheme.defaultComponentStyling import org.jetbrains.jewel.intui.standalone.styling.Default import org.jetbrains.jewel.intui.standalone.styling.Defaults -import org.jetbrains.jewel.intui.standalone.styling.IntUiChipStyle import org.jetbrains.jewel.intui.standalone.styling.IntUiCircularProgressStyle import org.jetbrains.jewel.intui.standalone.styling.IntUiDividerStyle import org.jetbrains.jewel.intui.standalone.styling.IntUiDropdownStyle @@ -94,7 +93,7 @@ object IntUiTheme : BaseIntUiTheme { defaultButtonStyle: ButtonStyle = ButtonStyle.Default.dark(), outlinedButtonStyle: ButtonStyle = ButtonStyle.Outlined.dark(), checkboxStyle: CheckboxStyle = CheckboxStyle.Defaults.dark(), - chipStyle: ChipStyle = IntUiChipStyle.dark(), + chipStyle: ChipStyle = ChipStyle.Defaults.dark(), dividerStyle: DividerStyle = IntUiDividerStyle.dark(), dropdownStyle: DropdownStyle = IntUiDropdownStyle.dark(), groupHeaderStyle: GroupHeaderStyle = IntUiGroupHeaderStyle.dark(), @@ -140,7 +139,7 @@ object IntUiTheme : BaseIntUiTheme { defaultButtonStyle: ButtonStyle = ButtonStyle.Default.light(), outlinedButtonStyle: ButtonStyle = ButtonStyle.Outlined.light(), checkboxStyle: CheckboxStyle = CheckboxStyle.Defaults.light(), - chipStyle: ChipStyle = IntUiChipStyle.light(), + chipStyle: ChipStyle = ChipStyle.Defaults.light(), dividerStyle: DividerStyle = IntUiDividerStyle.light(), dropdownStyle: DropdownStyle = IntUiDropdownStyle.light(), groupHeaderStyle: GroupHeaderStyle = IntUiGroupHeaderStyle.light(), diff --git a/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiChipStyling.kt b/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiChipStyling.kt index 32d79f38bb..76bf296489 100644 --- a/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiChipStyling.kt +++ b/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiChipStyling.kt @@ -3,217 +3,174 @@ package org.jetbrains.jewel.intui.standalone.styling import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.shape.CornerSize import androidx.compose.runtime.Composable -import androidx.compose.runtime.Immutable -import androidx.compose.runtime.Stable import androidx.compose.ui.graphics.Brush import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.SolidColor import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp -import org.jetbrains.jewel.GenerateDataFunctions import org.jetbrains.jewel.intui.core.theme.IntUiDarkTheme import org.jetbrains.jewel.intui.core.theme.IntUiLightTheme import org.jetbrains.jewel.styling.ChipColors import org.jetbrains.jewel.styling.ChipMetrics import org.jetbrains.jewel.styling.ChipStyle -@Stable -@GenerateDataFunctions -class IntUiChipStyle( - override val colors: IntUiChipColors, - override val metrics: IntUiChipMetrics, -) : ChipStyle { +val ChipStyle.Companion.Defaults: IntUiChipStyleFactory + get() = IntUiChipStyleFactory - companion object { +object IntUiChipStyleFactory { - @Composable - fun light( - colors: IntUiChipColors = IntUiChipColors.light(), - metrics: IntUiChipMetrics = IntUiChipMetrics(), - ) = IntUiChipStyle(colors, metrics) + @Composable + fun light( + colors: ChipColors = ChipColors.Defaults.light(), + metrics: ChipMetrics = ChipMetrics.defaults(), + ) = ChipStyle(colors, metrics) - @Composable - fun dark( - colors: IntUiChipColors = IntUiChipColors.dark(), - metrics: IntUiChipMetrics = IntUiChipMetrics(), - ) = IntUiChipStyle(colors, metrics) - } + @Composable + fun dark( + colors: ChipColors = ChipColors.Defaults.dark(), + metrics: ChipMetrics = ChipMetrics.defaults(), + ) = ChipStyle(colors, metrics) } -@Immutable -@GenerateDataFunctions -class IntUiChipColors( - override val background: Brush, - override val backgroundDisabled: Brush, - override val backgroundFocused: Brush, - override val backgroundPressed: Brush, - override val backgroundHovered: Brush, - override val backgroundSelected: Brush, - override val backgroundSelectedDisabled: Brush, - override val backgroundSelectedPressed: Brush, - override val backgroundSelectedFocused: Brush, - override val backgroundSelectedHovered: Brush, - override val content: Color, - override val contentDisabled: Color, - override val contentFocused: Color, - override val contentPressed: Color, - override val contentHovered: Color, - override val contentSelected: Color, - override val contentSelectedDisabled: Color, - override val contentSelectedPressed: Color, - override val contentSelectedFocused: Color, - override val contentSelectedHovered: Color, - override val border: Color, - override val borderDisabled: Color, - override val borderFocused: Color, - override val borderPressed: Color, - override val borderHovered: Color, - override val borderSelected: Color, - override val borderSelectedDisabled: Color, - override val borderSelectedPressed: Color, - override val borderSelectedFocused: Color, - override val borderSelectedHovered: Color, -) : ChipColors { +val ChipColors.Companion.Defaults: IntUiChipColorsFactory + get() = IntUiChipColorsFactory - companion object { +object IntUiChipColorsFactory { - @Composable - fun light( - background: Brush = SolidColor(IntUiLightTheme.colors.grey(14)), - backgroundDisabled: Brush = SolidColor(IntUiLightTheme.colors.grey(12)), - backgroundFocused: Brush = background, - backgroundPressed: Brush = SolidColor(IntUiLightTheme.colors.grey(13)), - backgroundHovered: Brush = background, - backgroundSelected: Brush = background, - backgroundSelectedDisabled: Brush = backgroundDisabled, - backgroundSelectedFocused: Brush = background, - backgroundSelectedPressed: Brush = background, - backgroundSelectedHovered: Brush = background, - content: Color = IntUiLightTheme.colors.grey(1), - contentDisabled: Color = IntUiLightTheme.colors.grey(8), - contentFocused: Color = content, - contentPressed: Color = content, - contentHovered: Color = content, - contentSelected: Color = content, - contentSelectedDisabled: Color = contentDisabled, - contentSelectedFocused: Color = content, - contentSelectedPressed: Color = content, - contentSelectedHovered: Color = content, - border: Color = IntUiLightTheme.colors.grey(9), - borderDisabled: Color = IntUiLightTheme.colors.grey(6), - borderFocused: Color = IntUiLightTheme.colors.blue(4), - borderPressed: Color = IntUiLightTheme.colors.grey(7), - borderHovered: Color = IntUiLightTheme.colors.grey(8), - borderSelected: Color = IntUiLightTheme.colors.blue(4), - borderSelectedDisabled: Color = borderSelected, - borderSelectedFocused: Color = borderSelected, - borderSelectedPressed: Color = borderSelected, - borderSelectedHovered: Color = borderSelected, - ) = IntUiChipColors( - background, - backgroundDisabled, - backgroundFocused, - backgroundPressed, - backgroundHovered, - backgroundSelected, - backgroundSelectedDisabled, - backgroundSelectedPressed, - backgroundSelectedFocused, - backgroundSelectedHovered, - content, - contentDisabled, - contentFocused, - contentPressed, - contentHovered, - contentSelected, - contentSelectedDisabled, - contentSelectedPressed, - contentSelectedFocused, - contentSelectedHovered, - border, - borderDisabled, - borderFocused, - borderPressed, - borderHovered, - borderSelected, - borderSelectedDisabled, - borderSelectedPressed, - borderSelectedFocused, - borderSelectedHovered, - ) + @Composable + fun light( + background: Brush = SolidColor(IntUiLightTheme.colors.grey(14)), + backgroundDisabled: Brush = SolidColor(IntUiLightTheme.colors.grey(12)), + backgroundFocused: Brush = background, + backgroundPressed: Brush = SolidColor(IntUiLightTheme.colors.grey(13)), + backgroundHovered: Brush = background, + backgroundSelected: Brush = background, + backgroundSelectedDisabled: Brush = backgroundDisabled, + backgroundSelectedFocused: Brush = background, + backgroundSelectedPressed: Brush = background, + backgroundSelectedHovered: Brush = background, + content: Color = IntUiLightTheme.colors.grey(1), + contentDisabled: Color = IntUiLightTheme.colors.grey(8), + contentFocused: Color = content, + contentPressed: Color = content, + contentHovered: Color = content, + contentSelected: Color = content, + contentSelectedDisabled: Color = contentDisabled, + contentSelectedFocused: Color = content, + contentSelectedPressed: Color = content, + contentSelectedHovered: Color = content, + border: Color = IntUiLightTheme.colors.grey(9), + borderDisabled: Color = IntUiLightTheme.colors.grey(6), + borderFocused: Color = IntUiLightTheme.colors.blue(4), + borderPressed: Color = IntUiLightTheme.colors.grey(7), + borderHovered: Color = IntUiLightTheme.colors.grey(8), + borderSelected: Color = IntUiLightTheme.colors.blue(4), + borderSelectedDisabled: Color = borderSelected, + borderSelectedFocused: Color = borderSelected, + borderSelectedPressed: Color = borderSelected, + borderSelectedHovered: Color = borderSelected, + ) = ChipColors( + background, + backgroundDisabled, + backgroundFocused, + backgroundPressed, + backgroundHovered, + backgroundSelected, + backgroundSelectedDisabled, + backgroundSelectedPressed, + backgroundSelectedFocused, + backgroundSelectedHovered, + content, + contentDisabled, + contentFocused, + contentPressed, + contentHovered, + contentSelected, + contentSelectedDisabled, + contentSelectedPressed, + contentSelectedFocused, + contentSelectedHovered, + border, + borderDisabled, + borderFocused, + borderPressed, + borderHovered, + borderSelected, + borderSelectedDisabled, + borderSelectedPressed, + borderSelectedFocused, + borderSelectedHovered, + ) - @Composable - fun dark( - background: Brush = SolidColor(IntUiDarkTheme.colors.grey(2)), - backgroundDisabled: Brush = SolidColor(IntUiDarkTheme.colors.grey(5)), - backgroundFocused: Brush = background, - backgroundPressed: Brush = background, - backgroundHovered: Brush = background, - backgroundSelected: Brush = background, - backgroundSelectedDisabled: Brush = backgroundDisabled, - backgroundSelectedFocused: Brush = background, - backgroundSelectedPressed: Brush = background, - backgroundSelectedHovered: Brush = background, - content: Color = IntUiDarkTheme.colors.grey(12), - contentDisabled: Color = IntUiDarkTheme.colors.grey(8), - contentFocused: Color = content, - contentPressed: Color = content, - contentHovered: Color = content, - contentSelected: Color = content, - contentSelectedDisabled: Color = contentDisabled, - contentSelectedFocused: Color = content, - contentSelectedPressed: Color = content, - contentSelectedHovered: Color = content, - border: Color = IntUiDarkTheme.colors.grey(5), - borderDisabled: Color = IntUiDarkTheme.colors.grey(6), - borderFocused: Color = IntUiDarkTheme.colors.blue(6), - borderPressed: Color = IntUiDarkTheme.colors.grey(7), - borderHovered: Color = borderPressed, - borderSelected: Color = IntUiDarkTheme.colors.blue(6), - borderSelectedDisabled: Color = borderSelected, - borderSelectedFocused: Color = borderSelected, - borderSelectedPressed: Color = borderSelected, - borderSelectedHovered: Color = borderSelected, - ) = IntUiChipColors( - background, - backgroundDisabled, - backgroundFocused, - backgroundPressed, - backgroundHovered, - backgroundSelected, - backgroundSelectedDisabled, - backgroundSelectedPressed, - backgroundSelectedFocused, - backgroundSelectedHovered, - content, - contentDisabled, - contentFocused, - contentPressed, - contentHovered, - contentSelected, - contentSelectedDisabled, - contentSelectedPressed, - contentSelectedFocused, - contentSelectedHovered, - border, - borderDisabled, - borderFocused, - borderPressed, - borderHovered, - borderSelected, - borderSelectedDisabled, - borderSelectedPressed, - borderSelectedFocused, - borderSelectedHovered, - ) - } + @Composable + fun dark( + background: Brush = SolidColor(IntUiDarkTheme.colors.grey(2)), + backgroundDisabled: Brush = SolidColor(IntUiDarkTheme.colors.grey(5)), + backgroundFocused: Brush = background, + backgroundPressed: Brush = background, + backgroundHovered: Brush = background, + backgroundSelected: Brush = background, + backgroundSelectedDisabled: Brush = backgroundDisabled, + backgroundSelectedFocused: Brush = background, + backgroundSelectedPressed: Brush = background, + backgroundSelectedHovered: Brush = background, + content: Color = IntUiDarkTheme.colors.grey(12), + contentDisabled: Color = IntUiDarkTheme.colors.grey(8), + contentFocused: Color = content, + contentPressed: Color = content, + contentHovered: Color = content, + contentSelected: Color = content, + contentSelectedDisabled: Color = contentDisabled, + contentSelectedFocused: Color = content, + contentSelectedPressed: Color = content, + contentSelectedHovered: Color = content, + border: Color = IntUiDarkTheme.colors.grey(5), + borderDisabled: Color = IntUiDarkTheme.colors.grey(6), + borderFocused: Color = IntUiDarkTheme.colors.blue(6), + borderPressed: Color = IntUiDarkTheme.colors.grey(7), + borderHovered: Color = borderPressed, + borderSelected: Color = IntUiDarkTheme.colors.blue(6), + borderSelectedDisabled: Color = borderSelected, + borderSelectedFocused: Color = borderSelected, + borderSelectedPressed: Color = borderSelected, + borderSelectedHovered: Color = borderSelected, + ) = ChipColors( + background, + backgroundDisabled, + backgroundFocused, + backgroundPressed, + backgroundHovered, + backgroundSelected, + backgroundSelectedDisabled, + backgroundSelectedPressed, + backgroundSelectedFocused, + backgroundSelectedHovered, + content, + contentDisabled, + contentFocused, + contentPressed, + contentHovered, + contentSelected, + contentSelectedDisabled, + contentSelectedPressed, + contentSelectedFocused, + contentSelectedHovered, + border, + borderDisabled, + borderFocused, + borderPressed, + borderHovered, + borderSelected, + borderSelectedDisabled, + borderSelectedPressed, + borderSelectedFocused, + borderSelectedHovered, + ) } -@Stable -@GenerateDataFunctions -class IntUiChipMetrics( - override val cornerSize: CornerSize = CornerSize(100), - override val padding: PaddingValues = PaddingValues(horizontal = 12.dp, vertical = 8.dp), - override val borderWidth: Dp = 1.dp, - override val borderWidthSelected: Dp = 2.dp, -) : ChipMetrics +fun ChipMetrics.Companion.defaults( + cornerSize: CornerSize = CornerSize(100), + padding: PaddingValues = PaddingValues(horizontal = 12.dp, vertical = 8.dp), + borderWidth: Dp = 1.dp, + borderWidthSelected: Dp = 2.dp, +) = ChipMetrics(cornerSize, padding, borderWidth, borderWidthSelected)