Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a line-height of 1.3x for the default text styles #587

Merged
merged 2 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ide-laf-bridge/api/ide-laf-bridge.api
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ public final class org/jetbrains/jewel/bridge/BridgeUtilsKt {
public static final fun retrieveIntAsDp-3F_vd3o (Ljava/lang/String;Landroidx/compose/ui/unit/Dp;)F
public static synthetic fun retrieveIntAsDp-3F_vd3o$default (Ljava/lang/String;Landroidx/compose/ui/unit/Dp;ILjava/lang/Object;)F
public static final fun retrieveIntAsDpOrUnspecified (Ljava/lang/String;)F
public static final fun retrieveTextStyle (Ljava/lang/String;Ljava/lang/String;)Landroidx/compose/ui/text/TextStyle;
public static synthetic fun retrieveTextStyle$default (Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Landroidx/compose/ui/text/TextStyle;
public static final fun retrieveTextStyle-WdJyH8Q (Ljava/lang/String;JJZIJ)Landroidx/compose/ui/text/TextStyle;
public static synthetic fun retrieveTextStyle-WdJyH8Q$default (Ljava/lang/String;JJZIJILjava/lang/Object;)Landroidx/compose/ui/text/TextStyle;
public static final fun retrieveTextStyle-tD9LlGs (Ljava/lang/String;Ljava/lang/String;JZIJ)Landroidx/compose/ui/text/TextStyle;
public static synthetic fun retrieveTextStyle-tD9LlGs$default (Ljava/lang/String;Ljava/lang/String;JZIJILjava/lang/Object;)Landroidx/compose/ui/text/TextStyle;
public static final fun toComposeColor (Ljava/awt/Color;)J
public static final fun toComposeColorOrUnspecified (Ljava/awt/Color;)J
public static final fun toDpSize (Lcom/intellij/util/ui/JBDimension;)J
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,17 @@ public fun retrieveArcAsCornerSizeWithFallbacks(vararg keys: String): CornerSize
keysNotFound(keys.toList(), "Int")
}

public fun retrieveTextStyle(fontKey: String, colorKey: String? = null): TextStyle {
public fun retrieveTextStyle(
fontKey: String,
colorKey: String? = null,
lineHeight: TextUnit = TextUnit.Unspecified,
bold: Boolean = false,
fontStyle: FontStyle = FontStyle.Normal,
size: TextUnit = TextUnit.Unspecified,
): TextStyle {
val baseColor = colorKey?.let { retrieveColorOrUnspecified(colorKey) } ?: Color.Unspecified
return retrieveTextStyle(fontKey, color = baseColor)
val resolvedStyle = retrieveTextStyle(fontKey, color = baseColor, lineHeight, bold, fontStyle, size)
return resolvedStyle.copy(lineHeight = resolvedStyle.fontSize * 1.3)
rock3r marked this conversation as resolved.
Show resolved Hide resolved
}

@OptIn(ExperimentalTextApi::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import org.jetbrains.jewel.bridge.theme.createBridgeComponentStyling
import org.jetbrains.jewel.bridge.theme.createBridgeThemeDefinition
import org.jetbrains.jewel.foundation.theme.ThemeDefinition
import org.jetbrains.jewel.ui.ComponentStyling
import org.jetbrains.jewel.ui.component.copyWithSize

@Service(Level.APP)
internal class SwingBridgeService(scope: CoroutineScope) {
Expand Down Expand Up @@ -55,7 +56,7 @@ internal class SwingBridgeService(scope: CoroutineScope) {
internal data class BridgeThemeData(val themeDefinition: ThemeDefinition, val componentStyling: ComponentStyling) {
companion object {
val DEFAULT = run {
val textStyle = TextStyle.Default.copy(fontSize = 13.sp)
val textStyle = TextStyle.Default.copyWithSize(fontSize = 13.sp)
val monospaceTextStyle = textStyle.copy(fontFamily = FontFamily.Monospace)
val themeDefinition =
createBridgeThemeDefinition(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.intellij.openapi.util.SystemInfo
import com.intellij.ui.NewUiValue
import org.jetbrains.jewel.foundation.theme.JewelTheme
import org.jetbrains.jewel.ui.component.Typography
import org.jetbrains.jewel.ui.component.copyWithSize
import org.jetbrains.jewel.ui.component.minus

/**
Expand All @@ -29,7 +30,7 @@ public fun Typography.medium(): TextStyle =
if (mediumAndSmallFontsAsRegular()) {
labelTextStyle()
} else {
labelTextStyle().copy(fontSize = labelTextSize() - 1.sp)
labelTextStyle().copyWithSize(fontSize = labelTextSize() - 1.sp)
}

/**
Expand All @@ -46,7 +47,7 @@ public fun Typography.small(): TextStyle =
if (mediumAndSmallFontsAsRegular()) {
labelTextStyle()
} else {
labelTextStyle().copy(fontSize = labelTextSize() - 2.sp)
labelTextStyle().copyWithSize(fontSize = labelTextSize() - 2.sp)
}

// Copied from JBFont — current as of IJP 233.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import androidx.compose.ui.unit.sp
import org.jetbrains.jewel.foundation.theme.JewelTheme
import org.jetbrains.jewel.intui.standalone.Inter
import org.jetbrains.jewel.intui.standalone.JetBrainsMono
import org.jetbrains.jewel.ui.component.Typography

public fun JewelTheme.Companion.createDefaultTextStyle(
color: Color = Color.Unspecified,
Expand All @@ -45,7 +46,7 @@ public fun JewelTheme.Companion.createDefaultTextStyle(
drawStyle: DrawStyle? = null,
textAlign: TextAlign = TextAlign.Unspecified,
textDirection: TextDirection = TextDirection.Unspecified,
lineHeight: TextUnit = TextUnit.Unspecified,
lineHeight: TextUnit = fontSize * Typography.DefaultLineHeightMultiplier,
textIndent: TextIndent? = null,
platformStyle: PlatformTextStyle? = null,
lineHeightStyle: LineHeightStyle? = null,
Expand Down Expand Up @@ -99,7 +100,7 @@ public fun JewelTheme.Companion.createDefaultTextStyle(
drawStyle: DrawStyle? = null,
textAlign: TextAlign = TextAlign.Unspecified,
textDirection: TextDirection = TextDirection.Unspecified,
lineHeight: TextUnit = TextUnit.Unspecified,
lineHeight: TextUnit = fontSize * Typography.DefaultLineHeightMultiplier,
textIndent: TextIndent? = null,
platformStyle: PlatformTextStyle? = null,
lineHeightStyle: LineHeightStyle? = null,
Expand Down Expand Up @@ -153,7 +154,7 @@ public fun JewelTheme.Companion.createEditorTextStyle(
drawStyle: DrawStyle? = null,
textAlign: TextAlign = TextAlign.Unspecified,
textDirection: TextDirection = TextDirection.Unspecified,
lineHeight: TextUnit = TextUnit.Unspecified,
lineHeight: TextUnit = fontSize * Typography.EditorLineHeightMultiplier,
textIndent: TextIndent? = null,
platformStyle: PlatformTextStyle? = null,
lineHeightStyle: LineHeightStyle? = null,
Expand Down Expand Up @@ -207,7 +208,7 @@ public fun JewelTheme.Companion.createEditorTextStyle(
drawStyle: DrawStyle? = null,
textAlign: TextAlign = TextAlign.Unspecified,
textDirection: TextDirection = TextDirection.Unspecified,
lineHeight: TextUnit = TextUnit.Unspecified,
lineHeight: TextUnit = fontSize * Typography.EditorLineHeightMultiplier,
textIndent: TextIndent? = null,
platformStyle: PlatformTextStyle? = null,
lineHeightStyle: LineHeightStyle? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package org.jetbrains.jewel.samples.ideplugin

import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.calculateEndPadding
import androidx.compose.foundation.layout.calculateStartPadding
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.text.input.rememberTextFieldState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
Expand Down Expand Up @@ -103,6 +105,49 @@ internal class SwingComparisonTabPanel : BorderLayoutPanel() {
}
}
.layout(RowLayout.PARENT_GRID)

val longText = "WordWrapInsideWordsIsSupported:" + ("NoSpace".repeat(20) + " ").repeat(5) + "End"
row("Long text (Swing)") { text(longText, maxLineLength = 100) }
row("Long text (Compose)") {
compose {
BoxWithConstraints {
Text(
longText,
modifier =
Modifier.width(
with(LocalDensity.current) {
// Guesstimate how wide this should be — we can't tell it to be
// "fill", as it crashes natively
JewelTheme.defaultTextStyle.fontSize.toDp() * 60
}
),
)
}
}
}

row("Titles (Swing)") {
text("This will wrap over a couple rows", maxLineLength = 30).component.font = JBFont.h1()
}
row("Titles (Compose)") {
compose {
BoxWithConstraints {
val style = Typography.h1TextStyle()
Text(
"This will wrap over a couple rows",
modifier =
Modifier.width(
with(LocalDensity.current) {
// Guesstimate how wide this should be — we can't tell it to be
// "fill", as it crashes natively
style.fontSize.toDp() * 10
}
),
style = style,
)
}
}
}
}

private fun Panel.iconsRow() {
Expand Down
6 changes: 6 additions & 0 deletions ui/api/ui.api
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,8 @@ public final class org/jetbrains/jewel/ui/component/TooltipKt {

public final class org/jetbrains/jewel/ui/component/Typography {
public static final field $stable I
public static final field DefaultLineHeightMultiplier F
public static final field EditorLineHeightMultiplier F
public static final field INSTANCE Lorg/jetbrains/jewel/ui/component/Typography;
public final fun consoleTextStyle (Landroidx/compose/runtime/Composer;I)Landroidx/compose/ui/text/TextStyle;
public final fun editorTextStyle (Landroidx/compose/runtime/Composer;I)Landroidx/compose/ui/text/TextStyle;
Expand All @@ -965,6 +967,10 @@ public final class org/jetbrains/jewel/ui/component/Typography {
}

public final class org/jetbrains/jewel/ui/component/TypographyKt {
public static final fun copyWithSize-Ce1Lr_4 (Landroidx/compose/ui/text/TextStyle;JJLandroidx/compose/ui/text/font/FontWeight;Landroidx/compose/ui/text/font/FontStyle;Landroidx/compose/ui/text/font/FontSynthesis;Landroidx/compose/ui/text/font/FontFamily;Ljava/lang/String;JLandroidx/compose/ui/text/style/BaselineShift;Landroidx/compose/ui/text/style/TextGeometricTransform;Landroidx/compose/ui/text/intl/LocaleList;JLandroidx/compose/ui/text/style/TextDecoration;Landroidx/compose/ui/graphics/Shadow;Landroidx/compose/ui/graphics/drawscope/DrawStyle;IILandroidx/compose/ui/text/style/TextIndent;Landroidx/compose/ui/text/PlatformTextStyle;Landroidx/compose/ui/text/style/LineHeightStyle;IILandroidx/compose/ui/text/style/TextMotion;)Landroidx/compose/ui/text/TextStyle;
public static synthetic fun copyWithSize-Ce1Lr_4$default (Landroidx/compose/ui/text/TextStyle;JJLandroidx/compose/ui/text/font/FontWeight;Landroidx/compose/ui/text/font/FontStyle;Landroidx/compose/ui/text/font/FontSynthesis;Landroidx/compose/ui/text/font/FontFamily;Ljava/lang/String;JLandroidx/compose/ui/text/style/BaselineShift;Landroidx/compose/ui/text/style/TextGeometricTransform;Landroidx/compose/ui/text/intl/LocaleList;JLandroidx/compose/ui/text/style/TextDecoration;Landroidx/compose/ui/graphics/Shadow;Landroidx/compose/ui/graphics/drawscope/DrawStyle;IILandroidx/compose/ui/text/style/TextIndent;Landroidx/compose/ui/text/PlatformTextStyle;Landroidx/compose/ui/text/style/LineHeightStyle;IILandroidx/compose/ui/text/style/TextMotion;ILjava/lang/Object;)Landroidx/compose/ui/text/TextStyle;
public static final fun copyWithSize-nfnV_I0 (Landroidx/compose/ui/text/TextStyle;JLandroidx/compose/ui/graphics/Brush;FLandroidx/compose/ui/text/font/FontWeight;Landroidx/compose/ui/text/font/FontStyle;Landroidx/compose/ui/text/font/FontSynthesis;Landroidx/compose/ui/text/font/FontFamily;Ljava/lang/String;JLandroidx/compose/ui/text/style/BaselineShift;Landroidx/compose/ui/text/style/TextGeometricTransform;Landroidx/compose/ui/text/intl/LocaleList;JLandroidx/compose/ui/text/style/TextDecoration;Landroidx/compose/ui/graphics/Shadow;Landroidx/compose/ui/graphics/drawscope/DrawStyle;IILandroidx/compose/ui/text/style/TextIndent;Landroidx/compose/ui/text/PlatformTextStyle;Landroidx/compose/ui/text/style/LineHeightStyle;IILandroidx/compose/ui/text/style/TextMotion;)Landroidx/compose/ui/text/TextStyle;
public static synthetic fun copyWithSize-nfnV_I0$default (Landroidx/compose/ui/text/TextStyle;JLandroidx/compose/ui/graphics/Brush;FLandroidx/compose/ui/text/font/FontWeight;Landroidx/compose/ui/text/font/FontStyle;Landroidx/compose/ui/text/font/FontSynthesis;Landroidx/compose/ui/text/font/FontFamily;Ljava/lang/String;JLandroidx/compose/ui/text/style/BaselineShift;Landroidx/compose/ui/text/style/TextGeometricTransform;Landroidx/compose/ui/text/intl/LocaleList;JLandroidx/compose/ui/text/style/TextDecoration;Landroidx/compose/ui/graphics/Shadow;Landroidx/compose/ui/graphics/drawscope/DrawStyle;IILandroidx/compose/ui/text/style/TextIndent;Landroidx/compose/ui/text/PlatformTextStyle;Landroidx/compose/ui/text/style/LineHeightStyle;IILandroidx/compose/ui/text/style/TextMotion;ILjava/lang/Object;)Landroidx/compose/ui/text/TextStyle;
public static final fun minus-NB67dxo (JJ)J
public static final fun plus-NB67dxo (JJ)J
}
Expand Down
Loading