Skip to content

Commit

Permalink
Rewrite/cleanup/simplify ListComboBox code
Browse files Browse the repository at this point in the history
* Split the editable and non-editable list combo boxes
* Fix up item state management as it was utter chaos
* Use the appropriate names for style items
* Add iconTextGap to list item metrics
* Only do preview selection when mouse-moving over an item, not when
  hovering, to reduce glitches when scrolling
* Fix margins and colours
  • Loading branch information
rock3r committed Dec 10, 2024
1 parent 8b9540b commit 1bcd3ba
Show file tree
Hide file tree
Showing 26 changed files with 945 additions and 582 deletions.
3 changes: 2 additions & 1 deletion foundation/api/foundation.api
Original file line number Diff line number Diff line change
Expand Up @@ -831,8 +831,9 @@ public final class org/jetbrains/jewel/foundation/modifier/BorderKt {
public static synthetic fun border-QWjY48E$default (Landroidx/compose/ui/Modifier;Lorg/jetbrains/jewel/foundation/Stroke$Alignment;FJLandroidx/compose/ui/graphics/Shape;FILjava/lang/Object;)Landroidx/compose/ui/Modifier;
}

public final class org/jetbrains/jewel/foundation/modifier/OnHoverModifierKt {
public final class org/jetbrains/jewel/foundation/modifier/PointerModifiersKt {
public static final fun onHover (Landroidx/compose/ui/Modifier;Lkotlin/jvm/functions/Function1;)Landroidx/compose/ui/Modifier;
public static final fun onMove (Landroidx/compose/ui/Modifier;Lkotlin/jvm/functions/Function1;)Landroidx/compose/ui/Modifier;
}

public final class org/jetbrains/jewel/foundation/state/CommonStateBitMask {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package org.jetbrains.jewel.foundation.modifier

import androidx.compose.ui.Modifier
import androidx.compose.ui.awt.awtEventOrNull
import androidx.compose.ui.input.pointer.PointerEventType
import androidx.compose.ui.input.pointer.pointerInput
import java.awt.event.MouseEvent

public fun Modifier.onHover(onHover: (Boolean) -> Unit): Modifier =
pointerInput(Unit) {
Expand All @@ -16,3 +18,15 @@ public fun Modifier.onHover(onHover: (Boolean) -> Unit): Modifier =
}
}
}

