Skip to content

Commit

Permalink
DividerStyle refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
rock3r committed Oct 20, 2023
1 parent 4c941ca commit 706e1bc
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 39 deletions.
19 changes: 13 additions & 6 deletions core/src/main/kotlin/org/jetbrains/jewel/styling/DividerStyling.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<DividerStyle> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 706e1bc

Please sign in to comment.