Skip to main content

Layout

Enum Layout 

Source
#[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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

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

Source

pub const ALL: &'static [Layout]

Every layout known to this version of the crate.

Source

pub fn name(self) -> &'static str

Lowercase name of the layout.

assert_eq!(keyhammer::cost::Layout::Abnt2.name(), "abnt2");
Source

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'));

Trait Implementations§

Source§

impl Clone for Layout

Source§

fn clone(&self) -> Layout

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Layout

Source§

impl Debug for Layout

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Layout

Source§

impl Hash for Layout

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Layout

Source§

fn eq(&self, other: &Layout) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Layout

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.