From c0a69b59e52cc24d447dc2aed05277ba2a02a8d6 Mon Sep 17 00:00:00 2001 From: Fabrizio Scarponi <36624359+fscarponi@users.noreply.github.com> Date: Wed, 4 Oct 2023 17:18:50 +0200 Subject: [PATCH] Tooltips (#154) * Added tooltips wip * fixes * fixes * fixes * happy lint * fixed border clip * fixed pr comments --------- Co-authored-by: davide magli --- .../main/kotlin/org/jetbrains/jewel/Button.kt | 4 +- .../kotlin/org/jetbrains/jewel/Checkbox.kt | 2 +- .../jewel/CircularProgressIndicator.kt | 2 +- .../kotlin/org/jetbrains/jewel/GroupHeader.kt | 23 +++--- .../jewel/IntelliJComponentStyling.kt | 4 + .../org/jetbrains/jewel/IntelliJTheme.kt | 15 ++-- .../jewel/IntelliJThemeDefinition.kt | 2 + .../org/jetbrains/jewel/LabelledTextField.kt | 28 +++---- .../kotlin/org/jetbrains/jewel/RadioButton.kt | 8 +- .../main/kotlin/org/jetbrains/jewel/Tabs.kt | 3 +- .../main/kotlin/org/jetbrains/jewel/Text.kt | 8 +- .../kotlin/org/jetbrains/jewel/TextArea.kt | 4 +- .../kotlin/org/jetbrains/jewel/TextField.kt | 2 +- .../kotlin/org/jetbrains/jewel/Tooltip.kt | 53 +++++++++++++ .../jewel/styling/GroupHeaderStyling.kt | 1 - .../jetbrains/jewel/styling/TooltipStyling.kt | 37 +++++++++ .../org/jetbrains/jewel/bridge/IntUiBridge.kt | 23 +++++- .../jewel/intui/core/BaseIntUiTheme.kt | 9 +-- .../jewel/intui/core/IntUiThemeDefinition.kt | 2 + .../jewel/intui/standalone/IntUiTheme.kt | 27 ++++--- .../styling/IntUiCheckboxStyling.kt | 4 +- .../styling/IntUiDropdownStyling.kt | 4 +- .../styling/IntUiGroupHeaderStyling.kt | 7 +- .../styling/IntUiLabelledTextFieldStyling.kt | 16 ++-- .../styling/IntUiLazyTreeStyling.kt | 4 +- .../standalone/styling/IntUiLinkStyling.kt | 8 +- .../styling/IntUiRadioButtonStyling.kt | 17 ++-- .../standalone/styling/IntUiTabStyling.kt | 6 +- .../styling/IntUiTextAreaStyling.kt | 4 +- .../styling/IntUiTextFieldStyling.kt | 4 +- .../standalone/styling/IntUiTooltipStyling.kt | 78 +++++++++++++++++++ .../samples/ideplugin/JewelDemoToolWindow.kt | 11 +++ .../jewel/samples/standalone/Main.kt | 2 + .../samples/standalone/components/Tooltips.kt | 21 +++++ 34 files changed, 334 insertions(+), 109 deletions(-) create mode 100644 core/src/main/kotlin/org/jetbrains/jewel/Tooltip.kt create mode 100644 core/src/main/kotlin/org/jetbrains/jewel/styling/TooltipStyling.kt create mode 100644 int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiTooltipStyling.kt create mode 100644 samples/standalone/src/main/kotlin/org/jetbrains/jewel/samples/standalone/components/Tooltips.kt diff --git a/core/src/main/kotlin/org/jetbrains/jewel/Button.kt b/core/src/main/kotlin/org/jetbrains/jewel/Button.kt index 6e7f911ae..7521dda44 100644 --- a/core/src/main/kotlin/org/jetbrains/jewel/Button.kt +++ b/core/src/main/kotlin/org/jetbrains/jewel/Button.kt @@ -43,7 +43,7 @@ fun DefaultButton( enabled: Boolean = true, interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, style: ButtonStyle = IntelliJTheme.defaultButtonStyle, - textStyle: TextStyle = IntelliJTheme.defaultTextStyle, + textStyle: TextStyle = IntelliJTheme.textStyle, content: @Composable RowScope.() -> Unit, ) { ButtonImpl( @@ -64,7 +64,7 @@ fun OutlinedButton( enabled: Boolean = true, interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, style: ButtonStyle = IntelliJTheme.outlinedButtonStyle, - textStyle: TextStyle = IntelliJTheme.defaultTextStyle, + textStyle: TextStyle = IntelliJTheme.textStyle, content: @Composable RowScope.() -> Unit, ) { ButtonImpl( diff --git a/core/src/main/kotlin/org/jetbrains/jewel/Checkbox.kt b/core/src/main/kotlin/org/jetbrains/jewel/Checkbox.kt index cc6d70385..2aaed34b7 100644 --- a/core/src/main/kotlin/org/jetbrains/jewel/Checkbox.kt +++ b/core/src/main/kotlin/org/jetbrains/jewel/Checkbox.kt @@ -315,7 +315,7 @@ private fun CheckboxImpl( val contentColor by colors.contentFor(checkboxState) CompositionLocalProvider( LocalTextStyle provides textStyle.copy(color = contentColor.takeOrElse { textStyle.color }), - LocalContentColor provides contentColor.takeOrElse { textStyle.color }, + LocalContentColor provides contentColor.takeOrElse { LocalContentColor.current }, ) { content() } diff --git a/core/src/main/kotlin/org/jetbrains/jewel/CircularProgressIndicator.kt b/core/src/main/kotlin/org/jetbrains/jewel/CircularProgressIndicator.kt index 20f7063ef..b605e96af 100644 --- a/core/src/main/kotlin/org/jetbrains/jewel/CircularProgressIndicator.kt +++ b/core/src/main/kotlin/org/jetbrains/jewel/CircularProgressIndicator.kt @@ -75,7 +75,7 @@ private fun CircularProgressIndicatorImpl( LaunchedEffect(style.color) { val frames = frameRetriever(style.color.takeOrElse { defaultColor }) while (true) { - for (i in 0 until frames.size) { + for (i in frames.indices) { currentFrame = frames[i] to i isFrameReady = true delay(style.frameTime.inWholeMilliseconds) diff --git a/core/src/main/kotlin/org/jetbrains/jewel/GroupHeader.kt b/core/src/main/kotlin/org/jetbrains/jewel/GroupHeader.kt index cd3486e5a..1deb0bcf9 100644 --- a/core/src/main/kotlin/org/jetbrains/jewel/GroupHeader.kt +++ b/core/src/main/kotlin/org/jetbrains/jewel/GroupHeader.kt @@ -2,9 +2,9 @@ package org.jetbrains.jewel import androidx.compose.foundation.layout.Row import androidx.compose.runtime.Composable -import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color import org.jetbrains.jewel.styling.GroupHeaderStyle import org.jetbrains.jewel.styling.LocalGroupHeaderStyle @@ -12,19 +12,16 @@ import org.jetbrains.jewel.styling.LocalGroupHeaderStyle fun GroupHeader( text: String, modifier: Modifier = Modifier, + textColor: Color = Color.Unspecified, style: GroupHeaderStyle = LocalGroupHeaderStyle.current, ) { - CompositionLocalProvider( - LocalContentColor provides style.colors.content, - ) { - Row(modifier, verticalAlignment = Alignment.CenterVertically) { - Text(text) - Divider( - color = style.colors.divider, - orientation = Orientation.Horizontal, - startIndent = style.metrics.indent, - thickness = style.metrics.dividerThickness, - ) - } + Row(modifier, verticalAlignment = Alignment.CenterVertically) { + Text(text, color = textColor) + Divider( + color = style.colors.divider, + orientation = Orientation.Horizontal, + startIndent = style.metrics.indent, + thickness = style.metrics.dividerThickness, + ) } } diff --git a/core/src/main/kotlin/org/jetbrains/jewel/IntelliJComponentStyling.kt b/core/src/main/kotlin/org/jetbrains/jewel/IntelliJComponentStyling.kt index 08a232f8f..bb2282384 100644 --- a/core/src/main/kotlin/org/jetbrains/jewel/IntelliJComponentStyling.kt +++ b/core/src/main/kotlin/org/jetbrains/jewel/IntelliJComponentStyling.kt @@ -17,6 +17,7 @@ import org.jetbrains.jewel.styling.ScrollbarStyle import org.jetbrains.jewel.styling.TabStyle import org.jetbrains.jewel.styling.TextAreaStyle import org.jetbrains.jewel.styling.TextFieldStyle +import org.jetbrains.jewel.styling.TooltipStyle @Stable class IntelliJComponentStyling( @@ -38,6 +39,7 @@ class IntelliJComponentStyling( val textAreaStyle: TextAreaStyle, val textFieldStyle: TextFieldStyle, val circularProgressStyle: CircularProgressStyle, + val tooltipStyle: TooltipStyle, ) { override fun equals(other: Any?): Boolean { @@ -64,6 +66,7 @@ class IntelliJComponentStyling( if (defaultTabStyle != other.defaultTabStyle) return false if (editorTabStyle != other.editorTabStyle) return false if (circularProgressStyle != other.circularProgressStyle) return false + if (tooltipStyle != other.tooltipStyle) return false return true } @@ -87,6 +90,7 @@ class IntelliJComponentStyling( result = 31 * result + defaultTabStyle.hashCode() result = 31 * result + editorTabStyle.hashCode() result = 31 * result + circularProgressStyle.hashCode() + result = 31 * result + tooltipStyle.hashCode() return result } diff --git a/core/src/main/kotlin/org/jetbrains/jewel/IntelliJTheme.kt b/core/src/main/kotlin/org/jetbrains/jewel/IntelliJTheme.kt index e036ab87e..ba1874492 100644 --- a/core/src/main/kotlin/org/jetbrains/jewel/IntelliJTheme.kt +++ b/core/src/main/kotlin/org/jetbrains/jewel/IntelliJTheme.kt @@ -34,12 +34,14 @@ import org.jetbrains.jewel.styling.LocalRadioButtonStyle import org.jetbrains.jewel.styling.LocalScrollbarStyle import org.jetbrains.jewel.styling.LocalTextAreaStyle import org.jetbrains.jewel.styling.LocalTextFieldStyle +import org.jetbrains.jewel.styling.LocalTooltipStyle import org.jetbrains.jewel.styling.MenuStyle import org.jetbrains.jewel.styling.RadioButtonStyle import org.jetbrains.jewel.styling.ScrollbarStyle import org.jetbrains.jewel.styling.TabStyle import org.jetbrains.jewel.styling.TextAreaStyle import org.jetbrains.jewel.styling.TextFieldStyle +import org.jetbrains.jewel.styling.TooltipStyle interface IntelliJTheme { @@ -59,7 +61,7 @@ interface IntelliJTheme { @ReadOnlyComposable get() = LocalGlobalMetrics.current - val defaultTextStyle: TextStyle + val textStyle: TextStyle @Composable @ReadOnlyComposable get() = LocalTextStyle.current @@ -182,6 +184,11 @@ interface IntelliJTheme { @Composable @ReadOnlyComposable get() = LocalCircularProgressStyle.current + + val tooltipStyle: TooltipStyle + @Composable + @ReadOnlyComposable + get() = LocalTooltipStyle.current } } @@ -198,12 +205,10 @@ fun IntelliJTheme( @Composable fun IntelliJTheme(theme: IntelliJThemeDefinition, content: @Composable () -> Unit) { - val defaultTextStyle = theme.defaultTextStyle - CompositionLocalProvider( LocalIsDarkTheme provides theme.isDark, - LocalContentColor provides defaultTextStyle.color, - LocalTextStyle provides defaultTextStyle, + LocalContentColor provides theme.contentColor, + LocalTextStyle provides theme.defaultTextStyle, LocalGlobalColors provides theme.globalColors, LocalGlobalMetrics provides theme.globalMetrics, content = content, diff --git a/core/src/main/kotlin/org/jetbrains/jewel/IntelliJThemeDefinition.kt b/core/src/main/kotlin/org/jetbrains/jewel/IntelliJThemeDefinition.kt index 605a6b54f..31ba5d9f4 100644 --- a/core/src/main/kotlin/org/jetbrains/jewel/IntelliJThemeDefinition.kt +++ b/core/src/main/kotlin/org/jetbrains/jewel/IntelliJThemeDefinition.kt @@ -1,6 +1,7 @@ package org.jetbrains.jewel import androidx.compose.runtime.Immutable +import androidx.compose.ui.graphics.Color import androidx.compose.ui.text.TextStyle @Immutable @@ -10,6 +11,7 @@ interface IntelliJThemeDefinition { val globalColors: GlobalColors val globalMetrics: GlobalMetrics val defaultTextStyle: TextStyle + val contentColor: Color val colorPalette: IntelliJThemeColorPalette val iconData: IntelliJThemeIconData diff --git a/core/src/main/kotlin/org/jetbrains/jewel/LabelledTextField.kt b/core/src/main/kotlin/org/jetbrains/jewel/LabelledTextField.kt index b29bf87ac..af2f8fd17 100644 --- a/core/src/main/kotlin/org/jetbrains/jewel/LabelledTextField.kt +++ b/core/src/main/kotlin/org/jetbrains/jewel/LabelledTextField.kt @@ -22,11 +22,11 @@ import androidx.compose.ui.unit.offset import org.jetbrains.jewel.styling.LabelledTextFieldStyle /** - * @param placeholder the optional placeholder to be displayed over the component when - * the [value] is empty. - * @param hint the optional hint to be displayed underneath the component. By default it - * will have a greyed out appearance and smaller text. * @param label the label to display above the component. + * @param hint the optional hint to be displayed underneath the component. + * By default it will have a greyed out appearance and smaller text. + * @param placeholder the optional placeholder to be displayed over the + * component when the [value] is empty. */ @Composable fun LabelledTextField( @@ -48,7 +48,7 @@ fun LabelledTextField( keyboardActions: KeyboardActions = KeyboardActions(), onTextLayout: (TextLayoutResult) -> Unit = {}, style: LabelledTextFieldStyle = IntelliJTheme.labelledTextFieldStyle, - textStyle: TextStyle = IntelliJTheme.defaultTextStyle, + textStyle: TextStyle = IntelliJTheme.textStyle, interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, ) { var textFieldValueState by remember { mutableStateOf(TextFieldValue(text = value)) } @@ -86,11 +86,11 @@ fun LabelledTextField( } /** - * @param placeholder the optional placeholder to be displayed over the component when - * the [value] is empty. - * @param hint the optional hint to be displayed underneath the component. By default it - * will have a greyed out appearance and smaller text. * @param label the label to display above the component. + * @param hint the optional hint to be displayed underneath the component. + * By default it will have a greyed out appearance and smaller text. + * @param placeholder the optional placeholder to be displayed over the + * component when the [value] is empty. */ @Composable fun LabelledTextField( @@ -112,18 +112,12 @@ fun LabelledTextField( keyboardActions: KeyboardActions = KeyboardActions(), onTextLayout: (TextLayoutResult) -> Unit = {}, style: LabelledTextFieldStyle = IntelliJTheme.labelledTextFieldStyle, - textStyle: TextStyle = IntelliJTheme.defaultTextStyle, + textStyle: TextStyle = IntelliJTheme.textStyle, interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, ) { LabelledTextFieldLayout( modifier = modifier, - label = { - CompositionLocalProvider( - LocalTextStyle provides style.textStyles.label, - LocalContentColor provides style.colors.label, - content = label, - ) - }, + label = label, textField = { TextField( value = value, diff --git a/core/src/main/kotlin/org/jetbrains/jewel/RadioButton.kt b/core/src/main/kotlin/org/jetbrains/jewel/RadioButton.kt index 67e490d52..cf833a209 100644 --- a/core/src/main/kotlin/org/jetbrains/jewel/RadioButton.kt +++ b/core/src/main/kotlin/org/jetbrains/jewel/RadioButton.kt @@ -47,7 +47,7 @@ fun RadioButton( outline: Outline = Outline.None, interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, style: RadioButtonStyle = IntelliJTheme.radioButtonStyle, - textStyle: TextStyle = IntelliJTheme.defaultTextStyle, + textStyle: TextStyle = IntelliJTheme.textStyle, ) { RadioButtonImpl( selected = selected, @@ -74,7 +74,7 @@ fun RadioButtonRow( outline: Outline = Outline.None, interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, style: RadioButtonStyle = IntelliJTheme.radioButtonStyle, - textStyle: TextStyle = IntelliJTheme.defaultTextStyle, + textStyle: TextStyle = IntelliJTheme.textStyle, ) { RadioButtonImpl( selected = selected, @@ -101,7 +101,7 @@ fun RadioButtonRow( outline: Outline = Outline.None, interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, style: RadioButtonStyle = IntelliJTheme.radioButtonStyle, - textStyle: TextStyle = IntelliJTheme.defaultTextStyle, + textStyle: TextStyle = IntelliJTheme.textStyle, content: @Composable RowScope.() -> Unit, ) { RadioButtonImpl( @@ -183,7 +183,7 @@ private fun RadioButtonImpl( val contentColor by colors.contentFor(radioButtonState) CompositionLocalProvider( LocalTextStyle provides textStyle.copy(color = contentColor.takeOrElse { textStyle.color }), - LocalContentColor provides contentColor.takeOrElse { textStyle.color }, + LocalContentColor provides contentColor.takeOrElse { textStyle.color.takeOrElse { LocalContentColor.current } }, ) { content() } diff --git a/core/src/main/kotlin/org/jetbrains/jewel/Tabs.kt b/core/src/main/kotlin/org/jetbrains/jewel/Tabs.kt index 8674cb072..ff36c4697 100644 --- a/core/src/main/kotlin/org/jetbrains/jewel/Tabs.kt +++ b/core/src/main/kotlin/org/jetbrains/jewel/Tabs.kt @@ -30,6 +30,7 @@ import androidx.compose.ui.draw.drawBehind import androidx.compose.ui.geometry.Offset import androidx.compose.ui.graphics.SolidColor import androidx.compose.ui.graphics.StrokeCap +import androidx.compose.ui.graphics.takeOrElse import androidx.compose.ui.input.pointer.PointerEventType import androidx.compose.ui.input.pointer.isTertiary import androidx.compose.ui.input.pointer.onPointerEvent @@ -77,7 +78,7 @@ internal fun TabImpl( CompositionLocalProvider( LocalIndication provides NoIndication, - LocalContentColor provides tabStyle.colors.contentFor(tabState).value, + LocalContentColor provides tabStyle.colors.contentFor(tabState).value.takeOrElse { LocalContentColor.current }, ) { val labelAlpha by tabStyle.contentAlpha.labelFor(tabState) val iconAlpha by tabStyle.contentAlpha.iconFor(tabState) diff --git a/core/src/main/kotlin/org/jetbrains/jewel/Text.kt b/core/src/main/kotlin/org/jetbrains/jewel/Text.kt index 255b87a6f..467a65642 100644 --- a/core/src/main/kotlin/org/jetbrains/jewel/Text.kt +++ b/core/src/main/kotlin/org/jetbrains/jewel/Text.kt @@ -35,7 +35,7 @@ fun Text( softWrap: Boolean = true, maxLines: Int = Int.MAX_VALUE, onTextLayout: (TextLayoutResult) -> Unit = {}, - style: TextStyle = IntelliJTheme.defaultTextStyle, + style: TextStyle = IntelliJTheme.textStyle, ) { Text( AnnotatedString(text), @@ -76,13 +76,11 @@ fun Text( maxLines: Int = Int.MAX_VALUE, inlineContent: Map = emptyMap(), onTextLayout: (TextLayoutResult) -> Unit = {}, - style: TextStyle = IntelliJTheme.defaultTextStyle, + style: TextStyle = IntelliJTheme.textStyle, ) { val textColor = color.takeOrElse { style.color.takeOrElse { - LocalContentColor.current.takeOrElse { - LocalTextStyle.current.color - } + LocalContentColor.current } } diff --git a/core/src/main/kotlin/org/jetbrains/jewel/TextArea.kt b/core/src/main/kotlin/org/jetbrains/jewel/TextArea.kt index 1dbc198e1..8929a96ee 100644 --- a/core/src/main/kotlin/org/jetbrains/jewel/TextArea.kt +++ b/core/src/main/kotlin/org/jetbrains/jewel/TextArea.kt @@ -46,7 +46,7 @@ fun TextArea( maxLines: Int = Int.MAX_VALUE, onTextLayout: (TextLayoutResult) -> Unit = {}, style: TextAreaStyle = IntelliJTheme.textAreaStyle, - textStyle: TextStyle = IntelliJTheme.defaultTextStyle, + textStyle: TextStyle = IntelliJTheme.textStyle, interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, ) { var textFieldValueState by remember { mutableStateOf(TextFieldValue(text = value)) } @@ -102,7 +102,7 @@ fun TextArea( maxLines: Int = Int.MAX_VALUE, onTextLayout: (TextLayoutResult) -> Unit = {}, style: TextAreaStyle = IntelliJTheme.textAreaStyle, - textStyle: TextStyle = IntelliJTheme.defaultTextStyle, + textStyle: TextStyle = IntelliJTheme.textStyle, interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, ) { val minSize = style.metrics.minSize diff --git a/core/src/main/kotlin/org/jetbrains/jewel/TextField.kt b/core/src/main/kotlin/org/jetbrains/jewel/TextField.kt index 7d414143e..199967e90 100644 --- a/core/src/main/kotlin/org/jetbrains/jewel/TextField.kt +++ b/core/src/main/kotlin/org/jetbrains/jewel/TextField.kt @@ -104,7 +104,7 @@ fun TextField( keyboardActions: KeyboardActions = KeyboardActions(), onTextLayout: (TextLayoutResult) -> Unit = {}, style: TextFieldStyle = IntelliJTheme.textFieldStyle, - textStyle: TextStyle = IntelliJTheme.defaultTextStyle, + textStyle: TextStyle = IntelliJTheme.textStyle, interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, ) { InputField( diff --git a/core/src/main/kotlin/org/jetbrains/jewel/Tooltip.kt b/core/src/main/kotlin/org/jetbrains/jewel/Tooltip.kt new file mode 100644 index 000000000..beff944e4 --- /dev/null +++ b/core/src/main/kotlin/org/jetbrains/jewel/Tooltip.kt @@ -0,0 +1,53 @@ +package org.jetbrains.jewel + +import androidx.compose.foundation.TooltipArea +import androidx.compose.foundation.TooltipPlacement +import androidx.compose.foundation.background +import androidx.compose.foundation.border +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.runtime.Composable +import androidx.compose.runtime.CompositionLocalProvider +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.DpOffset +import androidx.compose.ui.unit.dp +import org.jetbrains.jewel.styling.TooltipStyle + +@Composable fun Tooltip( + tooltip: @Composable () -> Unit, + modifier: Modifier = Modifier, + tooltipPlacement: TooltipPlacement = TooltipPlacement.ComponentRect( + alignment = Alignment.CenterEnd, + anchor = Alignment.BottomEnd, + offset = DpOffset(4.dp, 4.dp), + ), + style: TooltipStyle = IntelliJTheme.tooltipStyle, + content: @Composable () -> Unit, +) { + TooltipArea( + tooltip = { + CompositionLocalProvider( + 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), + ) { + tooltip() + } + } + }, + modifier = modifier, + delayMillis = style.metrics.showDelay.inWholeMilliseconds.toInt(), + tooltipPlacement = tooltipPlacement, + content = content, + ) +} diff --git a/core/src/main/kotlin/org/jetbrains/jewel/styling/GroupHeaderStyling.kt b/core/src/main/kotlin/org/jetbrains/jewel/styling/GroupHeaderStyling.kt index c79b7d6e2..849327367 100644 --- a/core/src/main/kotlin/org/jetbrains/jewel/styling/GroupHeaderStyling.kt +++ b/core/src/main/kotlin/org/jetbrains/jewel/styling/GroupHeaderStyling.kt @@ -15,7 +15,6 @@ interface GroupHeaderStyle { @Immutable interface GroupHeaderColors { - val content: Color val divider: Color } diff --git a/core/src/main/kotlin/org/jetbrains/jewel/styling/TooltipStyling.kt b/core/src/main/kotlin/org/jetbrains/jewel/styling/TooltipStyling.kt new file mode 100644 index 000000000..3686eae95 --- /dev/null +++ b/core/src/main/kotlin/org/jetbrains/jewel/styling/TooltipStyling.kt @@ -0,0 +1,37 @@ +package org.jetbrains.jewel.styling + +import androidx.compose.foundation.layout.PaddingValues +import androidx.compose.foundation.shape.CornerSize +import androidx.compose.runtime.Stable +import androidx.compose.runtime.staticCompositionLocalOf +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.unit.Dp +import kotlin.time.Duration + +@Stable +interface TooltipStyle { + + val colors: TooltipColors + val metrics: TooltipMetrics +} + +@Stable +interface TooltipColors { + + val background: Color + val content: Color + val border: Color +} + +@Stable +interface TooltipMetrics { + + val contentPadding: PaddingValues + val showDelay: Duration + val cornerSize: CornerSize + val borderWidth: Dp +} + +val LocalTooltipStyle = staticCompositionLocalOf { + error("No TooltipStyle provided") +} 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 1a6bf9c97..ef1a8d193 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 @@ -86,6 +86,9 @@ import org.jetbrains.jewel.intui.standalone.styling.IntUiTextAreaStyle import org.jetbrains.jewel.intui.standalone.styling.IntUiTextFieldColors import org.jetbrains.jewel.intui.standalone.styling.IntUiTextFieldMetrics 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.styling.InputFieldStyle import org.jetbrains.skiko.DependsOnJBR import javax.swing.UIManager @@ -114,6 +117,7 @@ internal fun createBridgeIntUiDefinition(textStyle: TextStyle): IntUiThemeDefini iconData = BridgeIconData.readFromLaF(), globalMetrics = BridgeGlobalMetrics.readFromLaF(), defaultTextStyle = textStyle, + contentColor = JBColor.foreground().toComposeColor(), ) } @@ -163,6 +167,7 @@ internal fun createSwingIntUiComponentStyling( scrollbarStyle = readScrollbarStyle(theme.isDark), textAreaStyle = readTextAreaStyle(textAreaTextStyle, textFieldStyle.metrics), circularProgressStyle = readCircularProgressStyle(theme.isDark), + tooltipStyle = readTooltipStyle(theme.isDark), textFieldStyle = textFieldStyle, ) } @@ -401,7 +406,6 @@ private fun readDropdownStyle( private fun readGroupHeaderStyle() = IntUiGroupHeaderStyle( colors = IntUiGroupHeaderColors( - content = retrieveColorOrUnspecified("Separator.foreground"), divider = retrieveColorOrUnspecified("Separator.separatorColor"), ), metrics = IntUiGroupHeaderMetrics( @@ -894,3 +898,20 @@ private fun readCircularProgressStyle( .takeIf { it.isSpecified } ?: 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" + return IntUiTooltipStyle( + metrics = IntUiTooltipMetrics(), + colors = IntUiTooltipColors( + content = retrieveColorOrUnspecified(content), + background = retrieveColorOrUnspecified(background), + border = retrieveColorOrUnspecified("Tooltip.borderColor"), + ), + ) +} diff --git a/int-ui/int-ui-core/src/main/kotlin/org/jetbrains/jewel/intui/core/BaseIntUiTheme.kt b/int-ui/int-ui-core/src/main/kotlin/org/jetbrains/jewel/intui/core/BaseIntUiTheme.kt index c3acb83a7..8265b45dd 100644 --- a/int-ui/int-ui-core/src/main/kotlin/org/jetbrains/jewel/intui/core/BaseIntUiTheme.kt +++ b/int-ui/int-ui-core/src/main/kotlin/org/jetbrains/jewel/intui/core/BaseIntUiTheme.kt @@ -44,6 +44,7 @@ import org.jetbrains.jewel.styling.LocalRadioButtonStyle import org.jetbrains.jewel.styling.LocalScrollbarStyle import org.jetbrains.jewel.styling.LocalTextAreaStyle import org.jetbrains.jewel.styling.LocalTextFieldStyle +import org.jetbrains.jewel.styling.LocalTooltipStyle import org.jetbrains.jewel.styling.MenuStyle import org.jetbrains.jewel.styling.RadioButtonStyle import org.jetbrains.jewel.styling.ScrollbarStyle @@ -53,9 +54,6 @@ import org.jetbrains.jewel.styling.TextFieldStyle interface BaseIntUiTheme : IntelliJTheme { - val defaultLightTextStyle: TextStyle - val defaultDarkTextStyle: TextStyle - val globalColors: GlobalColors @Composable @ReadOnlyComposable @@ -66,10 +64,10 @@ interface BaseIntUiTheme : IntelliJTheme { @ReadOnlyComposable get() = IntelliJTheme.globalMetrics - val defaultTextStyle: TextStyle + val textStyle: TextStyle @Composable @ReadOnlyComposable - get() = IntelliJTheme.defaultTextStyle + get() = IntelliJTheme.textStyle val contentColor: Color @Composable @@ -226,6 +224,7 @@ fun BaseIntUiTheme( LocalEditorTabStyle provides componentStyling.editorTabStyle, LocalIndication provides NoIndication, LocalCircularProgressStyle provides componentStyling.circularProgressStyle, + LocalTooltipStyle provides componentStyling.tooltipStyle, ) { IntelliJTheme(theme, swingCompatMode, content) } diff --git a/int-ui/int-ui-core/src/main/kotlin/org/jetbrains/jewel/intui/core/IntUiThemeDefinition.kt b/int-ui/int-ui-core/src/main/kotlin/org/jetbrains/jewel/intui/core/IntUiThemeDefinition.kt index cb042a0bd..dfbe84266 100644 --- a/int-ui/int-ui-core/src/main/kotlin/org/jetbrains/jewel/intui/core/IntUiThemeDefinition.kt +++ b/int-ui/int-ui-core/src/main/kotlin/org/jetbrains/jewel/intui/core/IntUiThemeDefinition.kt @@ -1,6 +1,7 @@ package org.jetbrains.jewel.intui.core import androidx.compose.runtime.Immutable +import androidx.compose.ui.graphics.Color import androidx.compose.ui.text.TextStyle import org.jetbrains.jewel.GlobalColors import org.jetbrains.jewel.GlobalMetrics @@ -15,6 +16,7 @@ class IntUiThemeDefinition( override val iconData: IntelliJThemeIconData, override val globalMetrics: GlobalMetrics, override val defaultTextStyle: TextStyle, + override val contentColor: Color, ) : IntelliJThemeDefinition { override fun equals(other: Any?): Boolean { 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 a7a9c6e4a..99fe885fa 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 @@ -5,6 +5,7 @@ import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember +import androidx.compose.ui.graphics.Color import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.font.FontFamily import androidx.compose.ui.text.font.FontStyle @@ -47,6 +48,7 @@ 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 +import org.jetbrains.jewel.intui.standalone.styling.IntUiTooltipStyle import org.jetbrains.jewel.styling.ButtonStyle import org.jetbrains.jewel.styling.CheckboxStyle import org.jetbrains.jewel.styling.ChipStyle @@ -66,24 +68,22 @@ import org.jetbrains.jewel.themes.StandalonePaletteMapperFactory object IntUiTheme : BaseIntUiTheme { - private val intUiDefaultTextStyle = TextStyle.Default.copy( + val defaultTextStyle = TextStyle.Default.copy( fontFamily = FontFamily.Inter, fontSize = 13.sp, fontWeight = FontWeight.Normal, fontStyle = FontStyle.Normal, ) - override val defaultLightTextStyle = intUiDefaultTextStyle.copy(color = IntUiLightTheme.colors.grey(1)) - override val defaultDarkTextStyle = intUiDefaultTextStyle.copy(color = IntUiDarkTheme.colors.grey(12)) - @Composable fun lightThemeDefinition( colors: GlobalColors = IntUiGlobalColors.light(), metrics: GlobalMetrics = IntUiGlobalMetrics(), palette: IntUiThemeColorPalette = IntUiLightTheme.colors, icons: IntelliJThemeIconData = IntUiLightTheme.icons, - defaultTextStyle: TextStyle = defaultLightTextStyle, - ) = IntUiThemeDefinition(isDark = false, colors, palette, icons, metrics, defaultTextStyle) + defaultTextStyle: TextStyle = this.defaultTextStyle, + contentColor: Color = IntUiLightTheme.colors.grey(1), + ) = IntUiThemeDefinition(isDark = false, colors, palette, icons, metrics, defaultTextStyle, contentColor) @Composable fun darkThemeDefinition( @@ -91,8 +91,9 @@ object IntUiTheme : BaseIntUiTheme { metrics: GlobalMetrics = IntUiGlobalMetrics(), palette: IntUiThemeColorPalette = IntUiDarkTheme.colors, icons: IntelliJThemeIconData = IntUiDarkTheme.icons, - defaultTextStyle: TextStyle = defaultDarkTextStyle, - ) = IntUiThemeDefinition(isDark = true, colors, palette, icons, metrics, defaultTextStyle) + defaultTextStyle: TextStyle = this.defaultTextStyle, + contentColor: Color = IntUiDarkTheme.colors.grey(12), + ) = IntUiThemeDefinition(isDark = true, colors, palette, icons, metrics, defaultTextStyle, contentColor) @Composable fun defaultComponentStyling(theme: IntUiThemeDefinition, svgLoader: SvgLoader): IntelliJComponentStyling { @@ -131,6 +132,7 @@ object IntUiTheme : BaseIntUiTheme { defaultTabStyle: TabStyle = IntUiTabStyle.Default.dark(svgLoader), editorTabStyle: TabStyle = IntUiTabStyle.Editor.dark(svgLoader), circularProgressStyle: CircularProgressStyle = IntUiCircularProgressStyle.dark(), + tooltipStyle: IntUiTooltipStyle = IntUiTooltipStyle.dark(), ) = IntelliJComponentStyling( checkboxStyle = checkboxStyle, @@ -151,6 +153,7 @@ object IntUiTheme : BaseIntUiTheme { textAreaStyle = textAreaStyle, textFieldStyle = textFieldStyle, circularProgressStyle = circularProgressStyle, + tooltipStyle = tooltipStyle, ) @Composable @@ -174,6 +177,7 @@ object IntUiTheme : BaseIntUiTheme { defaultTabStyle: TabStyle = IntUiTabStyle.Default.light(svgLoader), editorTabStyle: TabStyle = IntUiTabStyle.Editor.light(svgLoader), circularProgressStyle: CircularProgressStyle = IntUiCircularProgressStyle.light(), + tooltipStyle: IntUiTooltipStyle = IntUiTooltipStyle.light(), ) = IntelliJComponentStyling( checkboxStyle = checkboxStyle, chipStyle = chipStyle, @@ -193,6 +197,7 @@ object IntUiTheme : BaseIntUiTheme { textAreaStyle = textAreaStyle, textFieldStyle = textFieldStyle, circularProgressStyle = circularProgressStyle, + tooltipStyle = tooltipStyle, ) } @@ -215,9 +220,9 @@ fun IntUiTheme( /** * Create and remember an instance of [SvgLoader]. * - * Note that since [SvgLoader] may cache the loaded images, and - * that creating it may be somewhat expensive, you should only - * create it once at the top level, and pass it around. + * Note that since [SvgLoader] may cache the loaded images, and that + * creating it may be somewhat expensive, you should only create it once at + * the top level, and pass it around. */ @Composable fun rememberSvgLoader( diff --git a/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiCheckboxStyling.kt b/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiCheckboxStyling.kt index a0a711fa5..9272943b3 100644 --- a/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiCheckboxStyling.kt +++ b/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiCheckboxStyling.kt @@ -65,7 +65,7 @@ data class IntUiCheckboxColors( background: Color = IntUiLightTheme.colors.grey(14), backgroundDisabled: Color = IntUiLightTheme.colors.grey(13), backgroundSelected: Color = IntUiLightTheme.colors.blue(4), - content: Color = IntUiLightTheme.colors.grey(1), + content: Color = Color.Unspecified, contentDisabled: Color = IntUiLightTheme.colors.grey(8), contentSelected: Color = content, ) = IntUiCheckboxColors( @@ -82,7 +82,7 @@ data class IntUiCheckboxColors( background: Color = Color.Unspecified, backgroundDisabled: Color = IntUiDarkTheme.colors.grey(3), backgroundSelected: Color = IntUiDarkTheme.colors.blue(6), - content: Color = IntUiDarkTheme.colors.grey(12), + content: Color = Color.Unspecified, contentDisabled: Color = IntUiDarkTheme.colors.grey(7), contentSelected: Color = content, ) = IntUiCheckboxColors( diff --git a/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiDropdownStyling.kt b/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiDropdownStyling.kt index b14f6f6db..69450d903 100644 --- a/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiDropdownStyling.kt +++ b/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiDropdownStyling.kt @@ -40,7 +40,7 @@ data class IntUiDropdownStyle( colors: IntUiDropdownColors = IntUiDropdownColors.light(), metrics: IntUiDropdownMetrics = IntUiDropdownMetrics(), icons: IntUiDropdownIcons = intUiDropdownIcons(svgLoader), - textStyle: TextStyle = IntUiTheme.defaultLightTextStyle, + textStyle: TextStyle = IntUiTheme.defaultTextStyle, menuStyle: MenuStyle = IntUiMenuStyle.light(svgLoader), ) = IntUiDropdownStyle(colors, metrics, icons, textStyle, menuStyle) @@ -50,7 +50,7 @@ data class IntUiDropdownStyle( colors: IntUiDropdownColors = IntUiDropdownColors.dark(), metrics: IntUiDropdownMetrics = IntUiDropdownMetrics(), icons: IntUiDropdownIcons = intUiDropdownIcons(svgLoader), - textStyle: TextStyle = IntUiTheme.defaultDarkTextStyle, + textStyle: TextStyle = IntUiTheme.defaultTextStyle, menuStyle: MenuStyle = IntUiMenuStyle.dark(svgLoader), ) = IntUiDropdownStyle(colors, metrics, icons, textStyle, menuStyle) } diff --git a/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiGroupHeaderStyling.kt b/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiGroupHeaderStyling.kt index f25582164..1f316cee8 100644 --- a/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiGroupHeaderStyling.kt +++ b/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiGroupHeaderStyling.kt @@ -35,7 +35,6 @@ data class IntUiGroupHeaderStyle( @Immutable data class IntUiGroupHeaderColors( - override val content: Color, override val divider: Color, ) : GroupHeaderColors { @@ -43,15 +42,13 @@ data class IntUiGroupHeaderColors( @Composable fun light( - content: Color = IntUiLightTheme.colors.grey(1), divider: Color = IntUiLightTheme.colors.grey(12), - ) = IntUiGroupHeaderColors(content, divider) + ) = IntUiGroupHeaderColors(divider) @Composable fun dark( - content: Color = IntUiDarkTheme.colors.grey(12), divider: Color = IntUiDarkTheme.colors.grey(3), - ) = IntUiGroupHeaderColors(content, divider) + ) = IntUiGroupHeaderColors(divider) } } diff --git a/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiLabelledTextFieldStyling.kt b/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiLabelledTextFieldStyling.kt index 1ea4be9f1..c581ae57b 100644 --- a/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiLabelledTextFieldStyling.kt +++ b/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiLabelledTextFieldStyling.kt @@ -33,7 +33,7 @@ data class IntUiLabelledTextFieldStyle( fun light( colors: IntUiLabelledTextFieldColors = IntUiLabelledTextFieldColors.light(), metrics: IntUiLabelledTextFieldMetrics = IntUiLabelledTextFieldMetrics(), - textStyle: TextStyle = IntUiTheme.defaultLightTextStyle, + textStyle: TextStyle = IntUiTheme.defaultTextStyle, textStyles: IntUiLabelledTextFieldTextStyles = IntUiLabelledTextFieldTextStyles.light(), ) = IntUiLabelledTextFieldStyle(colors, metrics, textStyle, textStyles) @@ -41,7 +41,7 @@ data class IntUiLabelledTextFieldStyle( fun dark( colors: IntUiLabelledTextFieldColors = IntUiLabelledTextFieldColors.dark(), metrics: IntUiLabelledTextFieldMetrics = IntUiLabelledTextFieldMetrics(), - textStyle: TextStyle = IntUiTheme.defaultDarkTextStyle, + textStyle: TextStyle = IntUiTheme.defaultTextStyle, textStyles: IntUiLabelledTextFieldTextStyles = IntUiLabelledTextFieldTextStyles.dark(), ) = IntUiLabelledTextFieldStyle(colors, metrics, textStyle, textStyles) } @@ -99,7 +99,7 @@ data class IntUiLabelledTextFieldColors( caretPressed: Color = caret, caretHovered: Color = caret, placeholder: Color = IntUiLightTheme.colors.grey(8), - label: Color = IntUiLightTheme.colors.grey(1), + label: Color = Color.Unspecified, hint: Color = IntUiLightTheme.colors.grey(6), ) = IntUiLabelledTextFieldColors( background, @@ -150,7 +150,7 @@ data class IntUiLabelledTextFieldColors( caretPressed: Color = caret, caretHovered: Color = caret, placeholder: Color = IntUiDarkTheme.colors.grey(7), - label: Color = IntUiDarkTheme.colors.grey(12), + label: Color = Color.Unspecified, hint: Color = IntUiDarkTheme.colors.grey(7), ) = IntUiLabelledTextFieldColors( background, @@ -200,8 +200,8 @@ data class IntUiLabelledTextFieldTextStyles( @Composable fun light( - label: TextStyle = IntUiTheme.defaultLightTextStyle, - hint: TextStyle = IntUiTheme.defaultLightTextStyle.copy( + label: TextStyle = IntUiTheme.defaultTextStyle, + hint: TextStyle = IntUiTheme.defaultTextStyle.copy( fontSize = 12.sp, lineHeight = 16.sp, ), @@ -209,8 +209,8 @@ data class IntUiLabelledTextFieldTextStyles( @Composable fun dark( - label: TextStyle = IntUiTheme.defaultDarkTextStyle, - hint: TextStyle = IntUiTheme.defaultDarkTextStyle.copy( + label: TextStyle = IntUiTheme.defaultTextStyle, + hint: TextStyle = IntUiTheme.defaultTextStyle.copy( fontSize = 12.sp, lineHeight = 16.sp, ), diff --git a/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiLazyTreeStyling.kt b/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiLazyTreeStyling.kt index 1c83d7ef0..5f4bdea3e 100644 --- a/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiLazyTreeStyling.kt +++ b/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiLazyTreeStyling.kt @@ -60,7 +60,7 @@ data class IntUiLazyTreeColors( @Composable fun light( - content: Color = IntUiLightTheme.colors.grey(1), + content: Color = Color.Unspecified, contentFocused: Color = content, contentSelected: Color = content, contentSelectedFocused: Color = content, @@ -79,7 +79,7 @@ data class IntUiLazyTreeColors( @Composable fun dark( - content: Color = IntUiDarkTheme.colors.grey(12), + content: Color = Color.Unspecified, contentFocused: Color = content, contentSelected: Color = content, contentSelectedFocused: Color = content, diff --git a/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiLinkStyling.kt b/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiLinkStyling.kt index 224077275..71387e83e 100644 --- a/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiLinkStyling.kt +++ b/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiLinkStyling.kt @@ -152,8 +152,8 @@ data class IntUiLinkTextStyles( @Composable fun light( - normal: TextStyle = IntUiTheme.defaultLightTextStyle.copy(textDecoration = TextDecoration.Underline), - disabled: TextStyle = IntUiTheme.defaultLightTextStyle, + normal: TextStyle = IntUiTheme.defaultTextStyle.copy(textDecoration = TextDecoration.Underline), + disabled: TextStyle = IntUiTheme.defaultTextStyle, focused: TextStyle = normal, pressed: TextStyle = normal, hovered: TextStyle = normal, @@ -162,8 +162,8 @@ data class IntUiLinkTextStyles( @Composable fun dark( - normal: TextStyle = IntUiTheme.defaultDarkTextStyle.copy(textDecoration = TextDecoration.Underline), - disabled: TextStyle = IntUiTheme.defaultDarkTextStyle, + normal: TextStyle = IntUiTheme.defaultTextStyle.copy(textDecoration = TextDecoration.Underline), + disabled: TextStyle = IntUiTheme.defaultTextStyle, focused: TextStyle = normal, pressed: TextStyle = normal, hovered: TextStyle = normal, diff --git a/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiRadioButtonStyling.kt b/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiRadioButtonStyling.kt index eb109a54b..97608c5f7 100644 --- a/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiRadioButtonStyling.kt +++ b/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiRadioButtonStyling.kt @@ -10,7 +10,6 @@ import org.jetbrains.jewel.RadioButtonState import org.jetbrains.jewel.SvgLoader import org.jetbrains.jewel.intui.core.theme.IntUiDarkTheme import org.jetbrains.jewel.intui.core.theme.IntUiLightTheme -import org.jetbrains.jewel.intui.standalone.IntUiTheme import org.jetbrains.jewel.styling.PainterProvider import org.jetbrains.jewel.styling.RadioButtonColors import org.jetbrains.jewel.styling.RadioButtonIcons @@ -59,12 +58,12 @@ data class IntUiRadioButtonColors( @Composable fun light( - content: Color = IntUiTheme.defaultLightTextStyle.color, - contentHovered: Color = IntUiLightTheme.colors.grey(8), - contentDisabled: Color = content, + content: Color = Color.Unspecified, + contentHovered: Color = content, + contentDisabled: Color = IntUiLightTheme.colors.grey(8), contentSelected: Color = content, contentSelectedHovered: Color = content, - contentSelectedDisabled: Color = content, + contentSelectedDisabled: Color = contentDisabled, ) = IntUiRadioButtonColors( content, contentHovered, @@ -76,12 +75,12 @@ data class IntUiRadioButtonColors( @Composable fun dark( - content: Color = IntUiTheme.defaultDarkTextStyle.color, - contentHovered: Color = IntUiDarkTheme.colors.grey(8), - contentDisabled: Color = content, + content: Color = Color.Unspecified, + contentHovered: Color = content, + contentDisabled: Color = IntUiDarkTheme.colors.grey(8), contentSelected: Color = content, contentSelectedHovered: Color = content, - contentSelectedDisabled: Color = content, + contentSelectedDisabled: Color = contentDisabled, ) = IntUiRadioButtonColors( content, contentHovered, diff --git a/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiTabStyling.kt b/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiTabStyling.kt index 67393d019..a3cd7dcc8 100644 --- a/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiTabStyling.kt +++ b/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiTabStyling.kt @@ -139,7 +139,7 @@ data class IntUiTabColors( backgroundPressed: Color = backgroundHovered, backgroundSelected: Color = background, backgroundDisabled: Color = background, - content: Color = IntUiDarkTheme.colors.grey(12), + content: Color = Color.Unspecified, contentHovered: Color = content, contentDisabled: Color = content, contentPressed: Color = content, @@ -182,7 +182,7 @@ data class IntUiTabColors( backgroundPressed: Color = background, backgroundSelected: Color = background, backgroundDisabled: Color = background, - content: Color = IntUiLightTheme.colors.grey(3), + content: Color = Color.Unspecified, contentHovered: Color = content, contentDisabled: Color = content, contentPressed: Color = content, @@ -223,7 +223,7 @@ data class IntUiTabColors( backgroundSelected: Color = background, backgroundDisabled: Color = background, - content: Color = IntUiDarkTheme.colors.grey(12), + content: Color = Color.Unspecified, contentHovered: Color = content, contentDisabled: Color = content, contentPressed: Color = content, diff --git a/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiTextAreaStyling.kt b/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiTextAreaStyling.kt index 030fde99a..ba09fea98 100644 --- a/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiTextAreaStyling.kt +++ b/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiTextAreaStyling.kt @@ -30,14 +30,14 @@ data class IntUiTextAreaStyle( fun light( colors: IntUiTextAreaColors = IntUiTextAreaColors.light(), metrics: IntUiTextAreaMetrics = IntUiTextAreaMetrics(), - textStyle: TextStyle = IntUiTheme.defaultLightTextStyle, + textStyle: TextStyle = IntUiTheme.defaultTextStyle, ) = IntUiTextAreaStyle(colors, metrics, textStyle) @Composable fun dark( colors: IntUiTextAreaColors = IntUiTextAreaColors.dark(), metrics: IntUiTextAreaMetrics = IntUiTextAreaMetrics(), - textStyle: TextStyle = IntUiTheme.defaultDarkTextStyle, + textStyle: TextStyle = IntUiTheme.defaultTextStyle, ) = IntUiTextAreaStyle(colors, metrics, textStyle) } } diff --git a/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiTextFieldStyling.kt b/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiTextFieldStyling.kt index c27349b67..f4e7c98d6 100644 --- a/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiTextFieldStyling.kt +++ b/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiTextFieldStyling.kt @@ -30,14 +30,14 @@ data class IntUiTextFieldStyle( fun light( colors: IntUiTextFieldColors = IntUiTextFieldColors.light(), metrics: IntUiTextFieldMetrics = IntUiTextFieldMetrics(), - textStyle: TextStyle = IntUiTheme.defaultLightTextStyle, + textStyle: TextStyle = IntUiTheme.defaultTextStyle, ) = IntUiTextFieldStyle(colors, metrics, textStyle) @Composable fun dark( colors: IntUiTextFieldColors = IntUiTextFieldColors.dark(), metrics: IntUiTextFieldMetrics = IntUiTextFieldMetrics(), - textStyle: TextStyle = IntUiTheme.defaultDarkTextStyle, + textStyle: TextStyle = IntUiTheme.defaultTextStyle, ) = IntUiTextFieldStyle(colors, metrics, textStyle) } } 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 new file mode 100644 index 000000000..f6c39468d --- /dev/null +++ b/int-ui/int-ui-standalone/src/main/kotlin/org/jetbrains/jewel/intui/standalone/styling/IntUiTooltipStyling.kt @@ -0,0 +1,78 @@ +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.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 +import org.jetbrains.jewel.styling.TooltipMetrics +import org.jetbrains.jewel.styling.TooltipStyle +import kotlin.time.Duration +import kotlin.time.Duration.Companion.milliseconds + +@Stable +data class IntUiTooltipStyle( + override val colors: IntUiTooltipColors, + override val metrics: IntUiTooltipMetrics, +) : TooltipStyle { + + companion object { + + @Composable + fun light( + intUiTooltipColors: IntUiTooltipColors = IntUiTooltipColors.light(), + intUiTooltipMetrics: IntUiTooltipMetrics = IntUiTooltipMetrics(), + ): IntUiTooltipStyle = IntUiTooltipStyle( + colors = intUiTooltipColors, + metrics = intUiTooltipMetrics, + ) + + @Composable + fun dark( + intUiTooltipColors: IntUiTooltipColors = IntUiTooltipColors.dark(), + intUiTooltipMetrics: IntUiTooltipMetrics = IntUiTooltipMetrics(), + ): IntUiTooltipStyle = IntUiTooltipStyle( + colors = intUiTooltipColors, + metrics = intUiTooltipMetrics, + ) + } +} + +@Stable +data class IntUiTooltipColors( + override val content: Color, + override val background: Color, + override val border: Color, +) : TooltipColors { + + companion object { + + @Composable + fun light( + contentColor: Color = IntUiLightTheme.colors.grey(12), + backgroundColor: Color = IntUiLightTheme.colors.grey(2), + borderColor: Color = IntelliJTheme.globalColors.borders.normal, + ) = IntUiTooltipColors(contentColor, backgroundColor, borderColor) + + @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) + } +} + +@Stable +data class IntUiTooltipMetrics( + override val contentPadding: PaddingValues = PaddingValues(vertical = 8.dp, horizontal = 8.dp), + override val showDelay: Duration = 0.milliseconds, + override val cornerSize: CornerSize = CornerSize(8.dp), + override val borderWidth: Dp = 1.dp, +) : TooltipMetrics diff --git a/samples/ide-plugin/src/main/kotlin/org/jetbrains/jewel/samples/ideplugin/JewelDemoToolWindow.kt b/samples/ide-plugin/src/main/kotlin/org/jetbrains/jewel/samples/ideplugin/JewelDemoToolWindow.kt index 9de08e045..51c795b76 100644 --- a/samples/ide-plugin/src/main/kotlin/org/jetbrains/jewel/samples/ideplugin/JewelDemoToolWindow.kt +++ b/samples/ide-plugin/src/main/kotlin/org/jetbrains/jewel/samples/ideplugin/JewelDemoToolWindow.kt @@ -43,6 +43,7 @@ import org.jetbrains.jewel.OutlinedButton import org.jetbrains.jewel.RadioButtonRow import org.jetbrains.jewel.Text import org.jetbrains.jewel.TextField +import org.jetbrains.jewel.Tooltip import org.jetbrains.jewel.bridge.SwingBridgeService import org.jetbrains.jewel.bridge.SwingBridgeTheme import org.jetbrains.jewel.bridge.addComposeTab @@ -149,6 +150,16 @@ internal class JewelDemoToolWindow : ToolWindowFactory, DumbAware { Text("Circular progress big: ") CircularProgressIndicatorBig(svgLoader) } + Row(verticalAlignment = Alignment.CenterVertically) { + Tooltip(tooltip = { + Text("This is a tooltip") + }) { + Text( + modifier = Modifier.border(1.dp, IntUiTheme.globalColors.borders.normal).padding(4.dp), + text = "Hover Me!", + ) + } + } } } diff --git a/samples/standalone/src/main/kotlin/org/jetbrains/jewel/samples/standalone/Main.kt b/samples/standalone/src/main/kotlin/org/jetbrains/jewel/samples/standalone/Main.kt index 478560363..59a886e4f 100644 --- a/samples/standalone/src/main/kotlin/org/jetbrains/jewel/samples/standalone/Main.kt +++ b/samples/standalone/src/main/kotlin/org/jetbrains/jewel/samples/standalone/Main.kt @@ -46,6 +46,7 @@ import org.jetbrains.jewel.samples.standalone.components.RadioButtons import org.jetbrains.jewel.samples.standalone.components.Tabs import org.jetbrains.jewel.samples.standalone.components.TextAreas import org.jetbrains.jewel.samples.standalone.components.TextFields +import org.jetbrains.jewel.samples.standalone.components.Tooltips import java.io.InputStream fun main() { @@ -103,6 +104,7 @@ private fun ComponentShowcase(svgLoader: JewelSvgLoader, resourceLoader: Resourc Checkboxes() RadioButtons() Links() + Tooltips() TextFields(svgLoader, resourceLoader) TextAreas() ProgressBar(svgLoader) diff --git a/samples/standalone/src/main/kotlin/org/jetbrains/jewel/samples/standalone/components/Tooltips.kt b/samples/standalone/src/main/kotlin/org/jetbrains/jewel/samples/standalone/components/Tooltips.kt new file mode 100644 index 000000000..0b3c38e06 --- /dev/null +++ b/samples/standalone/src/main/kotlin/org/jetbrains/jewel/samples/standalone/components/Tooltips.kt @@ -0,0 +1,21 @@ +package org.jetbrains.jewel.samples.standalone.components + +import androidx.compose.foundation.border +import androidx.compose.foundation.layout.padding +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp +import org.jetbrains.jewel.GroupHeader +import org.jetbrains.jewel.Text +import org.jetbrains.jewel.Tooltip +import org.jetbrains.jewel.intui.standalone.IntUiTheme + +@Composable +fun Tooltips() { + GroupHeader("Tooltips") + Tooltip(tooltip = { + Text("This is a tooltip") + }) { + Text(modifier = Modifier.border(1.dp, IntUiTheme.globalColors.borders.normal).padding(4.dp), text = "Hover Me!") + } +}