keybinding
Builds KeybindingRecorder SettingsRow SettingsSection


The code that drew it
A still frame holds a repeating animation at its first frame and a one-shot at its last, because a still of a moving thing is not reproducible. Run the gallery to review motion.
fn keybinding(window: &mut Window, cx: &mut App) -> AnyElement {
if !cx.has_global::<SceneRecorders>() {
let idle = cx.new(|cx| {
KeybindingRecorder::new("scene.keybinding.idle", window, cx).label("Open workspace")
});
let recording = cx.new(|cx| {
KeybindingRecorder::new("scene.keybinding.recording", window, cx)
.label("Command palette")
});
let captured = cx.new(|cx| {
KeybindingRecorder::new("scene.keybinding.captured", window, cx)
.label("Toggle terminal")
.binding("ctrl-`")
});
let conflicting = cx.new(|cx| {
KeybindingRecorder::new("scene.keybinding.conflicting", window, cx)
.label("Split editor")
.binding("cmd-shift-p")
// The host's words, not the recorder's: it has no keymap.
.conflict(Some("Already opens the command palette"))
});
// Recording is a state, not a gesture, so the scene puts one recorder
// into it by hand rather than waiting for a keystroke that a still
// image could not photograph anyway.
recording.update(cx, |recorder, cx| recorder.start(window, cx));
cx.set_global(SceneRecorders {
idle,
recording,
captured,
conflicting,
});
}
let recorders = cx.global::<SceneRecorders>().clone();
let theme = cx.theme().clone();
// A recorder carries its name in the tree rather than drawing one, the way
// every other control here does, so the scene puts it where a keymap page
// would: in a settings row that states what the binding is for.
stack(&theme)
.w(px(680.0))
.child(
SettingsSection::new("scene.keybinding.keymap", "Keyboard shortcuts")
.description("Recording captures the next keystroke instead of acting on it.")
.row(
SettingsRow::new("scene.keybinding.row.open", "Open workspace")
.description("Nothing is bound yet")
.control(recorders.idle),
)
.row(
SettingsRow::new("scene.keybinding.row.palette", "Command palette")
.description("Listening for a keystroke")
.control(recorders.recording),
)
.row(
SettingsRow::new("scene.keybinding.row.terminal", "Toggle terminal")
.control(recorders.captured),
)
.row(
SettingsRow::new("scene.keybinding.row.split", "Split editor")
.description("The host judged this one, and said so")
.control(recorders.conflicting),
),
)
.child(caption(
&theme,
"Escape ends recording without capturing, so escape cannot be bound \
unless the caller turns allow_escape on.",
))
.into_any_element()
}