Skip to content

Commit

Permalink
Fix minor issues (typos, formatting)
Browse files Browse the repository at this point in the history
  • Loading branch information
rock3r committed Dec 13, 2023
1 parent 4ba45ab commit 8019784
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -533,8 +533,8 @@ private fun readLinkStyle(
private fun readMenuStyle(): MenuStyle {
val backgroundSelected = retrieveColorOrUnspecified("MenuItem.selectionBackground")
val foregroundSelected = retrieveColorOrUnspecified("MenuItem.selectionForeground")
val keybingingTint = retrieveColorOrUnspecified("MenuItem.acceleratorForeground")
val keybingingTintSelected = Color.Unspecified
val keybindingTint = retrieveColorOrUnspecified("MenuItem.acceleratorForeground")
val keybindingTintSelected = Color.Unspecified

val colors = MenuColors(
background = retrieveColorOrUnspecified("PopupMenu.background"),
Expand All @@ -557,11 +557,11 @@ private fun readMenuStyle(): MenuStyle {
iconTintFocused = Color.Unspecified,
iconTintPressed = Color.Unspecified,
iconTintHovered = Color.Unspecified,
keybindingTint = keybingingTint,
keybindingTintDisabled = keybingingTint,
keybindingTintFocused = keybingingTintSelected,
keybindingTintPressed = keybingingTintSelected,
keybindingTintHovered = keybingingTintSelected,
keybindingTint = keybindingTint,
keybindingTintDisabled = keybindingTint,
keybindingTintFocused = keybindingTintSelected,
keybindingTintPressed = keybindingTintSelected,
keybindingTintHovered = keybindingTintSelected,
separator = retrieveColorOrUnspecified("Menu.separatorColor"),
),
)
Expand Down
2 changes: 2 additions & 0 deletions ui/api/ui.api
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ public final class org/jetbrains/jewel/ui/DefaultComponentStyling : org/jetbrain
public final fun getTooltipStyle ()Lorg/jetbrains/jewel/ui/component/styling/TooltipStyle;
public final fun getUndecoratedDropdownStyle ()Lorg/jetbrains/jewel/ui/component/styling/DropdownStyle;
public fun hashCode ()I
public synthetic fun provide (Lkotlin/jvm/functions/Function0;)Lorg/jetbrains/jewel/ui/ComponentStyling;
public fun provide (Lkotlin/jvm/functions/Function2;)Lorg/jetbrains/jewel/ui/ComponentStyling;
public fun provide ([Landroidx/compose/runtime/ProvidedValue;)Lorg/jetbrains/jewel/ui/ComponentStyling;
public fun styles (Landroidx/compose/runtime/Composer;I)[Landroidx/compose/runtime/ProvidedValue;
public fun toString ()Ljava/lang/String;
public synthetic fun with (Lkotlin/jvm/functions/Function0;)Lorg/jetbrains/jewel/ui/ComponentStyling;
public fun with (Lkotlin/jvm/functions/Function2;)Lorg/jetbrains/jewel/ui/ComponentStyling;
public fun with (Lorg/jetbrains/jewel/ui/ComponentStyling;)Lorg/jetbrains/jewel/ui/ComponentStyling;
}
Expand Down
47 changes: 31 additions & 16 deletions ui/src/main/kotlin/org/jetbrains/jewel/ui/component/Menu.kt
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ internal fun MenuContent(

val selectableItems = remember { items.filterIsInstance<MenuSelectableItem>() }

val anyIconItem = remember { selectableItems.any { it.iconResource != null } }
val anyKeyBinding = remember { selectableItems.any { it.keybinding != null } }
val anyItemHasIcon = remember { selectableItems.any { it.iconResource != null } }
val anyItemHasKeybinding = remember { selectableItems.any { it.keybinding != null } }

val localMenuManager = LocalMenuManager.current
val scrollState = rememberScrollState()
Expand All @@ -165,7 +165,7 @@ internal fun MenuContent(
) {
Column(Modifier.verticalScroll(scrollState).padding(style.metrics.contentPadding)) {
items.forEach {
ShowMenuItem(it, anyIconItem, anyKeyBinding)
ShowMenuItem(it, anyItemHasIcon, anyItemHasKeybinding)
}
}

Expand All @@ -179,14 +179,18 @@ internal fun MenuContent(
}

@Composable
private fun ShowMenuItem(item: MenuItem, iconGap: Boolean = false, keybindingGap: Boolean = false) {
private fun ShowMenuItem(
item: MenuItem,
canShowIcon: Boolean = false,
canShowKeybinding: Boolean = false,
) {
when (item) {
is MenuSelectableItem -> MenuItem(
selected = item.isSelected,
onClick = item.onClick,
enabled = item.isEnabled,
iconGap = iconGap,
keybindingGap = keybindingGap,
canShowIcon = canShowIcon,
canShowKeybinding = canShowKeybinding,
iconResource = item.iconResource,
iconClass = item.iconClass,
keybinding = item.keybinding,
Expand All @@ -196,7 +200,7 @@ private fun ShowMenuItem(item: MenuItem, iconGap: Boolean = false, keybindingGap
is SubmenuItem -> MenuSubmenuItem(
enabled = item.isEnabled,
submenu = item.submenu,
iconGap = iconGap,
canShowIcon = canShowIcon,
iconResource = item.iconResource,
iconClass = item.iconClass,
content = item.content,
Expand Down Expand Up @@ -349,8 +353,8 @@ internal fun MenuItem(
iconResource: String?,
iconClass: Class<*>,
keybinding: Set<Char>?,
iconGap: Boolean,
keybindingGap: Boolean,
canShowIcon: Boolean,
canShowKeybinding: Boolean,
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
style: MenuStyle = JewelTheme.menuStyle,
content: @Composable () -> Unit,
Expand Down Expand Up @@ -422,18 +426,28 @@ internal fun MenuItem(
.padding(itemMetrics.contentPadding),
horizontalArrangement = Arrangement.spacedBy(4.dp),
) {
if (iconGap) {
if (canShowIcon) {
val iconModifier = Modifier.size(style.metrics.itemMetrics.iconSize)
if (iconResource != null) {
Icon(resource = iconResource, contentDescription = null, iconClass = iconClass)
Icon(
resource = iconResource,
contentDescription = null,
iconClass = iconClass,
modifier = iconModifier,
)
} else {
Box(modifier = Modifier.size(style.metrics.itemMetrics.iconSize))
Box(modifier = iconModifier)
}
}

Box(modifier = Modifier.weight(1f, true)) {
content()
}
if (keybindingGap) {
val keybindingText = remember { keybinding?.joinToString("") { it.toString() }.orEmpty() }

if (canShowKeybinding) {
val keybindingText = remember(keybinding) {
keybinding?.joinToString("") { it.toString() }.orEmpty()
}
Text(
modifier = Modifier.padding(style.metrics.itemMetrics.keybindingsPadding),
text = keybindingText,
Expand All @@ -449,7 +463,7 @@ internal fun MenuItem(
public fun MenuSubmenuItem(
modifier: Modifier = Modifier,
enabled: Boolean = true,
iconGap: Boolean,
canShowIcon: Boolean,
iconResource: String?,
iconClass: Class<*>,
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
Expand Down Expand Up @@ -517,13 +531,14 @@ public fun MenuSubmenuItem(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(4.dp),
) {
if (iconGap) {
if (canShowIcon) {
if (iconResource != null) {
Icon(resource = iconResource, iconClass = iconClass, contentDescription = "")
} else {
Box(Modifier.size(style.metrics.itemMetrics.iconSize))
}
}

Box(Modifier.weight(1f)) { content() }

val chevronPainter by style.icons.submenuChevron.getPainter(Stateful(itemState))
Expand Down

0 comments on commit 8019784

Please sign in to comment.