Skip to content

Commit

Permalink
Fix tooltip styling (#156)
Browse files Browse the repository at this point in the history
Fix inconsistencies with styling
  • Loading branch information
edivad1999 authored Oct 6, 2023
1 parent c0a69b5 commit 7633be3
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 26 deletions.
27 changes: 19 additions & 8 deletions core/src/main/kotlin/org/jetbrains/jewel/Tooltip.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ interface TooltipColors {
val background: Color
val content: Color
val border: Color
val shadow: Color
}

@Stable
Expand All @@ -30,6 +31,7 @@ interface TooltipMetrics {
val showDelay: Duration
val cornerSize: CornerSize
val borderWidth: Dp
val shadowSize: Dp
}

val LocalTooltipStyle = staticCompositionLocalOf<TooltipStyle> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
}
Expand Down Expand Up @@ -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),
),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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

0 comments on commit 7633be3

Please sign in to comment.