Pantrix UI

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

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).

ParameterTypeDefaultWhat it is
shortcutPantrixShortcutthe shortcut whose keys are drawn.
modifierModifierModifierthe caps' modifier.
sizeKeycapsSizeKeycapsSize.Mediumhow large the caps are: KeycapsSize.Medium, for the end of a row, by default.
styleKeycapsStyle?nullthis call's own style: over every enclosing one and under the density. Only the fields it sets change, on every platform.
colorsKeycapsColors?nullthis call's own colours, where they are not the theme's: the ones set here, with the theme's for the rest.
tagKeyString?nullthe 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.

ParameterTypeDefaultWhat it is
shapeShapeSpecShapeSpec.UnspecifiedA cap's shape: ShapeRole.Small, a key's slight rounding.
borderWidthDpDp.UnspecifiedHow wide the edge around a cap is.
gapDpDp.UnspecifiedThe room between two caps.
smallKeycapSizeStyleKeycapSizeStyle()KeycapsSize.Small's room in a cap.
mediumKeycapSizeStyleKeycapSizeStyle()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.

ParameterTypeDefaultWhat it is
containerColorColor.UnspecifiedThe fill of each cap: the theme's background, a step from the surface most rows stand on.
borderColorColor.UnspecifiedThe edge around each cap: the theme's border.
contentColorColor.UnspecifiedThe key's name on the cap: the theme's textSecondary, quieter than the words it stands by.

Accessibility