#[non_exhaustive]pub enum Layout {
Qwerty,
Qwertz,
Azerty,
Abnt2,
Dvorak,
Colemak,
}Expand description
A physical keyboard layout, from which the neighbouring-key relation of a
CostModel is derived.
§Geometry
Only the three letter rows are modelled (top, home, bottom). Every key is one unit wide and rows are shifted by half keys: offsets of 0, 0.5 and 1 key widths for every layout here. That rounds the real stagger of an ANSI board (0, 0.25 and 0.75) so that the derived relation equals the one QWERTY has always had in this crate. Two keys are neighbours when
- they are next to each other in a row, or
- they are in consecutive rows and their centres are at most half a key apart (a key touches two keys of the next row, or one at the end of a row).
The relation is symmetric and irreflexive by construction.
§What is and is not covered
Every modelled key counts, letters a to z and others alike: ç on
ABNT2 (next to l and p, and to . and ; below it), ù on AZERTY
(after m), ü on QWERTZ (after p) and ö, ä (after l), and the
punctuation keys of the ABNT2 bottom row, of Dvorak and of Colemak. The
search compares Unicode code points (docs/design/unicode.md), so a
query with ç for a term with l is a neighbouring-key substitution on
ABNT2. Keys are lowercase: an uppercase letter is a different symbol,
with no neighbours, unless the text is case folded (see
crate::text::Normalizer). With diacritic folding on (the default),
ç, ù, ü, ö and ä never reach the search (they become c, u,
u, o and a), so these neighbours only matter without it.
Not modelled at all: the number row, the extra ISO key beside the left shift, the punctuation columns after the letter rows of QWERTY, QWERTZ and AZERTY and after the top row of ABNT2, modifiers, dead keys and AltGr layers. The unit costs are the same for every layout and remain provisional.
The pairs of two letters a-z of ABNT2 are those of QWERTY; the layouts
differ by ç and the punctuation keys.
§Examples
use keyhammer::cost::Layout;
assert!(Layout::Qwerty.are_neighbours('a', 's'));
assert!(!Layout::Qwerty.are_neighbours('a', 'd'));
// ç sits next to l and p on ABNT2.
assert!(Layout::Abnt2.are_neighbours('l', 'ç'));
assert!(Layout::Abnt2.are_neighbours('ç', 'p'));
// ù follows m on AZERTY, ö follows l on QWERTZ.
assert!(Layout::Azerty.are_neighbours('m', 'ù'));
assert!(Layout::Qwertz.are_neighbours('l', 'ö'));
// QWERTZ swaps y and z: z now sits beside t, u, g and h.
assert!(Layout::Qwertz.are_neighbours('z', 't'));
assert!(!Layout::Qwerty.are_neighbours('z', 't'));
// Dvorak: home row is a o e u i d h t n s.
assert!(Layout::Dvorak.are_neighbours('u', 'i'));
// Colemak: home row is a r s t d h n e i o.
assert!(Layout::Colemak.are_neighbours('r', 's'));Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Qwerty
ANSI QWERTY, the default.
Qwertz
QWERTZ (German): y and z swapped relative to QWERTY, ü after p
and ö, ä after l.
Azerty
AZERTY (French): a/q and z/w swapped, m and ù on the home
row.
Abnt2
Brazilian ABNT2: the QWERTY letters, plus ç after l and the
punctuation keys , . ; after m.
Dvorak
Dvorak (US).
Colemak
Colemak (US).
Implementations§
Source§impl Layout
impl Layout
Sourcepub fn name(self) -> &'static str
pub fn name(self) -> &'static str
Lowercase name of the layout.
assert_eq!(keyhammer::cost::Layout::Abnt2.name(), "abnt2");Sourcepub fn are_neighbours(self, a: char, b: char) -> bool
pub fn are_neighbours(self, a: char, b: char) -> bool
Whether keys a and b are neighbours on this layout. false for a
key that is not on the modelled rows and for a == b. The cost model
of CostModel::for_layout uses exactly this relation.
use keyhammer::cost::Layout;
assert!(Layout::Azerty.are_neighbours('q', 'z')); // not so on QWERTY
assert!(!Layout::Qwerty.are_neighbours('q', 'z'));
assert!(!Layout::Qwerty.are_neighbours('q', 'q'));