#[non_exhaustive]pub struct Layout {
pub name: &'static str,
pub entries: &'static [Entry],
pub decimal_separator: char,
pub alternates: &'static [(char, &'static str)],
}Expand description
A keyboard layout: a table of positions, and the decimal key’s character.
#[non_exhaustive], because a layout is a description of a keyboard and
keyboards keep turning out to have one more thing about them worth writing
down. This crate has now added a field twice — the decimal separator, then
the alternates — and the second one broke every struct literal building a
Layout outside it. There is no third time: an added field costs nobody a
compile error from here.
It also says something true about the type. These tables are the layouts
that ship; a caller wanting another writes one here, where the tests that
walk every layout and check it can type its own alphabet will walk that one
too. A Layout assembled elsewhere would have skipped them.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.name: &'static strHuman-readable name, for logging what a device is being read as.
entries: &'static [Entry]Positions, in no particular order. Looked up by linear scan: about fifty comparisons, at most a few times per second, against the complexity of keeping a sorted table sorted.
decimal_separator: charWhat the numpad’s decimal key types. . in most of the world, , in most
of Europe.
alternates: &'static [(char, &'static str)]Accented characters a position can offer when held, by base character.
A fact about the layout rather than about any keyboard: which letters an
o should offer depends on what the writer of this language reaches
for, and a keyboard reading them from here switches its offers when it
switches layout, for free.
Keyed by the lower-case base character rather than by position, because
that is what makes the table readable and what makes KeyCode::Semicolon
offer ø’s relatives on Norwegian and ;’s nothing on US, without the
table having to know where the layout put anything.
The base character is not repeated in its own list — a keyboard shows the key itself alongside these.
Implementations§
Source§impl Layout
impl Layout
Sourcepub fn alternates_for(&self, base: char) -> impl Iterator<Item = char> + use<'_>
pub fn alternates_for(&self, base: char) -> impl Iterator<Item = char> + use<'_>
What holding a position offers, if anything.
Asked with the character the key currently types rather than its
position, so a shifted key offers the shifted forms: hold O and the
answer is ÖØÓ, not öøó. Empty for a position with nothing to offer,
which is most of them.
The case follows the base: a table written in lower case answers in upper for an upper-case base, so one table serves both.
Sourcepub fn entry(&self, code: KeyCode) -> Option<&'static Entry>
pub fn entry(&self, code: KeyCode) -> Option<&'static Entry>
What this layout puts on one position, at each of its four levels.
None for a position no layout describes. Positions the layout does not
list fall back to the shared letter table, so a layout only spells out
what it moves — which is why Layout::entry answers for KeyCode::A on
a table that never mentions it.
An on-screen keyboard reads this to letter its keys: the caller picks the level from the modifiers it is currently showing.