diff --git a/core/src/main/kotlin/org/jetbrains/jewel/styling/ScrollbarStyling.kt b/core/src/main/kotlin/org/jetbrains/jewel/styling/ScrollbarStyling.kt index 7911e6a6e..a8d9a9b93 100644 --- a/core/src/main/kotlin/org/jetbrains/jewel/styling/ScrollbarStyling.kt +++ b/core/src/main/kotlin/org/jetbrains/jewel/styling/ScrollbarStyling.kt @@ -7,30 +7,40 @@ import androidx.compose.runtime.Stable import androidx.compose.runtime.staticCompositionLocalOf import androidx.compose.ui.graphics.Color import androidx.compose.ui.unit.Dp +import org.jetbrains.jewel.GenerateDataFunctions import kotlin.time.Duration @Stable -interface ScrollbarStyle { - - val colors: ScrollbarColors - val metrics: ScrollbarMetrics - val hoverDuration: Duration +@GenerateDataFunctions +class ScrollbarStyle( + val colors: ScrollbarColors, + val metrics: ScrollbarMetrics, + val hoverDuration: Duration, +) { + + companion object } @Immutable -interface ScrollbarColors { +@GenerateDataFunctions +class ScrollbarColors( + val thumbBackground: Color, + val thumbBackgroundHovered: Color, +) { - val thumbBackground: Color - val thumbBackgroundHovered: Color + companion object } @Stable -interface ScrollbarMetrics { - - val thumbCornerSize: CornerSize - val thumbThickness: Dp - val minThumbLength: Dp - val trackPadding: PaddingValues +@GenerateDataFunctions +class ScrollbarMetrics( + val thumbCornerSize: CornerSize, + val thumbThickness: Dp, + val minThumbLength: Dp, + val trackPadding: PaddingValues, +) { + + companion object } val LocalScrollbarStyle = 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 b206228bf..54031e531 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 @@ -27,9 +27,6 @@ import org.jetbrains.jewel.intui.standalone.styling.IntUiLabelledTextFieldColors import org.jetbrains.jewel.intui.standalone.styling.IntUiLabelledTextFieldMetrics import org.jetbrains.jewel.intui.standalone.styling.IntUiLabelledTextFieldStyle import org.jetbrains.jewel.intui.standalone.styling.IntUiLabelledTextFieldTextStyles -import org.jetbrains.jewel.intui.standalone.styling.IntUiScrollbarColors -import org.jetbrains.jewel.intui.standalone.styling.IntUiScrollbarMetrics -import org.jetbrains.jewel.intui.standalone.styling.IntUiScrollbarStyle import org.jetbrains.jewel.intui.standalone.styling.IntUiTabColors import org.jetbrains.jewel.intui.standalone.styling.IntUiTabContentAlpha import org.jetbrains.jewel.intui.standalone.styling.IntUiTabIcons @@ -91,6 +88,9 @@ import org.jetbrains.jewel.styling.RadioButtonColors import org.jetbrains.jewel.styling.RadioButtonIcons import org.jetbrains.jewel.styling.RadioButtonMetrics import org.jetbrains.jewel.styling.RadioButtonStyle +import org.jetbrains.jewel.styling.ScrollbarColors +import org.jetbrains.jewel.styling.ScrollbarMetrics +import org.jetbrains.jewel.styling.ScrollbarStyle import org.jetbrains.jewel.styling.SubmenuMetrics import org.jetbrains.skiko.DependsOnJBR import javax.swing.UIManager @@ -101,6 +101,9 @@ private val logger = Logger.getInstance("JewelIntUiBridge") internal val uiDefaults get() = UIManager.getDefaults() +private val iconsBasePath + get() = DirProvider().dir() + @OptIn(DependsOnJBR::class) internal suspend fun createBridgeIntUiDefinition(): IntUiThemeDefinition { val textStyle = retrieveTextStyle("Label.font", "Label.foreground") @@ -252,9 +255,6 @@ private fun readOutlinedButtonStyle(): ButtonStyle { ) } -private val iconsBasePath - get() = DirProvider().dir() - private fun readCheckboxStyle(): CheckboxStyle { val textColor = retrieveColorOrUnspecified("CheckBox.foreground") val colors = CheckboxColors( @@ -447,15 +447,16 @@ private fun readUndecoratedDropdownStyle( ) } -private fun readGroupHeaderStyle() = GroupHeaderStyle( - colors = GroupHeaderColors( - divider = retrieveColorOrUnspecified("Separator.separatorColor"), - ), - metrics = GroupHeaderMetrics( - dividerThickness = 1.dp, // see DarculaSeparatorUI - indent = 1.dp, // see DarculaSeparatorUI - ), -) +private fun readGroupHeaderStyle() = + GroupHeaderStyle( + colors = GroupHeaderColors( + divider = retrieveColorOrUnspecified("Separator.separatorColor"), + ), + metrics = GroupHeaderMetrics( + dividerThickness = 1.dp, // see DarculaSeparatorUI + indent = 1.dp, // see DarculaSeparatorUI + ), + ) private fun readHorizontalProgressBarStyle() = HorizontalProgressBarStyle( colors = HorizontalProgressBarColors( @@ -644,23 +645,24 @@ private fun readRadioButtonStyle(): RadioButtonStyle { ) } -private fun readScrollbarStyle(isDark: Boolean) = IntUiScrollbarStyle( - colors = IntUiScrollbarColors( - // See ScrollBarPainter.THUMB_OPAQUE_BACKGROUND - thumbBackground = retrieveColorOrUnspecified("ScrollBar.Mac.Transparent.thumbColor") - .takeOrElse { if (isDark) Color(0x59808080) else Color(0x33000000) }, - // See ScrollBarPainter.THUMB_OPAQUE_HOVERED_BACKGROUND - thumbBackgroundHovered = retrieveColorOrUnspecified("ScrollBar.Mac.Transparent.hoverThumbColor") - .takeOrElse { if (isDark) Color(0x8C808080) else Color(0x80000000) }, - ), - metrics = IntUiScrollbarMetrics( - thumbCornerSize = CornerSize(100), - thumbThickness = 8.dp, - minThumbLength = 16.dp, - trackPadding = PaddingValues(start = 7.dp, end = 3.dp), - ), - hoverDuration = 300.milliseconds, -) +private fun readScrollbarStyle(isDark: Boolean) = + ScrollbarStyle( + colors = ScrollbarColors( + // See ScrollBarPainter.THUMB_OPAQUE_BACKGROUND + thumbBackground = retrieveColorOrUnspecified("ScrollBar.Mac.Transparent.thumbColor") + .takeOrElse { if (isDark) Color(0x59808080) else Color(0x33000000) }, + // See ScrollBarPainter.THUMB_OPAQUE_HOVERED_BACKGROUND + thumbBackgroundHovered = retrieveColorOrUnspecified("ScrollBar.Mac.Transparent.hoverThumbColor") + .takeOrElse { if (isDark) Color(0x8C808080) else Color(0x80000000) }, + ), + metrics = ScrollbarMetrics( + thumbCornerSize = CornerSize(100), + thumbThickness = 8.dp, + minThumbLength = 16.dp, + trackPadding = PaddingValues(start = 7.dp, end = 3.dp), + ), + hoverDuration = 300.milliseconds, + ) private fun readTextAreaStyle(textStyle: TextStyle, metrics: IntUiTextFieldMetrics): IntUiTextAreaStyle { val normalBackground = retrieveColorOrUnspecified("TextArea.background") @@ -919,23 +921,24 @@ private fun readTooltipStyle() = ), ) -private fun readIconButtonStyle(): IconButtonStyle = IconButtonStyle( - metrics = IconButtonMetrics( - cornerSize = CornerSize(DarculaUIUtil.BUTTON_ARC.dp / 2), - borderWidth = 1.dp, - padding = PaddingValues(0.dp), - minSize = DpSize(16.dp, 16.dp), - ), - colors = IconButtonColors( - background = Color.Unspecified, - backgroundDisabled = Color.Unspecified, - backgroundFocused = Color.Unspecified, - backgroundPressed = retrieveColorOrUnspecified("ActionButton.pressedBackground"), - backgroundHovered = retrieveColorOrUnspecified("ActionButton.hoverBackground"), - border = Color.Unspecified, - borderDisabled = Color.Unspecified, - borderFocused = retrieveColorOrUnspecified("ActionButton.focusedBorderColor"), - borderPressed = retrieveColorOrUnspecified("ActionButton.pressedBorderColor"), - borderHovered = retrieveColorOrUnspecified("ActionButton.hoverBorderColor"), - ), -) +private fun readIconButtonStyle(): IconButtonStyle = + IconButtonStyle( + metrics = IconButtonMetrics( + cornerSize = CornerSize(DarculaUIUtil.BUTTON_ARC.dp / 2), + borderWidth = 1.dp, + padding = PaddingValues(0.dp), + minSize = DpSize(16.dp, 16.dp), + ), + colors = IconButtonColors( + background = Color.Unspecified, + backgroundDisabled = Color.Unspecified, + backgroundFocused = Color.Unspecified, + backgroundPressed = retrieveColorOrUnspecified("ActionButton.pressedBackground"), + backgroundHovered = retrieveColorOrUnspecified("ActionButton.hoverBackground"), + border = Color.Unspecified, + borderDisabled = Color.Unspecified, + borderFocused = retrieveColorOrUnspecified("ActionButton.focusedBorderColor"), + borderPressed = retrieveColorOrUnspecified("ActionButton.pressedBorderColor"), + borderHovered = retrieveColorOrUnspecified("ActionButton.hoverBorderColor"), + ), + ) 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 26b2ff5b5..d4f7b287b 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.IntUiLabelledTextFieldStyle -import org.jetbrains.jewel.intui.standalone.styling.IntUiScrollbarStyle import org.jetbrains.jewel.intui.standalone.styling.IntUiTabStyle import org.jetbrains.jewel.intui.standalone.styling.IntUiTextAreaStyle import org.jetbrains.jewel.intui.standalone.styling.IntUiTextFieldStyle @@ -101,7 +100,7 @@ object IntUiTheme : BaseIntUiTheme { menuStyle: MenuStyle = MenuStyle.dark(), outlinedButtonStyle: ButtonStyle = ButtonStyle.Outlined.dark(), radioButtonStyle: RadioButtonStyle = RadioButtonStyle.dark(), - scrollbarStyle: ScrollbarStyle = IntUiScrollbarStyle.dark(), + scrollbarStyle: ScrollbarStyle = ScrollbarStyle.dark(), textAreaStyle: IntUiTextAreaStyle = IntUiTextAreaStyle.dark(), textFieldStyle: TextFieldStyle = IntUiTextFieldStyle.dark(), tooltipStyle: IntUiTooltipStyle = IntUiTooltipStyle.dark(), @@ -150,7 +149,7 @@ object IntUiTheme : BaseIntUiTheme { menuStyle: MenuStyle = MenuStyle.light(), outlinedButtonStyle: ButtonStyle = ButtonStyle.Outlined.light(), radioButtonStyle: RadioButtonStyle = RadioButtonStyle.light(), - scrollbarStyle: ScrollbarStyle = IntUiScrollbarStyle.light(), + scrollbarStyle: ScrollbarStyle = ScrollbarStyle.light(), textAreaStyle: IntUiTextAreaStyle = IntUiTextAreaStyle.light(), textFieldStyle: TextFieldStyle = IntUiTextFieldStyle.light(), tooltipStyle: IntUiTooltipStyle = IntUiTooltipStyle.light(), diff --git a/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiScrollbarStyling.kt b/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiScrollbarStyling.kt index 136817c65..0582b1f51 100644 --- a/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiScrollbarStyling.kt +++ b/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiScrollbarStyling.kt @@ -3,72 +3,44 @@ 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.Color import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp -import org.jetbrains.jewel.GenerateDataFunctions import org.jetbrains.jewel.styling.ScrollbarColors import org.jetbrains.jewel.styling.ScrollbarMetrics import org.jetbrains.jewel.styling.ScrollbarStyle import kotlin.time.Duration import kotlin.time.Duration.Companion.milliseconds -@Stable -@GenerateDataFunctions -class IntUiScrollbarStyle( - override val colors: IntUiScrollbarColors, - override val metrics: IntUiScrollbarMetrics, - override val hoverDuration: Duration, -) : ScrollbarStyle { - - companion object { - - @Composable - fun light( - colors: IntUiScrollbarColors = IntUiScrollbarColors.light(), - metrics: IntUiScrollbarMetrics = IntUiScrollbarMetrics(), - hoverDuration: Duration = 300.milliseconds, - ) = IntUiScrollbarStyle(colors, metrics, hoverDuration) - - @Composable - fun dark( - colors: IntUiScrollbarColors = IntUiScrollbarColors.dark(), - metrics: IntUiScrollbarMetrics = IntUiScrollbarMetrics(), - hoverDuration: Duration = 300.milliseconds, - ) = IntUiScrollbarStyle(colors, metrics, hoverDuration) - } -} - -@Immutable -@GenerateDataFunctions -class IntUiScrollbarColors( - override val thumbBackground: Color, - override val thumbBackgroundHovered: Color, -) : ScrollbarColors { - - companion object { - - @Composable - fun light( - thumbBackground: Color = Color(0x33000000), - thumbBackgroundHovered: Color = Color(0x80000000), - ) = IntUiScrollbarColors(thumbBackground, thumbBackgroundHovered) - - @Composable - fun dark( - thumbBackground: Color = Color(0x59808080), - thumbBackgroundHovered: Color = Color(0x8C808080), - ) = IntUiScrollbarColors(thumbBackground, thumbBackgroundHovered) - } -} - -@Stable -@GenerateDataFunctions -class IntUiScrollbarMetrics( - override val thumbCornerSize: CornerSize = CornerSize(100), - override val thumbThickness: Dp = 8.dp, - override val minThumbLength: Dp = 16.dp, - override val trackPadding: PaddingValues = PaddingValues(start = 7.dp, end = 3.dp), -) : ScrollbarMetrics +@Composable +fun ScrollbarStyle.Companion.light( + colors: ScrollbarColors = ScrollbarColors.light(), + metrics: ScrollbarMetrics = ScrollbarMetrics.defaults(), + hoverDuration: Duration = 300.milliseconds, +) = ScrollbarStyle(colors, metrics, hoverDuration) + +@Composable +fun ScrollbarStyle.Companion.dark( + colors: ScrollbarColors = ScrollbarColors.dark(), + metrics: ScrollbarMetrics = ScrollbarMetrics.defaults(), + hoverDuration: Duration = 300.milliseconds, +) = ScrollbarStyle(colors, metrics, hoverDuration) + +@Composable +fun ScrollbarColors.Companion.light( + thumbBackground: Color = Color(0x33000000), + thumbBackgroundHovered: Color = Color(0x80000000), +) = ScrollbarColors(thumbBackground, thumbBackgroundHovered) + +@Composable +fun ScrollbarColors.Companion.dark( + thumbBackground: Color = Color(0x59808080), + thumbBackgroundHovered: Color = Color(0x8C808080), +) = ScrollbarColors(thumbBackground, thumbBackgroundHovered) + +fun ScrollbarMetrics.Companion.defaults( + thumbCornerSize: CornerSize = CornerSize(100), + thumbThickness: Dp = 8.dp, + minThumbLength: Dp = 16.dp, + trackPadding: PaddingValues = PaddingValues(start = 7.dp, end = 3.dp), +) = ScrollbarMetrics(thumbCornerSize, thumbThickness, minThumbLength, trackPadding)