From 7633be31b5ed50e97933decf6188362722b5c926 Mon Sep 17 00:00:00 2001 From: Davide Magli Date: Fri, 6 Oct 2023 10:05:27 +0200 Subject: [PATCH] Fix tooltip styling (#156) Fix inconsistencies with styling --- .../kotlin/org/jetbrains/jewel/Tooltip.kt | 27 +++++++++++++------ .../jetbrains/jewel/styling/TooltipStyling.kt | 2 ++ .../org/jetbrains/jewel/bridge/IntUiBridge.kt | 17 +++++------- .../standalone/styling/IntUiTooltipStyling.kt | 17 +++++++----- 4 files changed, 37 insertions(+), 26 deletions(-) diff --git a/core/src/main/kotlin/org/jetbrains/jewel/Tooltip.kt b/core/src/main/kotlin/org/jetbrains/jewel/Tooltip.kt index beff944e4..b98bade98 100644 --- a/core/src/main/kotlin/org/jetbrains/jewel/Tooltip.kt +++ b/core/src/main/kotlin/org/jetbrains/jewel/Tooltip.kt @@ -11,6 +11,8 @@ import androidx.compose.runtime.Composable import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.shadow +import androidx.compose.ui.graphics.Color import androidx.compose.ui.unit.DpOffset import androidx.compose.ui.unit.dp import org.jetbrains.jewel.styling.TooltipStyle @@ -32,14 +34,23 @@ import org.jetbrains.jewel.styling.TooltipStyle LocalContentColor provides style.colors.content, ) { Box( - modifier = Modifier.background( - color = style.colors.background, - shape = RoundedCornerShape(style.metrics.cornerSize), - ).border( - width = style.metrics.borderWidth, - color = style.colors.border, - shape = RoundedCornerShape(style.metrics.cornerSize), - ).padding(style.metrics.contentPadding), + modifier = Modifier + .shadow( + elevation = style.metrics.shadowSize, + shape = RoundedCornerShape(style.metrics.cornerSize), + ambientColor = style.colors.shadow, + spotColor = Color.Transparent, + ) + .background( + color = style.colors.background, + shape = RoundedCornerShape(style.metrics.cornerSize), + ) + .border( + width = style.metrics.borderWidth, + color = style.colors.border, + shape = RoundedCornerShape(style.metrics.cornerSize), + ) + .padding(style.metrics.contentPadding), ) { tooltip() } diff --git a/core/src/main/kotlin/org/jetbrains/jewel/styling/TooltipStyling.kt b/core/src/main/kotlin/org/jetbrains/jewel/styling/TooltipStyling.kt index 3686eae95..bc9bada87 100644 --- a/core/src/main/kotlin/org/jetbrains/jewel/styling/TooltipStyling.kt +++ b/core/src/main/kotlin/org/jetbrains/jewel/styling/TooltipStyling.kt @@ -21,6 +21,7 @@ interface TooltipColors { val background: Color val content: Color val border: Color + val shadow: Color } @Stable @@ -30,6 +31,7 @@ interface TooltipMetrics { val showDelay: Duration val cornerSize: CornerSize val borderWidth: Dp + val shadowSize: Dp } val LocalTooltipStyle = 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 ef1a8d193..548d127e2 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 @@ -167,7 +167,7 @@ internal fun createSwingIntUiComponentStyling( scrollbarStyle = readScrollbarStyle(theme.isDark), textAreaStyle = readTextAreaStyle(textAreaTextStyle, textFieldStyle.metrics), circularProgressStyle = readCircularProgressStyle(theme.isDark), - tooltipStyle = readTooltipStyle(theme.isDark), + tooltipStyle = readTooltipStyle(), textFieldStyle = textFieldStyle, ) } @@ -899,19 +899,14 @@ private fun readCircularProgressStyle( ?: if (isDark) Color(0xFF6F737A) else Color(0xFFA8ADBD), ) -private fun readTooltipStyle( - isDark: Boolean, -): IntUiTooltipStyle { - val background = - if (isDark) "Tooltip.background" else "ToolTip.background" - val content = - if (isDark) "Tooltip.foreground" else "ToolTip.foreground" +private fun readTooltipStyle(): IntUiTooltipStyle { return IntUiTooltipStyle( metrics = IntUiTooltipMetrics(), colors = IntUiTooltipColors( - content = retrieveColorOrUnspecified(content), - background = retrieveColorOrUnspecified(background), - border = retrieveColorOrUnspecified("Tooltip.borderColor"), + content = retrieveColorOrUnspecified("ToolTip.foreground"), + background = retrieveColorOrUnspecified("ToolTip.background"), + border = retrieveColorOrUnspecified("ToolTip.borderColor"), + shadow = Color.Black.copy(alpha = .6f), ), ) } diff --git a/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiTooltipStyling.kt b/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiTooltipStyling.kt index f6c39468d..91fa66728 100644 --- a/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiTooltipStyling.kt +++ b/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiTooltipStyling.kt @@ -7,7 +7,6 @@ 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.IntelliJTheme import org.jetbrains.jewel.intui.core.theme.IntUiDarkTheme import org.jetbrains.jewel.intui.core.theme.IntUiLightTheme import org.jetbrains.jewel.styling.TooltipColors @@ -49,6 +48,7 @@ data class IntUiTooltipColors( override val content: Color, override val background: Color, override val border: Color, + override val shadow: Color, ) : TooltipColors { companion object { @@ -57,22 +57,25 @@ data class IntUiTooltipColors( fun light( contentColor: Color = IntUiLightTheme.colors.grey(12), backgroundColor: Color = IntUiLightTheme.colors.grey(2), - borderColor: Color = IntelliJTheme.globalColors.borders.normal, - ) = IntUiTooltipColors(contentColor, backgroundColor, borderColor) + borderColor: Color = backgroundColor, + shadow: Color = Color(0x78919191), // Not a palette color + ) = IntUiTooltipColors(contentColor, backgroundColor, borderColor, shadow) @Composable fun dark( contentColor: Color = IntUiDarkTheme.colors.grey(12), backgroundColor: Color = IntUiDarkTheme.colors.grey(2), - borderColor: Color = IntelliJTheme.globalColors.borders.normal, - ) = IntUiTooltipColors(contentColor, backgroundColor, borderColor) + shadow: Color = Color(0x66000000), // Not a palette color + borderColor: Color = IntUiDarkTheme.colors.grey(3), + ) = IntUiTooltipColors(contentColor, backgroundColor, borderColor, shadow) } } @Stable data class IntUiTooltipMetrics( - override val contentPadding: PaddingValues = PaddingValues(vertical = 8.dp, horizontal = 8.dp), + override val contentPadding: PaddingValues = PaddingValues(vertical = 9.dp, horizontal = 12.dp), override val showDelay: Duration = 0.milliseconds, - override val cornerSize: CornerSize = CornerSize(8.dp), + override val cornerSize: CornerSize = CornerSize(5.dp), override val borderWidth: Dp = 1.dp, + override val shadowSize: Dp = 12.dp, ) : TooltipMetrics