Keycaps
The keys of a shortcut, each on a cap of its own, as a menu, a list of shortcuts or a hint writes one: ⌘ K on Apple's systems and Ctrl K on the others, in the order and by the names of the system the app runs on (PantrixShortcut.keysOn).
import com.pantrixui.components.elements.keycaps.PantrixKeycaps
- As the system writes it.
⌥⇧⌘Fon Apple's systems,CtrlAltShiftFon the others: the order and the names arekeysOn's. - Two sizes.
KeycapsSize.Mediumfor the end of a row (footnote),KeycapsSize.Smallfor the end of a field or a launcher (caption). - In a sentence. The caps' first baseline is their keys': in a row lined up with
Modifier.alignByBaseline()they stand on the line of the words beside them. - Colour and style. A colour given with
KeycapsColorsis used, one left out stays the theme's: the fillbackground, the edgeborder, the keytextSecondary.KeycapsStylechanges the corners, the edge, the room between the caps and each size's room. - Automation. With
tagKeythe caps areKeycaps_<tagKey>; without a key they are not tagged.
Examples
A command's shortcut
A list of commands: the name on the left, the shortcut on the right on its caps. The shortcuts are drawn as the system the app runs on writes them: ⌘ on a Mac, Ctrl on Windows and Linux.
Column(verticalArrangement = Arrangement.spacedBy(PantrixTheme.spacing.sm)) {
COMMANDS.forEach { command ->
Row(modifier = Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically) {
PantrixText(text = command.name, modifier = Modifier.weight(1f))
PantrixKeycaps(shortcut = command.shortcut, tagKey = command.key)
}
}
}
private val COMMANDS = listOf(
Command("palette", "Palette", PantrixShortcut(Key.K, command = true)),
Command("save", "Save", PantrixShortcut(Key.S, command = true)),
Command("copy", "Copy", PantrixShortcut(Key.C, command = true, shift = true)),
Command("format", "Format", PantrixShortcut(Key.F, command = true, shift = true, alt = true))
)
private class Command(
val key: String,
val name: String,
val shortcut: PantrixShortcut
)
As each system writes it
One shortcut as two systems write it: on Apple's systems the modifier keys by their symbols, in the order ⌥ ⇧ ⌘; on the others by their names, in the order Ctrl Alt Shift. The app does not pick the system; here the two rows give it one each.
Column(verticalArrangement = Arrangement.spacedBy(PantrixTheme.spacing.sm)) {
SYSTEMS.forEach { (name, system) ->
Row(verticalAlignment = Alignment.CenterVertically) {
PantrixText(text = name, modifier = Modifier.weight(1f))
CompositionLocalProvider(LocalOperatingSystem provides system) {
PantrixKeycaps(shortcut = FORMAT, tagKey = "format_${system.name.lowercase()}")
}
}
}
}
private val SYSTEMS = listOf("macOS" to OperatingSystem.MacOs, "Windows" to OperatingSystem.Windows)
private val FORMAT = PantrixShortcut(Key.F, command = true, shift = true, alt = true)
In a sentence
Small caps in a sentence: all three parts stand on one baseline with alignByBaseline. A long paragraph that breaks does not take the caps along; this is for a short hint.
Row {
PantrixText(text = "Or press ", modifier = Modifier.alignByBaseline())
PantrixKeycaps(
shortcut = PASTE,
modifier = Modifier.alignByBaseline(),
size = KeycapsSize.Small,
tagKey = "paste"
)
PantrixText(text = " anywhere on this screen.", modifier = Modifier.alignByBaseline())
}
private val PASTE = PantrixShortcut(Key.V, command = true)
Colours and sizes of its own
In colours and sizes of their own: caps on the info fill, without a fill of their own and edged in the words' colour; less room between the caps, and wider caps.
val info = PantrixTheme.colors.info
Row(
modifier = Modifier
.clip(ShapeRole.Medium.toShape())
.background(info.container)
.padding(PantrixTheme.spacing.md),
horizontalArrangement = Arrangement.spacedBy(PantrixTheme.spacing.sm),
verticalAlignment = Alignment.CenterVertically
) {
PantrixText(text = "Format", color = info.onContainer)
PantrixKeycaps(
shortcut = FORMAT,
style = KeycapsStyle(gap = 2.dp, medium = KeycapSizeStyle(minWidth = 28.dp)),
colors = KeycapsColors(
container = Color.Transparent,
border = info.onContainer,
content = info.onContainer
),
tagKey = "own"
)
}
private val FORMAT = PantrixShortcut(Key.F, command = true, shift = true, alt = true)
API
shortcut
The keys of a shortcut, each on a cap of its own, as a menu, a list of shortcuts or a hint writes one: ⌘ K on Apple's systems and Ctrl K on the others, in the order and by the names of the system the app runs on (PantrixShortcut.keysOn).
| Parameter | Type | Default | What it is |
|---|---|---|---|
shortcut | PantrixShortcut | the shortcut whose keys are drawn. | |
modifier | Modifier | Modifier | the caps' modifier. |
size | KeycapsSize | KeycapsSize.Medium | how large the caps are: KeycapsSize.Medium, for the end of a row, by default. |
style | KeycapsStyle? | null | this call's own style: over every enclosing one and under the density. Only the fields it sets change, on every platform. |
colors | KeycapsColors? | null | this call's own colours, where they are not the theme's: the ones set here, with the theme's for the rest. |
tagKey | String? | null | the caps' automation key: they are Keycaps_<tagKey>, and are tagged only when given one. |
KeycapsStyle
PantrixKeycaps' geometry: the shape of a cap, its edge, the room between two caps, and a cap's room for each KeycapsSize. The same on every platform: a shortcut is written alike wherever a keyboard types it.
| Parameter | Type | Default | What it is |
|---|---|---|---|
shape | ShapeSpec | ShapeSpec.Unspecified | A cap's shape: ShapeRole.Small, a key's slight rounding. |
borderWidth | Dp | Dp.Unspecified | How wide the edge around a cap is. |
gap | Dp | Dp.Unspecified | The room between two caps. |
small | KeycapSizeStyle | KeycapSizeStyle() | KeycapsSize.Small's room in a cap. |
medium | KeycapSizeStyle | KeycapSizeStyle() | KeycapsSize.Medium's room in a cap. |
KeycapsColors
What PantrixKeycaps are painted with, where they are not the theme's: a colour that is set is used, and one that is left out stays the theme's.
| Parameter | Type | Default | What it is |
|---|---|---|---|
container | Color | Color.Unspecified | The fill of each cap: the theme's background, a step from the surface most rows stand on. |
border | Color | Color.Unspecified | The edge around each cap: the theme's border. |
content | Color | Color.Unspecified | The key's name on the cap: the theme's textSecondary, quieter than the words it stands by. |
Accessibility
- Screen reader. The shortcut is read once, as the system writes it (
writtenOn): "⌘K", "Ctrl+K". The caps are not pressed and are no stop of Tab.