public fun Modifier.onMove(onMove: (MouseEvent?) -> Unit): Modifier =
pointerInput(Unit) {
awaitPointerEventScope {
while (true) {
val event = awaitPointerEvent()
when (event.type) {
PointerEventType.Move -> onMove(event.awtEventOrNull)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ internal fun readDefaultComboBoxStyle(): ComboBoxStyle {
minSize = DpSize(minimumSize.width + arrowWidth, minimumSize.height),
cornerSize = componentArc,
contentPadding = retrieveInsetsAsPaddingValues("ComboBox.padding"),
popupContentPadding = PaddingValues(6.dp),
popupContentPadding = PaddingValues(vertical = 6.dp),
borderWidth = DarculaUIUtil.LW.dp,
maxPopupHeight = Dp.Unspecified,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,23 @@ internal fun readLazyTreeStyle(): LazyTreeStyle {
val selectedElementBackground = retrieveColorOrUnspecified("Tree.selectionBackground")
val inactiveSelectedElementBackground = retrieveColorOrUnspecified("Tree.selectionInactiveBackground")

val colors =
val itemColors =
SimpleListItemColors(
content = normalContent,
contentFocused = normalContent,
contentActive = normalContent,
contentSelected = selectedContent,
contentSelectedFocused = selectedContent,
backgroundFocused = Color.Transparent,
contentSelectedActive = selectedContent,
background = Color.Unspecified,
backgroundActive = Color.Unspecified,
backgroundSelected = inactiveSelectedElementBackground,
backgroundSelectedFocused = selectedElementBackground,
backgroundSelectedActive = selectedElementBackground,
)

val leftIndent = retrieveIntAsDpOrUnspecified("Tree.leftChildIndent").takeOrElse { 7.dp }
val rightIndent = retrieveIntAsDpOrUnspecified("Tree.rightChildIndent").takeOrElse { 11.dp }

return LazyTreeStyle(
colors = colors,
colors = itemColors,
metrics =
LazyTreeMetrics(
indentSize = leftIndent + rightIndent,
Expand All @@ -46,6 +47,7 @@ internal fun readLazyTreeStyle(): LazyTreeStyle {
innerPadding = PaddingValues(horizontal = 12.dp),
outerPadding = PaddingValues(4.dp),
selectionBackgroundCornerSize = CornerSize(JBUI.CurrentTheme.Tree.ARC.dp / 2),
iconTextGap = 2.dp,
),
elementMinHeight = retrieveIntAsDpOrUnspecified("Tree.rowHeight").takeOrElse { 24.dp },
chevronContentGap = 2.dp, // See com.intellij.ui.tree.ui.ClassicPainter.GAP
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package org.jetbrains.jewel.bridge.theme

import androidx.compose.foundation.shape.CornerSize
import androidx.compose.ui.unit.dp
import com.intellij.util.ui.JBUI
import org.jetbrains.jewel.bridge.dp
import org.jetbrains.jewel.bridge.retrieveColorOrUnspecified
import org.jetbrains.jewel.bridge.retrieveInsetsAsPaddingValues
import org.jetbrains.jewel.bridge.toPaddingValues
import org.jetbrains.jewel.ui.component.styling.SimpleListItemColors
import org.jetbrains.jewel.ui.component.styling.SimpleListItemMetrics
Expand All @@ -15,18 +15,19 @@ internal fun readSimpleListItemStyle() =
colors =
SimpleListItemColors(
background = retrieveColorOrUnspecified("ComboBox.background"),
backgroundFocused = retrieveColorOrUnspecified("ComboBox.selectionBackground"),
backgroundActive = retrieveColorOrUnspecified("ComboBox.background"),
backgroundSelected = retrieveColorOrUnspecified("ComboBox.selectionBackground"),
backgroundSelectedFocused = retrieveColorOrUnspecified("ComboBox.selectionBackground"),
backgroundSelectedActive = retrieveColorOrUnspecified("ComboBox.selectionBackground"),
content = retrieveColorOrUnspecified("ComboBox.foreground"),
contentFocused = retrieveColorOrUnspecified("ComboBox.foreground"),
contentActive = retrieveColorOrUnspecified("ComboBox.foreground"),
contentSelected = retrieveColorOrUnspecified("ComboBox.foreground"),
contentSelectedFocused = retrieveColorOrUnspecified("ComboBox.foreground"),
contentSelectedActive = retrieveColorOrUnspecified("ComboBox.foreground"),
),
metrics =
SimpleListItemMetrics(
innerPadding = retrieveInsetsAsPaddingValues("ComboBox.padding"),
innerPadding = JBUI.CurrentTheme.PopupMenu.Selection.innerInsets().toPaddingValues(),
outerPadding = JBUI.CurrentTheme.PopupMenu.Selection.outerInsets().toPaddingValues(),
selectionBackgroundCornerSize = CornerSize(JBUI.CurrentTheme.PopupMenu.Selection.ARC.dp / 2),
iconTextGap = 2.dp,
),
)
34 changes: 22 additions & 12 deletions int-ui/int-ui-standalone/api/int-ui-standalone.api
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ public final class org/jetbrains/jewel/intui/standalone/styling/IntUiDefaultInfo
public final class org/jetbrains/jewel/intui/standalone/styling/IntUiDefaultSimpleListItemLazyTreeStyleFactory {
public static final field $stable I
public static final field INSTANCE Lorg/jetbrains/jewel/intui/standalone/styling/IntUiDefaultSimpleListItemLazyTreeStyleFactory;
public final fun dark-69fazGs (JJJJJJJLandroidx/compose/runtime/Composer;II)Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemColors;
public final fun light-69fazGs (JJJJJJJLandroidx/compose/runtime/Composer;II)Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemColors;
public final fun dark-oq7We08 (JJJJJJJJLandroidx/compose/runtime/Composer;II)Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemColors;
public final fun light-oq7We08 (JJJJJJJJLandroidx/compose/runtime/Composer;II)Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemColors;
}

public final class org/jetbrains/jewel/intui/standalone/styling/IntUiDefaultSuccessBannerColorFactory {
Expand Down Expand Up @@ -297,8 +297,8 @@ public final class org/jetbrains/jewel/intui/standalone/styling/IntUiLazyTreeSty
public static final fun dark (Lorg/jetbrains/jewel/ui/component/styling/LazyTreeStyle$Companion;Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemColors;Lorg/jetbrains/jewel/ui/component/styling/LazyTreeMetrics;Lorg/jetbrains/jewel/ui/component/styling/LazyTreeIcons;Landroidx/compose/runtime/Composer;II)Lorg/jetbrains/jewel/ui/component/styling/LazyTreeStyle;
public static final fun defaults (Lorg/jetbrains/jewel/ui/component/styling/LazyTreeIcons$Companion;Lorg/jetbrains/jewel/ui/icon/IconKey;Lorg/jetbrains/jewel/ui/icon/IconKey;Lorg/jetbrains/jewel/ui/icon/IconKey;Lorg/jetbrains/jewel/ui/icon/IconKey;)Lorg/jetbrains/jewel/ui/component/styling/LazyTreeIcons;
public static synthetic fun defaults$default (Lorg/jetbrains/jewel/ui/component/styling/LazyTreeIcons$Companion;Lorg/jetbrains/jewel/ui/icon/IconKey;Lorg/jetbrains/jewel/ui/icon/IconKey;Lorg/jetbrains/jewel/ui/icon/IconKey;Lorg/jetbrains/jewel/ui/icon/IconKey;ILjava/lang/Object;)Lorg/jetbrains/jewel/ui/component/styling/LazyTreeIcons;
public static final fun defaults-hRm7RI8 (Lorg/jetbrains/jewel/ui/component/styling/LazyTreeMetrics$Companion;FLandroidx/compose/foundation/shape/CornerSize;Landroidx/compose/foundation/layout/PaddingValues;Landroidx/compose/foundation/layout/PaddingValues;FF)Lorg/jetbrains/jewel/ui/component/styling/LazyTreeMetrics;
public static synthetic fun defaults-hRm7RI8$default (Lorg/jetbrains/jewel/ui/component/styling/LazyTreeMetrics$Companion;FLandroidx/compose/foundation/shape/CornerSize;Landroidx/compose/foundation/layout/PaddingValues;Landroidx/compose/foundation/layout/PaddingValues;FFILjava/lang/Object;)Lorg/jetbrains/jewel/ui/component/styling/LazyTreeMetrics;
public static final fun defaults-FqMU-wI (Lorg/jetbrains/jewel/ui/component/styling/LazyTreeMetrics$Companion;FLandroidx/compose/foundation/shape/CornerSize;Landroidx/compose/foundation/layout/PaddingValues;Landroidx/compose/foundation/layout/PaddingValues;FFF)Lorg/jetbrains/jewel/ui/component/styling/LazyTreeMetrics;
public static synthetic fun defaults-FqMU-wI$default (Lorg/jetbrains/jewel/ui/component/styling/LazyTreeMetrics$Companion;FLandroidx/compose/foundation/shape/CornerSize;Landroidx/compose/foundation/layout/PaddingValues;Landroidx/compose/foundation/layout/PaddingValues;FFFILjava/lang/Object;)Lorg/jetbrains/jewel/ui/component/styling/LazyTreeMetrics;
public static final fun light (Lorg/jetbrains/jewel/ui/component/styling/LazyTreeStyle$Companion;Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemColors;Lorg/jetbrains/jewel/ui/component/styling/LazyTreeMetrics;Lorg/jetbrains/jewel/ui/component/styling/LazyTreeIcons;Landroidx/compose/runtime/Composer;II)Lorg/jetbrains/jewel/ui/component/styling/LazyTreeStyle;
}

Expand Down Expand Up @@ -421,19 +421,29 @@ public final class org/jetbrains/jewel/intui/standalone/styling/IntUiSegmentedCo
}

public final class org/jetbrains/jewel/intui/standalone/styling/IntUiSelectableLazyColumnStylingKt {
public static final fun dark-V6-xPKs (Lorg/jetbrains/jewel/ui/component/styling/SelectableLazyColumnStyle$Companion;FJLandroidx/compose/foundation/shape/CornerSize;Landroidx/compose/foundation/layout/PaddingValues;Landroidx/compose/foundation/layout/PaddingValues;JJLandroidx/compose/runtime/Composer;II)Lorg/jetbrains/jewel/ui/component/styling/SelectableLazyColumnStyle;
public static final fun light-V6-xPKs (Lorg/jetbrains/jewel/ui/component/styling/SelectableLazyColumnStyle$Companion;FJLandroidx/compose/foundation/shape/CornerSize;Landroidx/compose/foundation/layout/PaddingValues;Landroidx/compose/foundation/layout/PaddingValues;JJLandroidx/compose/runtime/Composer;II)Lorg/jetbrains/jewel/ui/component/styling/SelectableLazyColumnStyle;
public static final fun dark-DzVHIIc (Lorg/jetbrains/jewel/ui/component/styling/SelectableLazyColumnStyle$Companion;FLorg/jetbrains/jewel/ui/component/styling/SimpleListItemColors;Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemMetrics;Landroidx/compose/runtime/Composer;II)Lorg/jetbrains/jewel/ui/component/styling/SelectableLazyColumnStyle;
public static final fun light-DzVHIIc (Lorg/jetbrains/jewel/ui/component/styling/SelectableLazyColumnStyle$Companion;FLorg/jetbrains/jewel/ui/component/styling/SimpleListItemColors;Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemMetrics;Landroidx/compose/runtime/Composer;II)Lorg/jetbrains/jewel/ui/component/styling/SelectableLazyColumnStyle;
}

public final class org/jetbrains/jewel/intui/standalone/styling/IntUiSimpleListItemStylingKt {
public static final fun dark (Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemStyle$Companion;)Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemStyle;
public static final fun darkFullWidth-iLRpYWo (Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemStyle$Companion;JJJJJJJJ)Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemStyle;
public static synthetic fun darkFullWidth-iLRpYWo$default (Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemStyle$Companion;JJJJJJJJILjava/lang/Object;)Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemStyle;
public static final fun dark (Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemStyle$Companion;Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemColors;Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemMetrics;)Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemStyle;
public static synthetic fun dark$default (Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemStyle$Companion;Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemColors;Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemMetrics;ILjava/lang/Object;)Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemStyle;
public static final fun dark-iLRpYWo (Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemColors$Companion;JJJJJJJJ)Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemColors;
public static synthetic fun dark-iLRpYWo$default (Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemColors$Companion;JJJJJJJJILjava/lang/Object;)Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemColors;
public static final fun darkFullWidth (Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemStyle$Companion;Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemColors;Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemMetrics;)Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemStyle;
public static synthetic fun darkFullWidth$default (Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemStyle$Companion;Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemColors;Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemMetrics;ILjava/lang/Object;)Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemStyle;
public static final fun default (Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemStyle$Companion;Landroidx/compose/runtime/Composer;I)Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemStyle;
public static final fun default-M2VBTUQ (Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemMetrics$Companion;Landroidx/compose/foundation/layout/PaddingValues;Landroidx/compose/foundation/layout/PaddingValues;Landroidx/compose/foundation/shape/CornerSize;F)Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemMetrics;
public static synthetic fun default-M2VBTUQ$default (Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemMetrics$Companion;Landroidx/compose/foundation/layout/PaddingValues;Landroidx/compose/foundation/layout/PaddingValues;Landroidx/compose/foundation/shape/CornerSize;FILjava/lang/Object;)Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemMetrics;
public static final fun fullWidth (Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemStyle$Companion;Landroidx/compose/runtime/Composer;I)Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemStyle;
public static final fun light (Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemStyle$Companion;)Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemStyle;
public static final fun lightFullWidth-iLRpYWo (Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemStyle$Companion;JJJJJJJJ)Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemStyle;
public static synthetic fun lightFullWidth-iLRpYWo$default (Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemStyle$Companion;JJJJJJJJILjava/lang/Object;)Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemStyle;
public static final fun fullWidth-M2VBTUQ (Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemMetrics$Companion;Landroidx/compose/foundation/layout/PaddingValues;Landroidx/compose/foundation/layout/PaddingValues;Landroidx/compose/foundation/shape/CornerSize;F)Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemMetrics;
public static synthetic fun fullWidth-M2VBTUQ$default (Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemMetrics$Companion;Landroidx/compose/foundation/layout/PaddingValues;Landroidx/compose/foundation/layout/PaddingValues;Landroidx/compose/foundation/shape/CornerSize;FILjava/lang/Object;)Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemMetrics;
public static final fun light (Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemStyle$Companion;Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemColors;Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemMetrics;)Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemStyle;
public static synthetic fun light$default (Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemStyle$Companion;Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemColors;Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemMetrics;ILjava/lang/Object;)Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemStyle;
public static final fun light-iLRpYWo (Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemColors$Companion;JJJJJJJJ)Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemColors;
public static synthetic fun light-iLRpYWo$default (Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemColors$Companion;JJJJJJJJILjava/lang/Object;)Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemColors;
public static final fun lightFullWidth (Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemStyle$Companion;Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemColors;Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemMetrics;)Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemStyle;
public static synthetic fun lightFullWidth$default (Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemStyle$Companion;Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemColors;Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemMetrics;ILjava/lang/Object;)Lorg/jetbrains/jewel/ui/component/styling/SimpleListItemStyle;
}

public final class org/jetbrains/jewel/intui/standalone/styling/IntUiSliderStylingKt {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public fun ComboBoxMetrics.Companion.default(
minSize: DpSize = DpSize(49.dp, 24.dp),
cornerSize: CornerSize = CornerSize(4.dp),
contentPadding: PaddingValues = PaddingValues(horizontal = 6.dp, vertical = 2.dp),
popupContentPadding: PaddingValues = PaddingValues(6.dp),
popupContentPadding: PaddingValues = PaddingValues(vertical = 6.dp),
borderWidth: Dp = 1.dp,
maxPopupHeight: Dp = 200.dp,
): ComboBoxMetrics =
Expand All @@ -231,7 +231,7 @@ public fun ComboBoxMetrics.Companion.undecorated(
minSize: DpSize = DpSize(49.dp, 24.dp),
cornerSize: CornerSize = CornerSize(4.dp),
contentPadding: PaddingValues = PaddingValues(horizontal = 6.dp, vertical = 2.dp),
popupContentPadding: PaddingValues = PaddingValues(6.dp),
popupContentPadding: PaddingValues = PaddingValues(vertical = 6.dp),
borderWidth: Dp = 0.dp,
maxPopupHeight: Dp = 200.dp,
): ComboBoxMetrics =
Expand Down
Loading

0 comments on commit 1bcd3ba

Please sign in to comment.