pub enum UserInput {
Single(InputKind),
Chord(Vec<InputKind>),
VirtualDPad(VirtualDPad),
VirtualAxis(VirtualAxis),
}
Expand description
Some combination of user input, which may cross input-mode boundaries.
For example, this may store mouse, keyboard or gamepad input, including cross-device chords!
Suitable for use in an InputMap
Variants§
Single(InputKind)
A single button
Chord(Vec<InputKind>)
A combination of buttons, pressed simultaneously
VirtualDPad(VirtualDPad)
A virtual DPad that you can get an DualAxis
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
which can be converted into an InputKind
When working with keyboard modifiers, should be preferred to 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 over inputs of the same type convertible into an InputKind
s
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
Single
input returns 1 - A
Chord
returns the number of buttons in the chord - A
VirtualDPad
returns 1 - A
VirtualAxis
returns 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([ControlLeft.into(), AltLeft.into()]);
let a: UserInput = KeyA.into();
let ctrl_a = UserInput::chord([ControlLeft, KeyA]);
let ctrl_alt_a = UserInput::chord([ControlLeft, AltLeft, KeyA]);
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 Enum for UserInputwhere
Self: Any + Send + Sync,
InputKind: FromReflect + TypePath,
Vec<InputKind>: FromReflect + TypePath,
VirtualDPad: FromReflect + TypePath,
VirtualAxis: FromReflect + TypePath,
impl Enum for UserInputwhere
Self: Any + Send + Sync,
InputKind: FromReflect + TypePath,
Vec<InputKind>: FromReflect + TypePath,
VirtualDPad: FromReflect + TypePath,
VirtualAxis: FromReflect + TypePath,
source§fn field(&self, __name_param: &str) -> Option<&dyn Reflect>
fn field(&self, __name_param: &str) -> Option<&dyn Reflect>
source§fn field_at(&self, __index_param: usize) -> Option<&dyn Reflect>
fn field_at(&self, __index_param: usize) -> Option<&dyn Reflect>
source§fn field_mut(&mut self, __name_param: &str) -> Option<&mut dyn Reflect>
fn field_mut(&mut self, __name_param: &str) -> Option<&mut dyn Reflect>
source§fn field_at_mut(&mut self, __index_param: usize) -> Option<&mut dyn Reflect>
fn field_at_mut(&mut self, __index_param: usize) -> Option<&mut dyn Reflect>
source§fn index_of(&self, __name_param: &str) -> Option<usize>
fn index_of(&self, __name_param: &str) -> Option<usize>
source§fn name_at(&self, __index_param: usize) -> Option<&str>
fn name_at(&self, __index_param: usize) -> Option<&str>
source§fn iter_fields(&self) -> VariantFieldIter<'_>
fn iter_fields(&self) -> VariantFieldIter<'_>
source§fn variant_name(&self) -> &str
fn variant_name(&self) -> &str
source§fn variant_index(&self) -> usize
fn variant_index(&self) -> usize
source§fn variant_type(&self) -> VariantType
fn variant_type(&self) -> VariantType
fn clone_dynamic(&self) -> DynamicEnum
§fn is_variant(&self, variant_type: VariantType) -> bool
fn is_variant(&self, variant_type: VariantType) -> bool
§fn variant_path(&self) -> String
fn variant_path(&self) -> String
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<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 FromReflect for UserInputwhere
Self: Any + Send + Sync,
InputKind: FromReflect + TypePath,
Vec<InputKind>: FromReflect + TypePath,
VirtualDPad: FromReflect + TypePath,
VirtualAxis: FromReflect + TypePath,
impl FromReflect for UserInputwhere
Self: Any + Send + Sync,
InputKind: FromReflect + TypePath,
Vec<InputKind>: FromReflect + TypePath,
VirtualDPad: FromReflect + TypePath,
VirtualAxis: FromReflect + TypePath,
source§fn from_reflect(__param0: &dyn Reflect) -> Option<Self>
fn from_reflect(__param0: &dyn Reflect) -> Option<Self>
Self
from a reflected value.§fn take_from_reflect(
reflect: Box<dyn Reflect>
) -> Result<Self, Box<dyn Reflect>>
fn take_from_reflect( reflect: Box<dyn Reflect> ) -> Result<Self, Box<dyn Reflect>>
Self
using,
constructing the value using from_reflect
if that fails. Read moresource§impl GetTypeRegistration for UserInputwhere
Self: Any + Send + Sync,
InputKind: FromReflect + TypePath,
Vec<InputKind>: FromReflect + TypePath,
VirtualDPad: FromReflect + TypePath,
VirtualAxis: FromReflect + TypePath,
impl GetTypeRegistration for UserInputwhere
Self: Any + Send + Sync,
InputKind: FromReflect + TypePath,
Vec<InputKind>: FromReflect + TypePath,
VirtualDPad: FromReflect + TypePath,
VirtualAxis: FromReflect + TypePath,
fn get_type_registration() -> TypeRegistration
source§impl PartialEq for UserInput
impl PartialEq for UserInput
source§impl Reflect for UserInputwhere
Self: Any + Send + Sync,
InputKind: FromReflect + TypePath,
Vec<InputKind>: FromReflect + TypePath,
VirtualDPad: FromReflect + TypePath,
VirtualAxis: FromReflect + TypePath,
impl Reflect for UserInputwhere
Self: Any + Send + Sync,
InputKind: FromReflect + TypePath,
Vec<InputKind>: FromReflect + TypePath,
VirtualDPad: FromReflect + TypePath,
VirtualAxis: FromReflect + TypePath,
source§fn get_represented_type_info(&self) -> Option<&'static TypeInfo>
fn get_represented_type_info(&self) -> Option<&'static TypeInfo>
TypeInfo
] of the type represented by this value. Read moresource§fn as_any_mut(&mut self) -> &mut dyn Any
fn as_any_mut(&mut self) -> &mut dyn Any
&mut dyn Any
.source§fn into_reflect(self: Box<Self>) -> Box<dyn Reflect>
fn into_reflect(self: Box<Self>) -> Box<dyn Reflect>
source§fn as_reflect(&self) -> &dyn Reflect
fn as_reflect(&self) -> &dyn Reflect
source§fn as_reflect_mut(&mut self) -> &mut dyn Reflect
fn as_reflect_mut(&mut self) -> &mut dyn Reflect
source§fn clone_value(&self) -> Box<dyn Reflect>
fn clone_value(&self) -> Box<dyn Reflect>
Reflect
trait object. Read moresource§fn set(
&mut self,
__value_param: Box<dyn Reflect>
) -> Result<(), Box<dyn Reflect>>
fn set( &mut self, __value_param: Box<dyn Reflect> ) -> Result<(), Box<dyn Reflect>>
source§fn apply(&mut self, __value_param: &dyn Reflect)
fn apply(&mut self, __value_param: &dyn Reflect)
source§fn reflect_kind(&self) -> ReflectKind
fn reflect_kind(&self) -> ReflectKind
source§fn reflect_ref(&self) -> ReflectRef<'_>
fn reflect_ref(&self) -> ReflectRef<'_>
source§fn reflect_mut(&mut self) -> ReflectMut<'_>
fn reflect_mut(&mut self) -> ReflectMut<'_>
source§fn reflect_owned(self: Box<Self>) -> ReflectOwned
fn reflect_owned(self: Box<Self>) -> ReflectOwned
source§fn reflect_hash(&self) -> Option<u64>
fn reflect_hash(&self) -> Option<u64>
source§fn reflect_partial_eq(&self, value: &dyn Reflect) -> Option<bool>
fn reflect_partial_eq(&self, value: &dyn Reflect) -> Option<bool>
§fn debug(&self, f: &mut Formatter<'_>) -> Result<(), Error>
fn debug(&self, f: &mut Formatter<'_>) -> Result<(), Error>
§fn serializable(&self) -> Option<Serializable<'_>>
fn serializable(&self) -> Option<Serializable<'_>>
§fn is_dynamic(&self) -> bool
fn is_dynamic(&self) -> bool
source§impl TypePath for UserInput
impl TypePath for UserInput
source§fn type_path() -> &'static str
fn type_path() -> &'static str
source§fn short_type_path() -> &'static str
fn short_type_path() -> &'static str
source§fn type_ident() -> Option<&'static str>
fn type_ident() -> Option<&'static str>
source§fn crate_name() -> Option<&'static str>
fn crate_name() -> Option<&'static str>
source§impl Typed for UserInputwhere
Self: Any + Send + Sync,
InputKind: FromReflect + TypePath,
Vec<InputKind>: FromReflect + TypePath,
VirtualDPad: FromReflect + TypePath,
VirtualAxis: FromReflect + TypePath,
impl Typed for UserInputwhere
Self: Any + Send + Sync,
InputKind: FromReflect + TypePath,
Vec<InputKind>: FromReflect + TypePath,
VirtualDPad: FromReflect + TypePath,
VirtualAxis: FromReflect + TypePath,
impl Eq 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 T
impl<T, U> AsBindGroupShaderType<U> for T
§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.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
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> DynEq for T
impl<T> DynEq for T
§impl<T> DynamicTypePath for Twhere
T: TypePath,
impl<T> DynamicTypePath for Twhere
T: TypePath,
§fn reflect_type_path(&self) -> &str
fn reflect_type_path(&self) -> &str
TypePath::type_path
].§fn reflect_short_type_path(&self) -> &str
fn reflect_short_type_path(&self) -> &str
TypePath::short_type_path
].§fn reflect_type_ident(&self) -> Option<&str>
fn reflect_type_ident(&self) -> Option<&str>
TypePath::type_ident
].§fn reflect_crate_name(&self) -> Option<&str>
fn reflect_crate_name(&self) -> Option<&str>
TypePath::crate_name
].§fn reflect_module_path(&self) -> Option<&str>
fn reflect_module_path(&self) -> Option<&str>
TypePath::module_path
].§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<T> GetPath for Twhere
T: Reflect + ?Sized,
impl<T> GetPath for Twhere
T: Reflect + ?Sized,
§fn reflect_path<'p>(
&self,
path: impl ReflectPath<'p>
) -> Result<&(dyn Reflect + 'static), ReflectPathError<'p>>
fn reflect_path<'p>( &self, path: impl ReflectPath<'p> ) -> Result<&(dyn Reflect + 'static), ReflectPathError<'p>>
path
. Read more§fn reflect_path_mut<'p>(
&mut self,
path: impl ReflectPath<'p>
) -> Result<&mut (dyn Reflect + 'static), ReflectPathError<'p>>
fn reflect_path_mut<'p>( &mut self, path: impl ReflectPath<'p> ) -> Result<&mut (dyn Reflect + 'static), ReflectPathError<'p>>
path
. Read more