Skip to main content

Keymap

Struct Keymap 

Source
pub struct Keymap<A: ActionSet> { /* private fields */ }
Expand description

Lookup from chord, and from controller button or button chord, to actions, plus repeat and chord timings. A chord or button is on at most one action of each group (game ADR-0068), so one press can give an action of each group: the screen on top reacts to the ones it uses.

Implementations§

Source§

impl<A: ActionSet> Keymap<A>

Source

pub fn new( bindings: impl IntoIterator<Item = (Chord, A)>, repeat: RepeatDef, ) -> Self

A keymap with bindings plus the game’s fixed keys. A chord listed twice for one group keeps its last action of that group; reserved chords (plain Escape and Delete) are left out.

Source

pub fn with_pad<B: Into<ButtonChord>>( self, pad: impl IntoIterator<Item = (B, A)>, ) -> Self

This keymap with pad as its controller buttons and button chords, replacing any it had. A button or chord listed twice for one group keeps its last action of that group.

Source

pub fn with_chord(self, chord: ChordDef) -> Self

This keymap with chord as its button chords’ timing.

Source

pub fn with_default_pad(self, def: &KeymapDef<A>) -> Self

This keymap with the default controller buttons from a validated keymap definition (the same in every layout and the layout picker) and its chord timing.

Source

pub fn for_layout(def: &KeymapDef<A>, layout: Layout) -> Self

layout’s default bindings from a validated keymap definition (no player changes; for those see PlayerKeys), with its repeat timings and the default controller buttons. A definition without that layout gives a keymap with only the fixed keys and the buttons.

Source

pub fn layout_picker(def: &KeymapDef<A>) -> Self

The keys that work before any layout is chosen, from the keymap definition’s layout_picker section, so the layout picker can be used whichever hand the player types with. Actions it doesn’t list have no key. The controller buttons are the default ones, as in every layout.

Source

pub fn actions(&self, chord: Chord) -> &[A]

The actions bound to chord, one at most of each group, in group order. Shift+h and h are distinct: there is no fallback from a shifted chord to the plain one.

Source

pub fn action(&self, chord: Chord) -> Option<A>

The first of actions, if any: the only one for a chord of a single group.

Source

pub fn pad_actions(&self, button: Button) -> &[A]

The actions bound to the controller button button on its own, as actions.

Source

pub fn pad_action(&self, button: Button) -> Option<A>

The first of pad_actions, if any.

Source

pub fn chord_actions(&self, chord: ButtonChord) -> &[A]

The actions bound to chord (a button chord, or one button), as actions.

Source

pub fn buttons_for(&self, action: A) -> Vec<ButtonChord>

Every controller button and button chord bound to action, in the order they were given (file order for the keymap file).

Source

pub fn repeat(&self) -> RepeatDef

Key-repeat timings.

Source

pub fn chord(&self) -> ChordDef

Button chords’ timing.

Source

pub fn chord_wait(&self, button: Button) -> ChordWait

How long button holds back its own actions when pressed, so that a button chord with it can fire instead (ticket 1034). A button in no chord, or whose own action repeats (the D-pad on the cursor), acts on press. Otherwise it waits until it is let go if a partner of its acts on press (B in B+←: hold it as long as you like before ←) or it has no action of its own; else for the chord window or its release, whichever is first (A in A+B). A pad with no chords acts on press throughout, exactly as before chords.

Source

pub fn chords_for(&self, action: A) -> Vec<Chord>

Every chord bound to action (its key slots), in the order they were given: slot order for the player’s bindings, file order for the keymap file. Leaves out the fixed keys (see fixed_chords_for).

Source

pub fn fixed_chords_for(action: A) -> Vec<Chord>

The fixed chords that also trigger action in every keymap and can’t be rebound.

Source

pub fn cursor_keys_name(&self, arrows_name: &str) -> Option<String>

What moves the cursor, for help text: arrows (the language’s word for them) when the primary chords of the actions the game takes for up, left, down and right are the plain arrow keys, otherwise those chords in up-left-down-right order (wasd). None if any of them is unbound, or the game has no such action. Lives here, not with the help text, because it names keys.

Source

pub fn cursor_buttons_name(&self, kind: PadKind) -> Option<String>

What moves the cursor on a pad of kind, for help text: the whole sets of direction buttons the four cursor actions are on, joined with / (D-pad/L-stick with this game’s defaults); if they are on no whole set, each one’s primary_button’s name in up-left-down-right order. None if any cursor action has no button.

Source

pub fn primary_button(&self, action: A) -> Option<ButtonChord>

The button (or button chord) help text names for action: the first of buttons_for, or None if it has none.

Source

pub fn primary(&self, action: A) -> Option<Chord>

The chord help text names for action: the first of chords_for, or None if it has none.

Source

pub fn has_input(&self, action: A, device: Device) -> bool

Whether action has a key (keyboard) or a button (pad) for device.

Trait Implementations§

Source§

impl<A: Clone + ActionSet> Clone for Keymap<A>

Source§

fn clone(&self) -> Keymap<A>

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<A: Debug + ActionSet> Debug for Keymap<A>

Source§

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

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

impl<A: Eq + ActionSet> Eq for Keymap<A>

Source§

impl<A: PartialEq + ActionSet> PartialEq for Keymap<A>

Source§

fn eq(&self, other: &Keymap<A>) -> bool

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

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

Inequality operator !=. Read more
Source§

impl<A: PartialEq + ActionSet> StructuralPartialEq for Keymap<A>

Auto Trait Implementations§

§

impl<A> Freeze for Keymap<A>

§

impl<A> RefUnwindSafe for Keymap<A>
where A: RefUnwindSafe,

§

impl<A> Send for Keymap<A>
where A: Send,

§

impl<A> Sync for Keymap<A>
where A: Sync,

§

impl<A> Unpin for Keymap<A>

§

impl<A> UnsafeUnpin for Keymap<A>

§

impl<A> UnwindSafe for Keymap<A>
where A: RefUnwindSafe,

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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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.