pub enum UserInput {
Single(InputKind),
Chord(PetitSet<InputKind, 8>),
VirtualDPad(VirtualDPad),
VirtualAxis(VirtualAxis),
}Expand description
Some combination of user input, which may cross [Input]-mode boundaries
Suitable for use in an InputMap
Variants§
Single(InputKind)
A single button
Chord(PetitSet<InputKind, 8>)
A combination of buttons, pressed simultaneously
Up to 8 (!!) buttons can be chorded together at once. Chords are considered to belong to all of the [InputMode]s of their constituent buttons.
VirtualDPad(VirtualDPad)
A virtual DPad that you can get an [AxisPair] from
VirtualAxis(VirtualAxis)
A virtual axis that you can get a SingleAxis from
Implementations§
source§impl UserInput
impl UserInput
sourcepub fn modified(modifier: Modifier, input: impl Into<InputKind>) -> UserInput
pub fn modified(modifier: Modifier, input: impl Into<InputKind>) -> UserInput
Creates a UserInput::Chord from a Modifier and an input that can be converted into an InputKind
When working with keyboard modifiers, should be preferred over manually specifying both the left and right variant.
sourcepub fn chord(inputs: impl IntoIterator<Item = impl Into<InputKind>>) -> Self
pub fn chord(inputs: impl IntoIterator<Item = impl Into<InputKind>>) -> Self
Creates a UserInput::Chord from an iterator of inputs of the same type that can be converted into an InputKinds
If inputs has a length of 1, a UserInput::Single variant will be returned instead.
sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
The number of logical inputs that make up the UserInput.
- A
Singleinput returns 1 - A
Chordreturns the number of buttons in the chord - A
VirtualDPadreturns 1
sourcepub fn n_matching(&self, buttons: &HashSet<InputKind>) -> usize
pub fn n_matching(&self, buttons: &HashSet<InputKind>) -> usize
How many of the provided buttons are found in the UserInput
Example
use bevy::input::keyboard::KeyCode::*;
use bevy::utils::HashSet;
use leafwing_input_manager::user_input::UserInput;
let buttons = HashSet::from_iter([LControl.into(), LAlt.into()]);
let a: UserInput = A.into();
let ctrl_a = UserInput::chord([LControl, A]);
let ctrl_alt_a = UserInput::chord([LControl, LAlt, A]);
assert_eq!(a.n_matching(&buttons), 0);
assert_eq!(ctrl_a.n_matching(&buttons), 1);
assert_eq!(ctrl_alt_a.n_matching(&buttons), 2);sourcepub fn raw_inputs(&self) -> RawInputs
pub fn raw_inputs(&self) -> RawInputs
Returns the raw inputs that make up this UserInput
Trait Implementations§
source§impl<'de> Deserialize<'de> for UserInput
impl<'de> Deserialize<'de> for UserInput
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,
source§impl From<MouseMotionDirection> for UserInput
impl From<MouseMotionDirection> for UserInput
source§fn from(input: MouseMotionDirection) -> Self
fn from(input: MouseMotionDirection) -> Self
source§impl From<MouseWheelDirection> for UserInput
impl From<MouseWheelDirection> for UserInput
source§fn from(input: MouseWheelDirection) -> Self
fn from(input: MouseWheelDirection) -> Self
source§impl From<QwertyScanCode> for UserInput
impl From<QwertyScanCode> for UserInput
source§fn from(input: QwertyScanCode) -> Self
fn from(input: QwertyScanCode) -> Self
source§impl From<SingleAxis> for UserInput
impl From<SingleAxis> for UserInput
source§fn from(input: SingleAxis) -> Self
fn from(input: SingleAxis) -> Self
source§impl From<VirtualAxis> for UserInput
impl From<VirtualAxis> for UserInput
source§fn from(input: VirtualAxis) -> Self
fn from(input: VirtualAxis) -> Self
source§impl From<VirtualDPad> for UserInput
impl From<VirtualDPad> for UserInput
source§fn from(input: VirtualDPad) -> Self
fn from(input: VirtualDPad) -> Self
source§impl PartialEq<UserInput> for UserInput
impl PartialEq<UserInput> for UserInput
impl Eq for UserInput
impl StructuralEq for UserInput
impl StructuralPartialEq for UserInput
Auto Trait Implementations§
impl RefUnwindSafe for UserInput
impl Send for UserInput
impl Sync for UserInput
impl Unpin for UserInput
impl UnwindSafe for UserInput
Blanket Implementations§
§impl<T, U> AsBindGroupShaderType<U> for Twhere
U: ShaderType,
&'a T: for<'a> Into<U>,
impl<T, U> AsBindGroupShaderType<U> for Twhere U: ShaderType, &'a T: for<'a> Into<U>,
§fn as_bind_group_shader_type(&self, _images: &RenderAssets<Image>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<Image>) -> U
T [ShaderType] for self. When used in [AsBindGroup]
derives, it is safe to assume that all images in self exist.§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere T: Any,
§fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
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.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.