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 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 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
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>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl From<MouseMotionDirection> for UserInput
impl From<MouseMotionDirection> for UserInput
sourcefn from(input: MouseMotionDirection) -> Self
fn from(input: MouseMotionDirection) -> Self
Converts to this type from the input type.
sourceimpl From<MouseWheelDirection> for UserInput
impl From<MouseWheelDirection> for UserInput
sourcefn from(input: MouseWheelDirection) -> Self
fn from(input: MouseWheelDirection) -> Self
Converts to this type from the input type.
sourceimpl From<SingleAxis> for UserInput
impl From<SingleAxis> for UserInput
sourcefn from(input: SingleAxis) -> Self
fn from(input: SingleAxis) -> Self
Converts to this type from the input type.
sourceimpl From<VirtualDPad> for UserInput
impl From<VirtualDPad> for UserInput
sourcefn from(input: VirtualDPad) -> Self
fn from(input: VirtualDPad) -> Self
Converts to this type from the input type.
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 T where
U: ShaderType,
&'a T: for<'a> Into<U>,
impl<T, U> AsBindGroupShaderType<U> for T where
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
Return the T
[ShaderType
] for self
. When used in [AsBindGroup
]
derives, it is safe to assume that all images in self
exist. Read more
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T> Downcast for T where
T: Any,
impl<T> Downcast for T where
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>
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
. Read more
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Convert Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
. Read more
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. Read more
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. Read more
impl<T> DynHash for T where
T: DynEq + Hash,
impl<T> DynHash for T where
T: DynEq + Hash,
sourceimpl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
sourcefn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to key
and return true
if they are equal.
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> Serialize for T where
T: Serialize + ?Sized,
impl<T> Serialize for T where
T: Serialize + ?Sized,
fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<Ok, Error>
impl<T> TypeData for T where
T: 'static + Send + Sync + Clone,
impl<T> TypeData for T where
T: 'static + Send + Sync + Clone,
fn clone_type_data(&self) -> Box<dyn TypeData + 'static, Global>
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more