Skip to content

Commit

Permalink
Remove TextStyles from stylings (#490)
Browse files Browse the repository at this point in the history
* Remove textStyle from DropdownStyle

* Remove textStyle from InputFieldStyle and implementers

* Remove LinkTextStyles

* Update API definitions

* Address static analysis
  • Loading branch information
rock3r authored Jul 24, 2024
1 parent 3f24aca commit c5d1dd6
Show file tree
Hide file tree
Showing 15 changed files with 55 additions and 265 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,16 @@ internal class SwingBridgeService(scope: CoroutineScope) {
run {
val textStyle = TextStyle.Default.copy(fontSize = 13.sp)
val monospaceTextStyle = textStyle.copy(fontFamily = FontFamily.Monospace)
val themeDefinition = createBridgeThemeDefinition(textStyle, monospaceTextStyle, monospaceTextStyle)
val themeDefinition =
createBridgeThemeDefinition(
textStyle = textStyle,
editorTextStyle = monospaceTextStyle,
consoleTextStyle = monospaceTextStyle,
)

BridgeThemeData(
themeDefinition = themeDefinition,
componentStyling =
createBridgeComponentStyling(
theme = themeDefinition,
textFieldTextStyle = textStyle,
textAreaTextStyle = textStyle,
dropdownTextStyle = textStyle,
linkTextStyle = textStyle,
),
componentStyling = createBridgeComponentStyling(themeDefinition),
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ import org.jetbrains.jewel.ui.component.styling.LinkColors
import org.jetbrains.jewel.ui.component.styling.LinkIcons
import org.jetbrains.jewel.ui.component.styling.LinkMetrics
import org.jetbrains.jewel.ui.component.styling.LinkStyle
import org.jetbrains.jewel.ui.component.styling.LinkTextStyles
import org.jetbrains.jewel.ui.component.styling.MenuColors
import org.jetbrains.jewel.ui.component.styling.MenuIcons
import org.jetbrains.jewel.ui.component.styling.MenuItemColors
Expand Down Expand Up @@ -201,52 +200,37 @@ internal fun createBridgeThemeDefinition(
)
}

internal fun createBridgeComponentStyling(theme: ThemeDefinition) =
createBridgeComponentStyling(
theme = theme,
textFieldTextStyle = retrieveTextStyle("TextField.font", "TextField.foreground"),
textAreaTextStyle = retrieveTextStyle("TextArea.font", "TextArea.foreground"),
dropdownTextStyle = retrieveTextStyle("ComboBox.font"),
linkTextStyle = retrieveTextStyle("Label.font"),
)

internal fun createBridgeComponentStyling(
theme: ThemeDefinition,
textFieldTextStyle: TextStyle,
textAreaTextStyle: TextStyle,
dropdownTextStyle: TextStyle,
linkTextStyle: TextStyle,
): ComponentStyling {
internal fun createBridgeComponentStyling(theme: ThemeDefinition): ComponentStyling {
logger.debug("Obtaining Int UI component styling from Swing...")

val textFieldStyle = readTextFieldStyle(textFieldTextStyle)
val textFieldStyle = readTextFieldStyle()
val menuStyle = readMenuStyle()

return DefaultComponentStyling(
checkboxStyle = readCheckboxStyle(),
chipStyle = readChipStyle(),
circularProgressStyle = readCircularProgressStyle(theme.isDark),
defaultButtonStyle = readDefaultButtonStyle(),
defaultDropdownStyle = readDefaultDropdownStyle(menuStyle, dropdownTextStyle),
defaultDropdownStyle = readDefaultDropdownStyle(menuStyle),
defaultTabStyle = readDefaultTabStyle(),
dividerStyle = readDividerStyle(),
editorTabStyle = readEditorTabStyle(),
groupHeaderStyle = readGroupHeaderStyle(),
horizontalProgressBarStyle = readHorizontalProgressBarStyle(),
iconButtonStyle = readIconButtonStyle(),
lazyTreeStyle = readLazyTreeStyle(),
linkStyle = readLinkStyle(linkTextStyle),
linkStyle = readLinkStyle(),
menuStyle = menuStyle,
outlinedButtonStyle = readOutlinedButtonStyle(),
radioButtonStyle = readRadioButtonStyle(),
scrollbarStyle = readScrollbarStyle(theme.isDark),
segmentedControlButtonStyle = readSegmentedControlButtonStyle(),
segmentedControlStyle = readSegmentedControlStyle(),
sliderStyle = readSliderStyle(theme.isDark),
textAreaStyle = readTextAreaStyle(textAreaTextStyle, textFieldStyle.metrics),
textAreaStyle = readTextAreaStyle(textFieldStyle.metrics),
textFieldStyle = textFieldStyle,
tooltipStyle = readTooltipStyle(),
undecoratedDropdownStyle = readUndecoratedDropdownStyle(menuStyle, dropdownTextStyle),
undecoratedDropdownStyle = readUndecoratedDropdownStyle(menuStyle),
)
}

Expand Down Expand Up @@ -503,10 +487,7 @@ private fun readDividerStyle() =
metrics = DividerMetrics.defaults(),
)

private fun readDefaultDropdownStyle(
menuStyle: MenuStyle,
dropdownTextStyle: TextStyle,
): DropdownStyle {
private fun readDefaultDropdownStyle(menuStyle: MenuStyle): DropdownStyle {
val normalBackground = retrieveColorOrUnspecified("ComboBox.nonEditableBackground")
val normalContent = retrieveColorOrUnspecified("ComboBox.foreground")
val normalBorder = retrieveColorOrUnspecified("Component.borderColor")
Expand Down Expand Up @@ -549,15 +530,11 @@ private fun readDefaultDropdownStyle(
borderWidth = DarculaUIUtil.LW.dp,
),
icons = DropdownIcons(chevronDown = AllIconsKeys.General.ChevronDown),
textStyle = dropdownTextStyle,
menuStyle = menuStyle,
)
}

private fun readUndecoratedDropdownStyle(
menuStyle: MenuStyle,
dropdownTextStyle: TextStyle,
): DropdownStyle {
private fun readUndecoratedDropdownStyle(menuStyle: MenuStyle): DropdownStyle {
val normalBackground = retrieveColorOrUnspecified("ComboBox.nonEditableBackground")
val hoverBackground = retrieveColorOrUnspecified("MainToolbar.Dropdown.transparentHoverBackground")
val normalContent = retrieveColorOrUnspecified("ComboBox.foreground")
Expand Down Expand Up @@ -600,7 +577,6 @@ private fun readUndecoratedDropdownStyle(
borderWidth = 0.dp,
),
icons = DropdownIcons(chevronDown = AllIconsKeys.General.ChevronDown),
textStyle = dropdownTextStyle,
menuStyle = menuStyle,
)
}
Expand Down Expand Up @@ -636,7 +612,7 @@ private fun readHorizontalProgressBarStyle() =
indeterminateCycleDuration = 800.milliseconds, // See DarculaProgressBarUI.CYCLE_TIME_DEFAULT
)

private fun readLinkStyle(linkTextStyle: TextStyle): LinkStyle {
private fun readLinkStyle(): LinkStyle {
val normalContent =
retrieveColorOrUnspecified("Link.activeForeground")
.takeOrElse { retrieveColorOrUnspecified("Link.activeForeground") }
Expand Down Expand Up @@ -676,15 +652,6 @@ private fun readLinkStyle(linkTextStyle: TextStyle): LinkStyle {
dropdownChevron = AllIconsKeys.General.ChevronDown,
externalLink = AllIconsKeys.Ide.External_link_arrow,
),
textStyles =
LinkTextStyles(
normal = linkTextStyle,
disabled = linkTextStyle,
focused = linkTextStyle,
pressed = linkTextStyle,
hovered = linkTextStyle,
visited = linkTextStyle,
),
)
}

Expand Down Expand Up @@ -943,10 +910,7 @@ private fun readSliderStyle(dark: Boolean): SliderStyle {
return SliderStyle(colors, SliderMetrics.defaults(), CircleShape)
}

private fun readTextAreaStyle(
textStyle: TextStyle,
metrics: TextFieldMetrics,
): TextAreaStyle {
private fun readTextAreaStyle(metrics: TextFieldMetrics): TextAreaStyle {
val normalBackground = retrieveColorOrUnspecified("TextArea.background")
val normalContent = retrieveColorOrUnspecified("TextArea.foreground")
val normalBorder = DarculaUIUtil.getOutlineColor(true, false).toComposeColor()
Expand Down Expand Up @@ -987,11 +951,10 @@ private fun readTextAreaStyle(
minSize = metrics.minSize,
borderWidth = metrics.borderWidth,
),
textStyle = textStyle,
)
}

private fun readTextFieldStyle(textFieldStyle: TextStyle): TextFieldStyle {
private fun readTextFieldStyle(): TextFieldStyle {
val normalBackground = retrieveColorOrUnspecified("TextField.background")
val normalContent = retrieveColorOrUnspecified("TextField.foreground")
val normalBorder = DarculaUIUtil.getOutlineColor(true, false).toComposeColor()
Expand Down Expand Up @@ -1033,7 +996,6 @@ private fun readTextFieldStyle(textFieldStyle: TextStyle): TextFieldStyle {
minSize = DpSize(minimumSize.width, minimumSize.height),
borderWidth = DarculaUIUtil.LW.dp,
),
textStyle = textFieldStyle,
)
}

Expand Down
Loading

0 comments on commit c5d1dd6

Please sign in to comment.