pub struct Custom {
pub bit: u8,
pub keys: Cow<'static, [Key]>,
pub pad: Cow<'static, [Button]>,
}Expand description
A button of your game’s own (attack, interact, …): which Intent bit, and the keys
and gamepad buttons that set it. Fixed ones can be const; rebound ones are built at
runtime (Scheme::bind).
use std::borrow::Cow;
use game_toolkit::prelude::{Button, Key};
use game_toolkit_platformer::controls::{Custom, Scheme};
const ATTACK: u8 = 0;
const SCHEME: Scheme = Scheme {
custom: Cow::Borrowed(&[Custom::new(ATTACK, &[Key::KeyX], &[Button::West])]),
..Scheme::SNAPPY
};
assert_eq!(SCHEME.custom.len(), 1);
// A rebinding menu: attack on V from now on, the pad as it was.
let mut scheme = SCHEME;
scheme.bind(ATTACK, vec![Key::KeyV], &[Button::West][..]);
assert_eq!(scheme.custom[0].keys[..], [Key::KeyV]);
scheme.bind(1, &[Key::KeyB][..], vec![]); // a second button, added
assert_eq!(scheme.custom.len(), 2);Fields§
§bit: u8The bit in Intent::custom and Intent::custom_pressed, 0 to 31.
keys: Cow<'static, [Key]>Keys.
pad: Cow<'static, [Button]>Gamepad buttons.
Implementations§
Trait Implementations§
impl StructuralPartialEq for Custom
Auto Trait Implementations§
impl Freeze for Custom
impl RefUnwindSafe for Custom
impl Send for Custom
impl Sync for Custom
impl Unpin for Custom
impl UnsafeUnpin for Custom
impl UnwindSafe for Custom
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.