Skip to content

Commit

Permalink
keybindings
Browse files Browse the repository at this point in the history
  • Loading branch information
fscarponi committed Dec 11, 2023
1 parent 57c4356 commit 300ae3e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import org.jetbrains.jewel.ui.component.Dropdown
import org.jetbrains.jewel.ui.component.Text
import org.jetbrains.jewel.ui.component.separator
import org.jetbrains.jewel.ui.component.styling.DropdownStyle
import kotlin.random.Random

@Composable
@View(title = "Dropdowns", position = 3)
Expand Down Expand Up @@ -118,8 +119,11 @@ fun Dropdowns() {
separator()
} else {
selectableItem(
iconResource = dropdownIcons.random(),
iconResource = dropdownIconsSample.random(),
iconClass = DropdownStyle::class.java,
keybinding = if (Random.nextBoolean()) null else dropdownKeybindingsSample.shuffled()
.take(2)
.toSet(),
selected = false,
onClick = { }
) {
Expand All @@ -133,8 +137,11 @@ fun Dropdowns() {
separator()
} else {
selectableItem(
iconResource = dropdownIcons.random(),
iconResource = dropdownIconsSample.random(),
iconClass = DropdownStyle::class.java,
keybinding = if (Random.nextBoolean()) null else dropdownKeybindingsSample.shuffled()
.take(2)
.toSet(),
selected = false,
onClick = { }
) {
Expand All @@ -149,7 +156,7 @@ fun Dropdowns() {
separator()
} else {
selectableItem(
iconResource = dropdownIcons.random(),
iconResource = dropdownIconsSample.random(),
iconClass = DropdownStyle::class.java,
selected = false,
onClick = { }
Expand All @@ -171,4 +178,5 @@ fun Dropdowns() {
}
}

private val dropdownIcons = listOf("icons/search.svg", "icons/close.svg", null)
private val dropdownIconsSample = listOf("icons/search.svg", "icons/close.svg", null)
private val dropdownKeybindingsSample = setOf('A', 'B', '', '', '')
11 changes: 8 additions & 3 deletions ui/src/main/kotlin/org/jetbrains/jewel/ui/component/Menu.kt
Original file line number Diff line number Diff line change
Expand Up @@ -426,17 +426,22 @@ internal fun MenuItem(
Box(modifier = Modifier.size(16.dp)) // todo 16 dp move to style.metrics.iconSize
}
}
content()
Box(modifier = Modifier.weight(1f, true)) {
content()
}
if (keybindingGap) {
val keybindingText = keybinding?.joinToString("+") { it.toString() } ?: ""
Text(keybindingText)
Text(
modifier = Modifier.padding(start = 4.dp),
text = keybindingText,
color = style.colors.itemColors.iconTint
)
}
}
}
}
}


@Composable
public fun MenuSubmenuItem(
modifier: Modifier = Modifier,
Expand Down

0 comments on commit 300ae3e

Please sign in to comment.