Skip to content

Commit

Permalink
Add ListComboBox (#627)
Browse files Browse the repository at this point in the history
* integrate ComboBox in Standalone

Signed-off-by: Ivan Morgillo <[email protected]>

* add ComboBoxes to SwingComparisonTabPanel

Signed-off-by: Ivan Morgillo <[email protected]>

* fix text color in ComboBox

Signed-off-by: Ivan Morgillo <[email protected]>

* add a bit of space below combobox in IDE example

Signed-off-by: Ivan Morgillo <[email protected]>

* tune ComboBox popup padding

Signed-off-by: Ivan Morgillo <[email protected]>

* fix ComboBox field background color

Signed-off-by: Ivan Morgillo <[email protected]>

* extract textStyle in ComboBox

Signed-off-by: Ivan Morgillo <[email protected]>

* update API files

Signed-off-by: Ivan Morgillo <[email protected]>

* make the formatter happy

Signed-off-by: Ivan Morgillo <[email protected]>

* fix ComboBox border

Signed-off-by: Ivan Morgillo <[email protected]>

* tune ComboBox focus

Signed-off-by: Ivan Morgillo <[email protected]>

* Revert "tune ComboBox focus"

This reverts commit f336503.

* iterate on focus

Signed-off-by: Ivan Morgillo <[email protected]>

* reformat

Signed-off-by: Ivan Morgillo <[email protected]>

* remove cursorBrush style

Signed-off-by: Ivan Morgillo <[email protected]>

* add isEditable flag to ComboBox

Signed-off-by: Ivan Morgillo <[email protected]>

* make the formatter happy

* tune ComboBox menu horizontal padding

Signed-off-by: Ivan Morgillo <[email protected]>

* remove offset from Standalone style

Signed-off-by: Ivan Morgillo <[email protected]>

* fix a couple of paddings in the menu

Signed-off-by: Ivan Morgillo <[email protected]>

* make linter and formatter happy

Signed-off-by: Ivan Morgillo <[email protected]>

* make the formatter happy

* add not-editable ComboBox to Standalone

Signed-off-by: Ivan Morgillo <[email protected]>

* fix focus on not-editable ComboBox

Signed-off-by: Ivan Morgillo <[email protected]>

* rearrange ComboBox params to make ktlint happy

Signed-off-by: Ivan Morgillo <[email protected]>

* update API files

Signed-off-by: Ivan Morgillo <[email protected]>

* fix single line on not-editable ComboBox

reference: #601 (review)
Signed-off-by: Ivan Morgillo <[email protected]>

* prevent the ComboBox from expanding

reference: #601 (review)
Signed-off-by: Ivan Morgillo <[email protected]>

* iterate on colors

reference: #601 (comment)
Signed-off-by: Ivan Morgillo <[email protected]>

* address a couple of feedbacks

reference: #601 (comment)
Signed-off-by: Ivan Morgillo <[email protected]>

* iterate on focus management on ComboBox

Signed-off-by: Ivan Morgillo <[email protected]>

* reformat and update API files

Signed-off-by: Ivan Morgillo <[email protected]>

* fix focus on click for not-editable ComboBox

Signed-off-by: Ivan Morgillo <[email protected]>

* inline a few variables to reduce clutter

Signed-off-by: Ivan Morgillo <[email protected]>

* add different states for different ComboBoxes

Signed-off-by: Ivan Morgillo <[email protected]>

* reformat things

Signed-off-by: Ivan Morgillo <[email protected]>

* introduce ComboBoxStyle

Signed-off-by: Ivan Morgillo <[email protected]>

* restore DropdownStyle

Signed-off-by: Ivan Morgillo <[email protected]>

* split ComboBoxes states in Standalone sample

Signed-off-by: Ivan Morgillo <[email protected]>

* tune old DropDown style for IDE

Signed-off-by: Ivan Morgillo <[email protected]>

* tune ComboBox focus once more

Signed-off-by: Ivan Morgillo <[email protected]>

* update API files

Signed-off-by: Ivan Morgillo <[email protected]>

* fix ComboBox popup expand

Signed-off-by: Ivan Morgillo <[email protected]>

* remove focused padding for ComboBox divider

It's not happening in the IDE sample

Signed-off-by: Ivan Morgillo <[email protected]>

* iterate on ComboBox focus

Signed-off-by: Ivan Morgillo <[email protected]>

* iterate on ComboBox focus

Signed-off-by: Ivan Morgillo <[email protected]>

* add ui-tests module

Signed-off-by: Ivan Morgillo <[email protected]>

* start adding tests to ComboBox

Signed-off-by: Ivan Morgillo <[email protected]>

* add more tests for ComboBox

Signed-off-by: Ivan Morgillo <[email protected]>

* massive WIP commit because I'm getting paranoid

I know there is IntelliJ local history. Give me a break!

Signed-off-by: Ivan Morgillo <[email protected]>

* clean up and initial restoration of ComboBox features

Signed-off-by: Ivan Morgillo <[email protected]>

* rework ComboBox

Signed-off-by: Ivan Morgillo <[email protected]>

* add enabled/disabled chevron click tests

Signed-off-by: Ivan Morgillo <[email protected]>

* add click management to chevron

Signed-off-by: Ivan Morgillo <[email protected]>

* fix popup open/close when not-editable

Signed-off-by: Ivan Morgillo <[email protected]>

* add another batch of tests for ComboBox

Signed-off-by: Ivan Morgillo <[email protected]>

* add maxPopupHeight to ComboBox

Signed-off-by: Ivan Morgillo <[email protected]>

* add onPopupStateChange

Signed-off-by: Ivan Morgillo <[email protected]>

* extract NotEditableComboBox

Signed-off-by: Ivan Morgillo <[email protected]>

* iterate on ListComboBox item selection

Signed-off-by: Ivan Morgillo <[email protected]>

* improve TAB navigation on NotEditableComboBox

Signed-off-by: Ivan Morgillo <[email protected]>

* update IDE plugin example

Signed-off-by: Ivan Morgillo <[email protected]>

* reformat SwingComparisonTabPanel

Signed-off-by: Ivan Morgillo <[email protected]>

* iterate on ListComboBox scroll

Signed-off-by: Ivan Morgillo <[email protected]>

* remove debug border

Signed-off-by: Ivan Morgillo <[email protected]>

* reuse PointerInputScope.detectPressAndCancel

Signed-off-by: Ivan Morgillo <[email protected]>

* extract PopupContainerStyle

Signed-off-by: Ivan Morgillo <[email protected]>

* iterate on IntUiBridge.SimpleListItemStyle

Signed-off-by: Ivan Morgillo <[email protected]>

* update API files

Signed-off-by: Ivan Morgillo <[email protected]>

* ensure 100% tests are passing

Signed-off-by: Ivan Morgillo <[email protected]>

* move ListComboBox item selection with hover

Signed-off-by: Ivan Morgillo <[email protected]>

* iterate on hover and selection for SimpleListItem

Signed-off-by: Ivan Morgillo <[email protected]>

* have Esc to close an open popup

Signed-off-by: Ivan Morgillo <[email protected]>

* iterate on ListComboBox height

Signed-off-by: Ivan Morgillo <[email protected]>

* fix SimpleListItemColors.dark background color

Signed-off-by: Ivan Morgillo <[email protected]>

* iterate on Enter key press

Signed-off-by: Ivan Morgillo <[email protected]>

* close popup on click

Signed-off-by: Ivan Morgillo <[email protected]>

* fix *ComboBox arrow and arrow area size

Signed-off-by: Ivan Morgillo <[email protected]>

* remove unnecessary box

Signed-off-by: Ivan Morgillo <[email protected]>

* Update ktlint plugin config to also support 0.25 beta

They changed the config and didn't implement a migration of the old
config to the new config 🤦

* Cleanup code and refactor

Stuff is still broken, maybe more than before :P

* Remove duplicated focused handling

* Rename flag in ComboBox

* Remove Text from EditableComboBox

* Fix KotlinC woes

* Fix chevron alignment in EditableComboBox

* restore basic onHover behavior for ListComboBox

Signed-off-by: Ivan Morgillo <[email protected]>

* fix missing plugin in :ui-tests

Signed-off-by: Ivan Morgillo <[email protected]>

* Fix missing ⬇️ event on editable ComboBox (#635)

* rename a bunch of lambdas to make the linter happy

Signed-off-by: Ivan Morgillo <[email protected]>

* Fix #632

Signed-off-by: Ivan Morgillo <[email protected]>

* stitch broken tests

Signed-off-by: Ivan Morgillo <[email protected]>

* update API files

Signed-off-by: Ivan Morgillo <[email protected]>

* stitch IDE sample

Signed-off-by: Ivan Morgillo <[email protected]>

* make the formatter happy

* renamed a bunch of lambdas and shushed the linter

Signed-off-by: Ivan Morgillo <[email protected]>

* format EditableComboBox

* improve test for disabled ComboBox

Signed-off-by: Ivan Morgillo <[email protected]>

---------

Signed-off-by: Ivan Morgillo <[email protected]>
Co-authored-by: morgillo <[email protected]>

* Remove rounderd corner from SimpleListItemStyle in bridge (#651)

* remove rounded corner from IntUiBridge SimpleListItemMetrics

Signed-off-by: Ivan Morgillo <[email protected]>

* make the formatter happy

---------

Signed-off-by: Ivan Morgillo <[email protected]>

* Iterate on ListComboBox and SimpleListItem metrics (#658)

* tune the SimpleListItemStyle

Signed-off-by: Ivan Morgillo <[email protected]>

* update API files and format

Signed-off-by: Ivan Morgillo <[email protected]>

* stitch ListComboBox

Signed-off-by: Ivan Morgillo <[email protected]>

* update API files

Signed-off-by: Ivan Morgillo <[email protected]>

* iterate on the SwingComparisonTabPanel ComboBox example

Signed-off-by: Ivan Morgillo <[email protected]>

* iterate on *ComboBox colors

Signed-off-by: Ivan Morgillo <[email protected]>

* update API files

Signed-off-by: Ivan Morgillo <[email protected]>

* iterate on *ComboBox colors and chevron positioning

Signed-off-by: Ivan Morgillo <[email protected]>

---------

Signed-off-by: Ivan Morgillo <[email protected]>

* fix warning in ListComboBox

Signed-off-by: Ivan Morgillo <[email protected]>

* stitch IntUiBridge

Signed-off-by: Ivan Morgillo <[email protected]>

* Fix ListComboBox hover (#659)

* massive WIP commit because I'm getting paranoid

I know there is IntelliJ local history. Give me a break!

Signed-off-by: Ivan Morgillo <[email protected]>

* update IDE plugin example

Signed-off-by: Ivan Morgillo <[email protected]>

* improve hover management for ListComboBox

Signed-off-by: Ivan Morgillo <[email protected]>

* iterate on ListComboBox item selection on hover

Signed-off-by: Ivan Morgillo <[email protected]>

* fix missing click event on ComboBox.PopupContainer

Signed-off-by: Ivan Morgillo <[email protected]>

* refactor ListComboBox.hoverItemIndex

Signed-off-by: Ivan Morgillo <[email protected]>

* make the formatter happy

Signed-off-by: Ivan Morgillo <[email protected]>

* update API files

Signed-off-by: Ivan Morgillo <[email protected]>

* stitch ComboBoxStyling

Signed-off-by: Ivan Morgillo <[email protected]>

* iterate on ListComboBox item selection on hover

Signed-off-by: Ivan Morgillo <[email protected]>

* update API files

Signed-off-by: Ivan Morgillo <[email protected]>

* make ListComboBox.hoverItemIndex nullable

Signed-off-by: Ivan Morgillo <[email protected]>

* remove redundant variable ListComboBox.lastHoveredIndex

Signed-off-by: Ivan Morgillo <[email protected]>

* remove redundant variable ListComboBox.previewSelection

Signed-off-by: Ivan Morgillo <[email protected]>

* make the formatter happy

---------

Signed-off-by: Ivan Morgillo <[email protected]>
Co-authored-by: morgillo <[email protected]>

* Split IntUiBridge into separate files according to components (#670)

* extract IntUiBridgeCheckbox

Signed-off-by: morgillo <[email protected]>

* extract IntUiBridgeRadioButton

Signed-off-by: morgillo <[email protected]>

* extract IntUiBridgeCircularProgress

Signed-off-by: morgillo <[email protected]>

* extract IntUiBridgeButton

Signed-off-by: morgillo <[email protected]>

* extract IntUiBridgeChip

Signed-off-by: morgillo <[email protected]>

* extract IntUiBridgeComboBox

Signed-off-by: morgillo <[email protected]>

* extract IntUiBridgeDropDown

Signed-off-by: morgillo <[email protected]>

* extract IntUiBridgeSimpleListItem

Signed-off-by: morgillo <[email protected]>

* iterate on IntUiBridgeProgress

Signed-off-by: morgillo <[email protected]>

* iterate on IntUiBridgeLink

Signed-off-by: morgillo <[email protected]>

* iterate on IntUiBridgeMenu

Signed-off-by: morgillo <[email protected]>

* iterate on IntUiBridgePopupContainer

Signed-off-by: morgillo <[email protected]>

* iterate on IntUiBridgeSegmentedControl

Signed-off-by: morgillo <[email protected]>

* iterate on IntUiBridgeSlider

Signed-off-by: morgillo <[email protected]>

* iterate on IntUiBridgeTextArea

Signed-off-by: morgillo <[email protected]>

* iterate on IntUiBridgeTextField

Signed-off-by: morgillo <[email protected]>

* iterate on IntUiBridgeLazyTree

Signed-off-by: morgillo <[email protected]>

* iterate on IntUiBridgeTab

Signed-off-by: morgillo <[email protected]>

* iterate on IntUiBridgeButton

Signed-off-by: morgillo <[email protected]>

* extract on IntUiBridgeTooltip

Signed-off-by: morgillo <[email protected]>

* extract on IntUiBridgeGroupHeader

Signed-off-by: morgillo <[email protected]>

* extract on IntUiBridgeSelectableLazyColumn

Signed-off-by: morgillo <[email protected]>

* extract on IntUiBridgeDivider

Signed-off-by: morgillo <[email protected]>

* extract on IntUiBridgeText

Signed-off-by: morgillo <[email protected]>

* reformat all the IntUiBridge* files

Signed-off-by: morgillo <[email protected]>

---------

Signed-off-by: morgillo <[email protected]>
Co-authored-by: morgillo <[email protected]>

* Reduce duplication in ListComboBox (#669)

* extract ListComboBox.onSelectedIndexesChange()

Signed-off-by: morgillo <[email protected]>

* extract common parts in ListComboBox

Signed-off-by: morgillo <[email protected]>

* reformat ListComboBox

Signed-off-by: morgillo <[email protected]>

* refactor ListComboBox.contentItems

reference #669 (comment)

Signed-off-by: Ivan Morgillo <[email protected]>

* extract ComboBoxMetrics.popupContentPadding

reference #669 (comment)

Signed-off-by: Ivan Morgillo <[email protected]>

* make formatter happy

* rebase ListComboBox

Signed-off-by: Ivan Morgillo <[email protected]>

---------

Signed-off-by: morgillo <[email protected]>
Signed-off-by: Ivan Morgillo <[email protected]>
Co-authored-by: morgillo <[email protected]>

* In ListComboBox prevents caret from moving on key up/down pressed (#692)

* prevent caret moving on key up/down pressed

Signed-off-by: Ivan Morgillo <[email protected]>

* simplify when in EditableComboBox

reference #692 (comment)

Signed-off-by: Ivan Morgillo <[email protected]>

* properly notify event processing in EditableComboBox

reference #692 (comment)

Signed-off-by: Ivan Morgillo <[email protected]>

---------

Signed-off-by: Ivan Morgillo <[email protected]>

---------

Signed-off-by: Ivan Morgillo <[email protected]>
Signed-off-by: morgillo <[email protected]>
Co-authored-by: morgillo <[email protected]>
Co-authored-by: Sebastiano Poggi <[email protected]>
  • Loading branch information
3 people authored Nov 19, 2024
1 parent 547e4c2 commit f5dae48
Show file tree
Hide file tree
Showing 59 changed files with 4,559 additions and 1,385 deletions.
10 changes: 9 additions & 1 deletion .idea/ktlint-plugin.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public fun SelectableLazyColumn(
state: SelectableLazyListState = rememberSelectableLazyListState(),
contentPadding: PaddingValues = PaddingValues(0.dp),
reverseLayout: Boolean = false,
onSelectedIndexesChanged: (List<Int>) -> Unit = {},
onSelectedIndexesChange: (List<Int>) -> Unit = {},
verticalArrangement: Arrangement.Vertical = if (!reverseLayout) Arrangement.Top else Arrangement.Bottom,
horizontalAlignment: Alignment.Horizontal = Alignment.Start,
flingBehavior: FlingBehavior = ScrollableDefaults.flingBehavior(),
Expand All @@ -64,7 +64,7 @@ public fun SelectableLazyColumn(
val keys = remember(container) { container.getKeys() }
var isFocused by remember { mutableStateOf(false) }

val latestOnSelectedIndexesChanged = rememberUpdatedState(onSelectedIndexesChanged)
val latestOnSelectedIndexesChanged = rememberUpdatedState(onSelectedIndexesChange)
LaunchedEffect(state, container) {
snapshotFlow { state.selectedKeys }
.collect { selectedKeys ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public fun <T> BasicLazyTree(
selectionMode = selectionMode,
keyActions = keyActions,
pointerEventActions = pointerEventScopedActions,
onSelectedIndexesChanged = {
onSelectedIndexesChange = {
onSelectionChange(it.map { element -> flattenedTree[element] as Tree.Element<T> })
},
interactionSource = remember { MutableInteractionSource() },
Expand Down
2 changes: 1 addition & 1 deletion ide-laf-bridge/api/ide-laf-bridge.api
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public final class org/jetbrains/jewel/bridge/theme/BridgeThemeColorPaletteKt {
public static final fun readFromLaF (Lorg/jetbrains/jewel/foundation/theme/ThemeColorPalette$Companion;)Lorg/jetbrains/jewel/foundation/theme/ThemeColorPalette;
}

public final class org/jetbrains/jewel/bridge/theme/IntUiBridgeKt {
public final class org/jetbrains/jewel/bridge/theme/IntUiBridgeTextKt {
public static final fun retrieveConsoleTextStyle ()Landroidx/compose/ui/text/TextStyle;
public static final fun retrieveDefaultTextStyle ()Landroidx/compose/ui/text/TextStyle;
public static final fun retrieveEditorTextStyle ()Landroidx/compose/ui/text/TextStyle;
Expand Down
1,104 changes: 7 additions & 1,097 deletions ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/theme/IntUiBridge.kt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
package org.jetbrains.jewel.bridge.theme

import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.shape.CornerSize
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.dp
import com.intellij.ide.ui.laf.darcula.DarculaUIUtil
import com.intellij.util.ui.JBUI
import org.jetbrains.jewel.bridge.createVerticalBrush
import org.jetbrains.jewel.bridge.dp
import org.jetbrains.jewel.bridge.retrieveArcAsCornerSizeWithFallbacks
import org.jetbrains.jewel.bridge.retrieveColorOrUnspecified
import org.jetbrains.jewel.bridge.toComposeColor
import org.jetbrains.jewel.bridge.toDpSize
import org.jetbrains.jewel.foundation.Stroke
import org.jetbrains.jewel.ui.component.styling.ButtonColors
import org.jetbrains.jewel.ui.component.styling.ButtonMetrics
import org.jetbrains.jewel.ui.component.styling.ButtonStyle
import org.jetbrains.jewel.ui.component.styling.IconButtonColors
import org.jetbrains.jewel.ui.component.styling.IconButtonMetrics
import org.jetbrains.jewel.ui.component.styling.IconButtonStyle
import org.jetbrains.jewel.ui.component.styling.SegmentedControlButtonColors
import org.jetbrains.jewel.ui.component.styling.SegmentedControlButtonMetrics
import org.jetbrains.jewel.ui.component.styling.SegmentedControlButtonStyle

internal fun readDefaultButtonStyle(): ButtonStyle {
val normalBackground =
listOf(
JBUI.CurrentTheme.Button.defaultButtonColorStart().toComposeColor(),
JBUI.CurrentTheme.Button.defaultButtonColorEnd().toComposeColor(),
)
.createVerticalBrush()

val normalContent = retrieveColorOrUnspecified("Button.default.foreground")

val normalBorder =
listOf(
JBUI.CurrentTheme.Button.buttonOutlineColorStart(true).toComposeColor(),
JBUI.CurrentTheme.Button.buttonOutlineColorEnd(true).toComposeColor(),
)
.createVerticalBrush()

val colors =
ButtonColors(
background = normalBackground,
backgroundDisabled = SolidColor(Color.Transparent),
backgroundFocused = normalBackground,
backgroundPressed = normalBackground,
backgroundHovered = normalBackground,
content = normalContent,
contentDisabled = retrieveColorOrUnspecified("Button.disabledText"),
contentFocused = normalContent,
contentPressed = normalContent,
contentHovered = normalContent,
border = normalBorder,
borderDisabled = SolidColor(JBUI.CurrentTheme.Button.disabledOutlineColor().toComposeColor()),
borderFocused = SolidColor(retrieveColorOrUnspecified("Button.default.focusedBorderColor")),
borderPressed = normalBorder,
borderHovered = normalBorder,
)

val minimumSize = JBUI.CurrentTheme.Button.minimumSize().toDpSize()
return ButtonStyle(
colors = colors,
metrics =
ButtonMetrics(
cornerSize = retrieveArcAsCornerSizeWithFallbacks("Button.default.arc", "Button.arc"),
padding = PaddingValues(horizontal = 14.dp), // see DarculaButtonUI.HORIZONTAL_PADDING
minSize = DpSize(minimumSize.width, minimumSize.height),
borderWidth = 1.dp,
focusOutlineExpand = 1.5.dp, // From DarculaButtonPainter.getBorderInsets
),
focusOutlineAlignment = Stroke.Alignment.Center,
)
}

internal fun readOutlinedButtonStyle(): ButtonStyle {
val normalBackground =
listOf(
JBUI.CurrentTheme.Button.buttonColorStart().toComposeColor(),
JBUI.CurrentTheme.Button.buttonColorEnd().toComposeColor(),
)
.createVerticalBrush()

val normalContent = retrieveColorOrUnspecified("Button.foreground")

val normalBorder =
listOf(
JBUI.CurrentTheme.Button.buttonOutlineColorStart(false).toComposeColor(),
JBUI.CurrentTheme.Button.buttonOutlineColorEnd(false).toComposeColor(),
)
.createVerticalBrush()

val colors =
ButtonColors(
background = normalBackground,
backgroundDisabled = SolidColor(Color.Transparent),
backgroundFocused = normalBackground,
backgroundPressed = normalBackground,
backgroundHovered = normalBackground,
content = normalContent,
contentDisabled = retrieveColorOrUnspecified("Button.disabledText"),
contentFocused = normalContent,
contentPressed = normalContent,
contentHovered = normalContent,
border = normalBorder,
borderDisabled = SolidColor(JBUI.CurrentTheme.Button.disabledOutlineColor().toComposeColor()),
borderFocused = SolidColor(JBUI.CurrentTheme.Button.focusBorderColor(false).toComposeColor()),
borderPressed = normalBorder,
borderHovered = normalBorder,
)

val minimumSize = JBUI.CurrentTheme.Button.minimumSize().toDpSize()
return ButtonStyle(
colors = colors,
metrics =
ButtonMetrics(
cornerSize = CornerSize(DarculaUIUtil.BUTTON_ARC.dp / 2),
padding = PaddingValues(horizontal = 14.dp), // see DarculaButtonUI.HORIZONTAL_PADDING
minSize = DpSize(minimumSize.width, minimumSize.height),
borderWidth = DarculaUIUtil.LW.dp,
focusOutlineExpand = Dp.Unspecified,
),
focusOutlineAlignment = Stroke.Alignment.Center,
)
}

internal fun readSegmentedControlButtonStyle(): SegmentedControlButtonStyle {
val selectedBackground = SolidColor(JBUI.CurrentTheme.SegmentedButton.SELECTED_BUTTON_COLOR.toComposeColor())

val normalBorder =
listOf(
JBUI.CurrentTheme.SegmentedButton.SELECTED_START_BORDER_COLOR.toComposeColor(),
JBUI.CurrentTheme.SegmentedButton.SELECTED_END_BORDER_COLOR.toComposeColor(),
)
.createVerticalBrush()

val selectedDisabledBorder =
listOf(
JBUI.CurrentTheme.Button.buttonOutlineColorStart(false).toComposeColor(),
JBUI.CurrentTheme.Button.buttonOutlineColorEnd(false).toComposeColor(),
)
.createVerticalBrush()

val colors =
SegmentedControlButtonColors(
background = SolidColor(Color.Transparent),
backgroundPressed = selectedBackground,
backgroundHovered = SolidColor(JBUI.CurrentTheme.ActionButton.hoverBackground().toComposeColor()),
backgroundSelected = selectedBackground,
backgroundSelectedFocused =
SolidColor(JBUI.CurrentTheme.SegmentedButton.FOCUSED_SELECTED_BUTTON_COLOR.toComposeColor()),
content = retrieveColorOrUnspecified("Button.foreground"),
contentDisabled = retrieveColorOrUnspecified("Label.disabledForeground"),
border = normalBorder,
borderSelected = normalBorder,
borderSelectedDisabled = selectedDisabledBorder,
borderSelectedFocused = SolidColor(JBUI.CurrentTheme.Button.focusBorderColor(false).toComposeColor()),
)

val minimumSize = JBUI.CurrentTheme.Button.minimumSize().toDpSize()
return SegmentedControlButtonStyle(
colors = colors,
metrics =
SegmentedControlButtonMetrics(
cornerSize = CornerSize(DarculaUIUtil.BUTTON_ARC.dp / 2),
segmentedButtonPadding = PaddingValues(horizontal = 14.dp),
minSize = DpSize(minimumSize.width, minimumSize.height),
borderWidth = DarculaUIUtil.LW.dp,
),
)
}

internal fun readIconButtonStyle(): IconButtonStyle =
IconButtonStyle(
metrics =
IconButtonMetrics(
cornerSize = CornerSize(DarculaUIUtil.BUTTON_ARC.dp / 2),
borderWidth = 1.dp,
padding = PaddingValues(0.dp),
minSize = DpSize(24.dp, 24.dp),
),
colors =
IconButtonColors(
foregroundSelectedActivated = retrieveColorOrUnspecified("ToolWindow.Button.selectedForeground"),
background = Color.Unspecified,
backgroundDisabled = Color.Unspecified,
backgroundSelected = retrieveColorOrUnspecified("ActionButton.pressedBackground"),
backgroundSelectedActivated = retrieveColorOrUnspecified("ToolWindow.Button.selectedBackground"),
backgroundPressed = retrieveColorOrUnspecified("ActionButton.pressedBackground"),
backgroundHovered = retrieveColorOrUnspecified("ActionButton.hoverBackground"),
backgroundFocused = retrieveColorOrUnspecified("ActionButton.hoverBackground"),
border = Color.Unspecified,
borderDisabled = Color.Unspecified,
borderSelected = retrieveColorOrUnspecified("ActionButton.pressedBackground"),
borderSelectedActivated = retrieveColorOrUnspecified("ToolWindow.Button.selectedBackground"),
borderFocused = Color.Unspecified,
borderPressed = retrieveColorOrUnspecified("ActionButton.pressedBorderColor"),
borderHovered = retrieveColorOrUnspecified("ActionButton.hoverBorderColor"),
),
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package org.jetbrains.jewel.bridge.theme

import androidx.compose.foundation.shape.CornerSize
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.isSpecified
import org.jetbrains.jewel.bridge.isNewUiTheme
import org.jetbrains.jewel.bridge.retrieveColorOrUnspecified
import org.jetbrains.jewel.bridge.retrieveIntAsDpOrUnspecified
import org.jetbrains.jewel.ui.component.styling.CheckboxColors
import org.jetbrains.jewel.ui.component.styling.CheckboxIcons
import org.jetbrains.jewel.ui.component.styling.CheckboxMetrics
import org.jetbrains.jewel.ui.component.styling.CheckboxStyle
import org.jetbrains.jewel.ui.icon.PathIconKey

internal fun readCheckboxStyle(): CheckboxStyle {
val textColor = retrieveColorOrUnspecified("CheckBox.foreground")
val colors =
CheckboxColors(
content = textColor,
contentDisabled = retrieveColorOrUnspecified("CheckBox.disabledText"),
contentSelected = textColor,
)

val newUiTheme = isNewUiTheme()
val metrics = if (newUiTheme) NewUiCheckboxMetrics else ClassicUiCheckboxMetrics

// This value is not normally defined in the themes, but Swing checks it anyway.
// The default hardcoded in
// com.intellij.ide.ui.laf.darcula.ui.DarculaCheckBoxUI.getDefaultIcon()
// is not correct though, the SVG is 19x19 and is missing 1px on the right
val checkboxSize =
retrieveIntAsDpOrUnspecified("CheckBox.iconSize").let {
when {
it.isSpecified -> DpSize(it, it)
else -> metrics.checkboxSize
}
}

return CheckboxStyle(
colors = colors,
metrics =
CheckboxMetrics(
checkboxSize = checkboxSize,
outlineCornerSize = CornerSize(metrics.outlineCornerSize),
outlineFocusedCornerSize = CornerSize(metrics.outlineFocusedCornerSize),
outlineSelectedCornerSize = CornerSize(metrics.outlineSelectedCornerSize),
outlineSelectedFocusedCornerSize = CornerSize(metrics.outlineSelectedFocusedCornerSize),
outlineSize = metrics.outlineSize,
outlineSelectedSize = metrics.outlineSelectedSize,
outlineFocusedSize = metrics.outlineFocusedSize,
outlineSelectedFocusedSize = metrics.outlineSelectedFocusedSize,
iconContentGap = metrics.iconContentGap,
),
icons = CheckboxIcons(checkbox = PathIconKey("${iconsBasePath}checkBox.svg", CheckboxIcons::class.java)),
)
}

private interface BridgeCheckboxMetrics {
val outlineSize: DpSize
val outlineFocusedSize: DpSize
val outlineSelectedSize: DpSize
val outlineSelectedFocusedSize: DpSize

val outlineCornerSize: Dp
val outlineFocusedCornerSize: Dp
val outlineSelectedCornerSize: Dp
val outlineSelectedFocusedCornerSize: Dp

val checkboxSize: DpSize
val iconContentGap: Dp
}

private object ClassicUiCheckboxMetrics : BridgeCheckboxMetrics {
override val outlineSize = DpSize(14.dp, 14.dp)
override val outlineFocusedSize = DpSize(15.dp, 15.dp)
override val outlineSelectedSize = outlineSize
override val outlineSelectedFocusedSize = outlineFocusedSize

override val outlineCornerSize = 2.dp
override val outlineFocusedCornerSize = 3.dp
override val outlineSelectedCornerSize = outlineCornerSize
override val outlineSelectedFocusedCornerSize = outlineFocusedCornerSize

override val checkboxSize = DpSize(20.dp, 19.dp)
override val iconContentGap = 4.dp
}

private object NewUiCheckboxMetrics : BridgeCheckboxMetrics {
override val outlineSize = DpSize(16.dp, 16.dp)
override val outlineFocusedSize = outlineSize
override val outlineSelectedSize = DpSize(20.dp, 20.dp)
override val outlineSelectedFocusedSize = outlineSelectedSize

override val outlineCornerSize = 3.dp
override val outlineFocusedCornerSize = outlineCornerSize
override val outlineSelectedCornerSize = 4.5.dp
override val outlineSelectedFocusedCornerSize = outlineSelectedCornerSize

override val checkboxSize = DpSize(24.dp, 24.dp)
override val iconContentGap = 5.dp
}
Loading

0 comments on commit f5dae48

Please sign in to comment.