Expand description
A PS4-style on-screen keyboard: QWERTY, a Shift toggle for case, a symbols
page, a wide Space bar, plus Backspace and OK keys, with a boxed selection.
The D-pad moves the highlight; the caller feeds it Keyboard::activate.
Promoted from PSXcel, which built it for cell text entry; any game that names saves, enters high scores, or takes chat text wants the same thing (zelda3-psx hand-rolled a name-entry grid; gh-psx will want score names). Nav between rows maps by horizontal key centre so a wide key (Space) lines up sensibly with the narrow keys above it.
Rendering assumes a 320-wide display and psx-font’s 8x8 glyph cell; the
keyboard occupies the bottom PANEL_HEIGHT pixels. Colors come from a
caller-supplied Palette, so any game theme drops in.
let mut kb = Keyboard::new();
// per frame:
if pad.repeats(button::LEFT, 14, 3) { kb.step(Direction::Left); }
if pad.just_pressed(button::CROSS) {
match kb.activate() {
Action::Insert(ch) => text.push(ch),
Action::Backspace => text.pop(),
Action::Commit => return Some(text),
Action::None => {}
}
}
kb.draw(&font, &Palette::GRAY, "X:Type SQ:Del R2:OK");Structs§
- Keyboard
- The keyboard state machine: highlight position + page/case toggles.
- Palette
- Colors for the keyboard panel; all
(r, g, b).
Enums§
- Action
- What pressing the highlighted key does. Toggles (Shift/Sym) return
None. - Direction
- D-pad direction for
Keyboard::step.
Constants§
- PANEL_
HEIGHT - Height of the whole panel as
drawpaints it: the hint line, the key rows and the margin below them, down to the bottom of a 240-line display. - PANEL_
TOP - Top edge of the panel as
drawpaints it on a 240-line display. A game keeps its own content above this line. - Y0
Deprecated - The top of the key rows, 14 pixels below
PANEL_TOP. It was documented as the panel’s top edge and callers subtract the hint line from it (Y0 - 14); that isPANEL_TOP, so usePANEL_TOPand drop the subtraction.