agg_gui/widgets/on_screen_keyboard/key.rs
1//! Individual key cell — geometry, label, and the action a tap commits.
2
3use crate::geometry::Rect;
4
5use super::layouts::Layer;
6
7/// What happens when the user releases a tap on this key.
8#[derive(Debug, Clone, Copy)]
9pub enum KeyAction {
10 /// Insert a literal character at the focused widget's cursor. The
11 /// keyboard synthesizes `Event::KeyDown { Key::Char(c), … }` for
12 /// every letter / digit / punctuation key.
13 Char(char),
14 /// Delete one character / grapheme to the left of the cursor.
15 Backspace,
16 /// Submit the form / accept the value. The host widget (TextField,
17 /// TextArea) decides what "submit" means.
18 Enter,
19 /// Insert a single space — kept separate from `Char(' ')` because
20 /// the visual / layout treatment for the spacebar is special.
21 Space,
22 /// Switch the visible layer (letters / shift / numbers / symbols).
23 /// Internal to the keyboard; never reaches the focused widget.
24 Switch(Layer),
25 /// Dismiss the keyboard (no-op on the focused widget). Maps to the
26 /// "downward chevron" key common on iOS keyboards.
27 Dismiss,
28}
29
30/// Visual label rendered on a key. Either text or a tiny glyph.
31#[derive(Debug, Clone)]
32pub enum KeyCap {
33 /// A single character or short word ("space", "ABC", "123").
34 Text(String),
35 /// A vector glyph drawn by `key::paint_glyph`. Used for keys whose
36 /// label is a symbol that doesn't have a satisfying Unicode form
37 /// (e.g. iOS / Android backspace, return arrow).
38 Glyph(KeyGlyph),
39}
40
41/// Built-in glyphs the keyboard paints procedurally (no font lookup
42/// required so the keyboard renders even before the host app has
43/// installed a typeface).
44#[derive(Debug, Clone, Copy)]
45pub enum KeyGlyph {
46 /// Left-pointing chevron with an X — backspace.
47 Backspace,
48 /// Up-arrow into a horizontal bar — shift.
49 Shift,
50 /// Down-pointing chevron — dismiss keyboard.
51 DismissDown,
52 /// Bent arrow — return / enter.
53 Return,
54}
55
56/// One key cell positioned and painted by the layout engine. Stored in
57/// [`super::state::KeyboardState::last_painted_keys`] so taps can be
58/// hit-tested in O(n).
59#[derive(Debug, Clone)]
60pub struct PaintedKey {
61 /// Hit-test rectangle in viewport coordinates (Y-up).
62 pub rect: Rect,
63 /// Action committed on release.
64 pub action: KeyAction,
65 /// Cap as it was painted (kept for inspection / accessibility).
66 #[allow(dead_code)]
67 pub cap: KeyCap,
68}