Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Kbd

Layer: atom · Path: src/atoms/kbd.rs · Exports: kbd::Kbd

A keyboard-key chip: mono (kbd) text in a small token-bordered box — e.g. ⌘K, Ctrl, Esc. Modeled on shadcn’s Kbd.

Design

  • Purpose / when to use — display a keyboard shortcut inline (menus, tooltips, command palettes). Read-only.
  • Anatomy — rounded rect (muted fill + border stroke, RADIUS_SM) with (SPACE_2, SPACE_1) padding around a centered kbd-style galley in muted_foreground.
  • Variants / sizes / states — none; single appearance, sense is hover only.
  • Tokens consumedtheme.muted (fill), theme.border (stroke), theme.muted_foreground (text), core::RADIUS_SM, core::SPACE_2/SPACE_1 (padding), core::BORDER_THIN, typography::kbd.
  • Accessibility — bare hover Response; no widget_info.

API

SignatureEffect
Kbd::new(keys: impl Into<String>) -> SelfConstruct with the key text.
.show(self, ui: &mut Ui) -> ResponsePaint and return the hover Response.

Usage

#![allow(unused)]
fn main() {
use ouroboros_ui::atoms::Kbd;

Kbd::new("Esc").show(ui);
Kbd::new("⌘K").show(ui);
}

Composition

Atom: paints the box and builds the text galley inline with the kbd type style. Does not compose Text, though TextRole::Kbd uses the same style.

Notes

  • The whole string is rendered in one chip; for multi-key combos either pass "Ctrl+K" as one string or place several Kbds with separators.

See tokens · theming · typography.