From 706e1bc8b095bc8d4db63d63c92b392ca03f27d3 Mon Sep 17 00:00:00 2001 From: Sebastiano Poggi Date: Fri, 20 Oct 2023 13:16:17 +0200 Subject: [PATCH] DividerStyle refactor --- .../jetbrains/jewel/styling/DividerStyling.kt | 19 +++++--- .../org/jetbrains/jewel/bridge/IntUiBridge.kt | 9 ++-- .../jewel/intui/standalone/IntUiTheme.kt | 5 +-- .../standalone/styling/IntUiDividerStyle.kt | 43 ++++++++----------- 4 files changed, 37 insertions(+), 39 deletions(-) diff --git a/core/src/main/kotlin/org/jetbrains/jewel/styling/DividerStyling.kt b/core/src/main/kotlin/org/jetbrains/jewel/styling/DividerStyling.kt index 67fcda051f..a56455f21c 100644 --- a/core/src/main/kotlin/org/jetbrains/jewel/styling/DividerStyling.kt +++ b/core/src/main/kotlin/org/jetbrains/jewel/styling/DividerStyling.kt @@ -4,19 +4,26 @@ import androidx.compose.runtime.Immutable import androidx.compose.runtime.staticCompositionLocalOf import androidx.compose.ui.graphics.Color import androidx.compose.ui.unit.Dp +import org.jetbrains.jewel.GenerateDataFunctions @Immutable -interface DividerStyle { +@GenerateDataFunctions +class DividerStyle( + val color: Color, + val metrics: DividerMetrics, +) { - val color: Color - val metrics: DividerMetrics + companion object } @Immutable -interface DividerMetrics { +@GenerateDataFunctions +class DividerMetrics( + val thickness: Dp, + val startIndent: Dp, +) { - val thickness: Dp - val startIndent: Dp + companion object } val LocalDividerStyle = 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 5509f4c16a..2cb39de104 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,8 +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.IntUiDividerMetrics -import org.jetbrains.jewel.intui.standalone.styling.IntUiDividerStyle import org.jetbrains.jewel.intui.standalone.styling.IntUiDropdownColors import org.jetbrains.jewel.intui.standalone.styling.IntUiDropdownIcons import org.jetbrains.jewel.intui.standalone.styling.IntUiDropdownMetrics @@ -79,6 +77,7 @@ import org.jetbrains.jewel.intui.standalone.styling.IntUiTextFieldStyle import org.jetbrains.jewel.intui.standalone.styling.IntUiTooltipColors import org.jetbrains.jewel.intui.standalone.styling.IntUiTooltipMetrics import org.jetbrains.jewel.intui.standalone.styling.IntUiTooltipStyle +import org.jetbrains.jewel.intui.standalone.styling.defaults import org.jetbrains.jewel.styling.ButtonColors import org.jetbrains.jewel.styling.ButtonMetrics import org.jetbrains.jewel.styling.ButtonStyle @@ -90,6 +89,8 @@ import org.jetbrains.jewel.styling.ChipColors import org.jetbrains.jewel.styling.ChipMetrics import org.jetbrains.jewel.styling.ChipStyle import org.jetbrains.jewel.styling.CircularProgressStyle +import org.jetbrains.jewel.styling.DividerMetrics +import org.jetbrains.jewel.styling.DividerStyle import org.jetbrains.jewel.styling.InputFieldStyle import org.jetbrains.skiko.DependsOnJBR import javax.swing.UIManager @@ -335,9 +336,9 @@ private fun readChipStyle(): ChipStyle { } private fun readDividerStyle() = - IntUiDividerStyle( + DividerStyle( color = retrieveColorOrUnspecified("Borders.color"), - metrics = IntUiDividerMetrics(), + metrics = DividerMetrics.defaults(), ) private fun readDropdownStyle( 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 c3bbbe7978..8601d3006a 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.IntUiDividerStyle import org.jetbrains.jewel.intui.standalone.styling.IntUiDropdownStyle import org.jetbrains.jewel.intui.standalone.styling.IntUiGroupHeaderStyle import org.jetbrains.jewel.intui.standalone.styling.IntUiHorizontalProgressBarStyle @@ -93,7 +92,7 @@ object IntUiTheme : BaseIntUiTheme { outlinedButtonStyle: ButtonStyle = ButtonStyle.Outlined.dark(), checkboxStyle: CheckboxStyle = CheckboxStyle.Defaults.dark(), chipStyle: ChipStyle = ChipStyle.Defaults.dark(), - dividerStyle: DividerStyle = IntUiDividerStyle.dark(), + dividerStyle: DividerStyle = DividerStyle.Defaults.dark(), dropdownStyle: DropdownStyle = IntUiDropdownStyle.dark(), groupHeaderStyle: GroupHeaderStyle = IntUiGroupHeaderStyle.dark(), labelledTextFieldStyle: LabelledTextFieldStyle = IntUiLabelledTextFieldStyle.dark(), @@ -139,7 +138,7 @@ object IntUiTheme : BaseIntUiTheme { outlinedButtonStyle: ButtonStyle = ButtonStyle.Outlined.light(), checkboxStyle: CheckboxStyle = CheckboxStyle.Defaults.light(), chipStyle: ChipStyle = ChipStyle.Defaults.light(), - dividerStyle: DividerStyle = IntUiDividerStyle.light(), + dividerStyle: DividerStyle = DividerStyle.Defaults.light(), dropdownStyle: DropdownStyle = IntUiDropdownStyle.light(), groupHeaderStyle: GroupHeaderStyle = IntUiGroupHeaderStyle.light(), labelledTextFieldStyle: LabelledTextFieldStyle = IntUiLabelledTextFieldStyle.light(), diff --git a/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiDividerStyle.kt b/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiDividerStyle.kt index 0b7441f62c..f340182014 100644 --- a/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiDividerStyle.kt +++ b/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiDividerStyle.kt @@ -1,42 +1,33 @@ package org.jetbrains.jewel.intui.standalone.styling 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.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.DividerMetrics import org.jetbrains.jewel.styling.DividerStyle -@Immutable -@GenerateDataFunctions -class IntUiDividerStyle( - override val color: Color, - override val metrics: DividerMetrics, -) : DividerStyle { +val DividerStyle.Companion.Defaults: IntUiDividerStyleFactory + get() = IntUiDividerStyleFactory - companion object { +object IntUiDividerStyleFactory { - @Composable - fun light( - color: Color = IntUiLightTheme.colors.grey(12), - metrics: IntUiDividerMetrics = IntUiDividerMetrics(), - ) = IntUiDividerStyle(color, metrics) + @Composable + fun light( + color: Color = IntUiLightTheme.colors.grey(12), + metrics: DividerMetrics = DividerMetrics.defaults(), + ) = DividerStyle(color, metrics) - @Composable - fun dark( - color: Color = IntUiDarkTheme.colors.grey(1), - metrics: IntUiDividerMetrics = IntUiDividerMetrics(), - ) = IntUiDividerStyle(color, metrics) - } + @Composable + fun dark( + color: Color = IntUiDarkTheme.colors.grey(1), + metrics: DividerMetrics = DividerMetrics.defaults(), + ) = DividerStyle(color, metrics) } -@Immutable -@GenerateDataFunctions -class IntUiDividerMetrics( - override val thickness: Dp = 1.dp, - override val startIndent: Dp = 0.dp, -) : DividerMetrics +fun DividerMetrics.Companion.defaults( + thickness: Dp = 1.dp, + startIndent: Dp = 0.dp, +) = DividerMetrics(thickness, startIndent)