pub enum UserInput {
Single(InputKind),
Chord(PetitSet<InputKind, 8>),
VirtualDPad(VirtualDPad),
}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
Implementations
sourceimpl 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
sourceimpl<'de> Deserialize<'de> for UserInput
impl<'de> Deserialize<'de> for UserInput
sourcefn 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>,
sourceimpl From<MouseMotionDirection> for UserInput
impl From<MouseMotionDirection> for UserInput
sourcefn from(input: MouseMotionDirection) -> Self
fn from(input: MouseMotionDirection) -> Self
sourceimpl From<MouseWheelDirection> for UserInput
impl From<MouseWheelDirection> for UserInput
sourcefn from(input: MouseWheelDirection) -> Self
fn from(input: MouseWheelDirection) -> Self
sourceimpl From<SingleAxis> for UserInput
impl From<SingleAxis> for UserInput
sourcefn from(input: SingleAxis) -> Self
fn from(input: SingleAxis) -> Self
sourceimpl From<VirtualDPad> for UserInput
impl From<VirtualDPad> for UserInput
sourcefn from(input: VirtualDPad) -> Self
fn from(input: VirtualDPad) -> Self
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: &HashMap<Handle<Image>, <Image as RenderAsset>::PreparedAsset, RandomState, Global>
) -> U
fn as_bind_group_shader_type(
&self,
_images: &HashMap<Handle<Image>, <Image as RenderAsset>::PreparedAsset, RandomState, Global>
) -> U
T [ShaderType] for self. When used in [AsBindGroup]
derives, it is safe to assume that all images in self exist. Read moresourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
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. Read morefn 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. Read morefn 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. Read morefn 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. Read moreimpl<T> DynHash for Twhere
T: DynEq + Hash,
impl<T> DynHash for Twhere
T: DynEq + Hash,
sourceimpl<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,
sourcefn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.