diff --git a/core/src/main/kotlin/org/jetbrains/jewel/styling/CheckboxStyling.kt b/core/src/main/kotlin/org/jetbrains/jewel/styling/CheckboxStyling.kt index 744d82c9b7..6323b23638 100644 --- a/core/src/main/kotlin/org/jetbrains/jewel/styling/CheckboxStyling.kt +++ b/core/src/main/kotlin/org/jetbrains/jewel/styling/CheckboxStyling.kt @@ -11,36 +11,27 @@ import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.DpOffset import androidx.compose.ui.unit.DpSize import org.jetbrains.jewel.CheckboxState +import org.jetbrains.jewel.GenerateDataFunctions import org.jetbrains.jewel.painter.PainterProvider @Immutable -interface CheckboxStyle { +@GenerateDataFunctions +class CheckboxStyle( + val colors: CheckboxColors, + val metrics: CheckboxMetrics, + val icons: CheckboxIcons, +) { - val colors: CheckboxColors - val metrics: CheckboxMetrics - val icons: CheckboxIcons + companion object } -// TODO these should be used to tint the SVGs @Immutable -interface CheckboxColors { - - val checkboxBackground: Color - val checkboxBackgroundDisabled: Color - val checkboxBackgroundSelected: Color - - @Composable - fun backgroundFor(state: CheckboxState) = rememberUpdatedState( - when { - !state.isEnabled -> checkboxBackgroundDisabled - state.toggleableState == ToggleableState.On -> checkboxBackgroundSelected - else -> checkboxBackground - }, - ) - - val content: Color - val contentDisabled: Color - val contentSelected: Color +@GenerateDataFunctions +class CheckboxColors( + val content: Color, + val contentDisabled: Color, + val contentSelected: Color, +) { @Composable fun contentFor(state: CheckboxState) = rememberUpdatedState( @@ -50,22 +41,28 @@ interface CheckboxColors { else -> content }, ) + + companion object } @Immutable -interface CheckboxMetrics { +@GenerateDataFunctions +class CheckboxMetrics( + val checkboxSize: DpSize, + val checkboxCornerSize: CornerSize, + val outlineSize: DpSize, + val outlineOffset: DpOffset, + val iconContentGap: Dp, +) { - val checkboxSize: DpSize - val checkboxCornerSize: CornerSize - val outlineSize: DpSize - val outlineOffset: DpOffset - val iconContentGap: Dp + companion object } @Immutable -interface CheckboxIcons { +@GenerateDataFunctions +class CheckboxIcons(val checkbox: PainterProvider) { - val checkbox: PainterProvider + companion object } val LocalCheckboxStyle = 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 d4ca912c5d..6071a92206 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,10 +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.IntUiCheckboxColors -import org.jetbrains.jewel.intui.standalone.styling.IntUiCheckboxIcons -import org.jetbrains.jewel.intui.standalone.styling.IntUiCheckboxMetrics -import org.jetbrains.jewel.intui.standalone.styling.IntUiCheckboxStyle import org.jetbrains.jewel.intui.standalone.styling.IntUiChipColors import org.jetbrains.jewel.intui.standalone.styling.IntUiChipMetrics import org.jetbrains.jewel.intui.standalone.styling.IntUiChipStyle @@ -90,6 +86,10 @@ import org.jetbrains.jewel.intui.standalone.styling.IntUiTooltipStyle import org.jetbrains.jewel.styling.ButtonColors import org.jetbrains.jewel.styling.ButtonMetrics import org.jetbrains.jewel.styling.ButtonStyle +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.InputFieldStyle import org.jetbrains.skiko.DependsOnJBR import javax.swing.UIManager @@ -253,28 +253,24 @@ private fun readOutlinedButtonStyle(): ButtonStyle { private val iconsBasePath get() = DirProvider().dir() -private fun readCheckboxStyle(): IntUiCheckboxStyle { - val background = retrieveColorOrUnspecified("CheckBox.background") +private fun readCheckboxStyle(): CheckboxStyle { val textColor = retrieveColorOrUnspecified("CheckBox.foreground") - val colors = IntUiCheckboxColors( - checkboxBackground = background, - checkboxBackgroundDisabled = background, - checkboxBackgroundSelected = background, + val colors = CheckboxColors( content = textColor, contentDisabled = retrieveColorOrUnspecified("CheckBox.disabledText"), contentSelected = textColor, ) - return IntUiCheckboxStyle( + return CheckboxStyle( colors = colors, - metrics = IntUiCheckboxMetrics( + metrics = CheckboxMetrics( checkboxSize = DarculaCheckBoxUI().defaultIcon.let { DpSize(it.iconWidth.dp, it.iconHeight.dp) }, checkboxCornerSize = CornerSize(3.dp), // See DarculaCheckBoxUI#drawCheckIcon outlineSize = DpSize(15.dp, 15.dp), // Extrapolated from SVG outlineOffset = DpOffset(2.5.dp, 1.5.dp), // Extrapolated from SVG iconContentGap = 5.dp, // See DarculaCheckBoxUI#textIconGap ), - icons = IntUiCheckboxIcons( + icons = CheckboxIcons( checkbox = bridgePainterProvider("${iconsBasePath}checkBox.svg"), ), ) 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 16287c0a52..78eb9d3588 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 @@ -20,7 +20,7 @@ import org.jetbrains.jewel.intui.core.theme.IntUiDarkTheme 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.IntUiCheckboxStyle +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 @@ -93,7 +93,7 @@ object IntUiTheme : BaseIntUiTheme { @Composable fun darkComponentStyling( defaultButtonStyle: ButtonStyle = ButtonStyle.Default.dark(), outlinedButtonStyle: ButtonStyle = ButtonStyle.Outlined.dark(), - checkboxStyle: CheckboxStyle = IntUiCheckboxStyle.dark(), + checkboxStyle: CheckboxStyle = CheckboxStyle.Defaults.dark(), chipStyle: ChipStyle = IntUiChipStyle.dark(), dividerStyle: DividerStyle = IntUiDividerStyle.dark(), dropdownStyle: DropdownStyle = IntUiDropdownStyle.dark(), @@ -139,7 +139,7 @@ object IntUiTheme : BaseIntUiTheme { @Composable fun lightComponentStyling( defaultButtonStyle: ButtonStyle = ButtonStyle.Default.light(), outlinedButtonStyle: ButtonStyle = ButtonStyle.Outlined.light(), - checkboxStyle: CheckboxStyle = IntUiCheckboxStyle.light(), + checkboxStyle: CheckboxStyle = CheckboxStyle.Defaults.light(), chipStyle: ChipStyle = IntUiChipStyle.light(), dividerStyle: DividerStyle = IntUiDividerStyle.light(), dropdownStyle: DropdownStyle = IntUiDropdownStyle.light(), diff --git a/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiCheckboxStyling.kt b/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiCheckboxStyling.kt index 0685b19c6e..3f7d38b32f 100644 --- a/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiCheckboxStyling.kt +++ b/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiCheckboxStyling.kt @@ -2,13 +2,11 @@ package org.jetbrains.jewel.intui.standalone.styling import androidx.compose.foundation.shape.CornerSize import androidx.compose.runtime.Composable -import androidx.compose.runtime.Immutable import androidx.compose.ui.graphics.Color import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.DpOffset import androidx.compose.ui.unit.DpSize 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.intui.standalone.standalonePainterProvider @@ -18,108 +16,70 @@ import org.jetbrains.jewel.styling.CheckboxIcons import org.jetbrains.jewel.styling.CheckboxMetrics import org.jetbrains.jewel.styling.CheckboxStyle -@Immutable -@GenerateDataFunctions -class IntUiCheckboxStyle( - override val colors: IntUiCheckboxColors, - override val metrics: IntUiCheckboxMetrics, - override val icons: IntUiCheckboxIcons, -) : CheckboxStyle { +val CheckboxStyle.Companion.Defaults: IntUiCheckboxStyleFactory + get() = IntUiCheckboxStyleFactory - companion object { +object IntUiCheckboxStyleFactory { - @Composable fun light( - colors: IntUiCheckboxColors = IntUiCheckboxColors.light(), - metrics: IntUiCheckboxMetrics = IntUiCheckboxMetrics(), - icons: IntUiCheckboxIcons = IntUiCheckboxIcons.light(), - ) = IntUiCheckboxStyle(colors, metrics, icons) + @Composable + fun light( + colors: CheckboxColors = CheckboxColors.Defaults.light(), + metrics: CheckboxMetrics = CheckboxMetrics.defaults(), + icons: CheckboxIcons = CheckboxIcons.Defaults.light(), + ) = CheckboxStyle(colors, metrics, icons) - @Composable fun dark( - colors: IntUiCheckboxColors = IntUiCheckboxColors.dark(), - metrics: IntUiCheckboxMetrics = IntUiCheckboxMetrics(), - icons: IntUiCheckboxIcons = IntUiCheckboxIcons.dark(), - ) = IntUiCheckboxStyle(colors, metrics, icons) - } + @Composable + fun dark( + colors: CheckboxColors = CheckboxColors.Defaults.dark(), + metrics: CheckboxMetrics = CheckboxMetrics.defaults(), + icons: CheckboxIcons = CheckboxIcons.Defaults.dark(), + ) = CheckboxStyle(colors, metrics, icons) } -@Immutable -@GenerateDataFunctions -class IntUiCheckboxColors( - override val checkboxBackground: Color, - override val checkboxBackgroundDisabled: Color, - override val checkboxBackgroundSelected: Color, - override val content: Color, - override val contentDisabled: Color, - override val contentSelected: Color, -) : CheckboxColors { +val CheckboxColors.Companion.Defaults: IntUiCheckboxColorsFactory + get() = IntUiCheckboxColorsFactory - companion object { +object IntUiCheckboxColorsFactory { - @Composable fun light( - background: Color = IntUiLightTheme.colors.grey(14), - backgroundDisabled: Color = IntUiLightTheme.colors.grey(13), - backgroundSelected: Color = IntUiLightTheme.colors.blue(4), - content: Color = Color.Unspecified, - contentDisabled: Color = IntUiLightTheme.colors.grey(8), - contentSelected: Color = content, - ) = IntUiCheckboxColors( - background, - backgroundDisabled, - backgroundSelected, - content, - contentDisabled, - contentSelected, - ) + @Composable + fun light( + content: Color = Color.Unspecified, + contentDisabled: Color = IntUiLightTheme.colors.grey(8), + contentSelected: Color = content, + ) = CheckboxColors(content, contentDisabled, contentSelected) - @Composable fun dark( - background: Color = Color.Unspecified, - backgroundDisabled: Color = IntUiDarkTheme.colors.grey(3), - backgroundSelected: Color = IntUiDarkTheme.colors.blue(6), - content: Color = Color.Unspecified, - contentDisabled: Color = IntUiDarkTheme.colors.grey(7), - contentSelected: Color = content, - ) = IntUiCheckboxColors( - background, - backgroundDisabled, - backgroundSelected, - content, - contentDisabled, - contentSelected, - ) - } + @Composable + fun dark( + content: Color = Color.Unspecified, + contentDisabled: Color = IntUiDarkTheme.colors.grey(7), + contentSelected: Color = content, + ) = CheckboxColors(content, contentDisabled, contentSelected) } -@Immutable -@GenerateDataFunctions -class IntUiCheckboxMetrics( - override val checkboxSize: DpSize = DpSize(19.dp, 19.dp), - override val checkboxCornerSize: CornerSize = CornerSize(3.dp), - override val outlineSize: DpSize = DpSize(15.dp, 15.dp), - override val outlineOffset: DpOffset = DpOffset(2.5.dp, 1.5.dp), - override val iconContentGap: Dp = 5.dp, -) : CheckboxMetrics +fun CheckboxMetrics.Companion.defaults( + checkboxSize: DpSize = DpSize(19.dp, 19.dp), + checkboxCornerSize: CornerSize = CornerSize(3.dp), + outlineSize: DpSize = DpSize(15.dp, 15.dp), + outlineOffset: DpOffset = DpOffset(2.5.dp, 1.5.dp), + iconContentGap: Dp = 5.dp, +) = CheckboxMetrics(checkboxSize, checkboxCornerSize, outlineSize, outlineOffset, iconContentGap) -@Immutable -@GenerateDataFunctions -class IntUiCheckboxIcons( - override val checkbox: PainterProvider, -) : CheckboxIcons { +val CheckboxIcons.Companion.Defaults: IntUiCheckboxIconsFactory + get() = IntUiCheckboxIconsFactory - companion object { +object IntUiCheckboxIconsFactory { - @Composable - fun checkbox( - basePath: String = "com/intellij/ide/ui/laf/icons/intellij/checkBox.svg", - ): PainterProvider = standalonePainterProvider(basePath) + @Composable + fun light( + checkbox: PainterProvider = checkbox("com/intellij/ide/ui/laf/icons/intellij/checkBox.svg"), + ) = CheckboxIcons(checkbox) - @Composable - fun light( - checkbox: PainterProvider = checkbox("com/intellij/ide/ui/laf/icons/intellij/checkBox.svg"), - ) = IntUiCheckboxIcons(checkbox) + @Composable + fun dark( + checkbox: PainterProvider = checkbox("com/intellij/ide/ui/laf/icons/darcula/checkBox.svg"), + ) = CheckboxIcons(checkbox) - @Composable - fun dark( - checkbox: PainterProvider = checkbox("com/intellij/ide/ui/laf/icons/darcula/checkBox.svg"), - ) = IntUiCheckboxIcons(checkbox) - } + @Composable + private fun checkbox(basePath: String): PainterProvider = + standalonePainterProvider(basePath) }