pub enum UserInput {
Single(InputKind),
Chord(Box<PetitSet<InputKind, 8>>),
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(Box<PetitSet<InputKind, 8>>)
A combination of buttons, pressed simultaneously
Up to 8 (!!) buttons can be chorded together at once.
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
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 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([ControlLeft.into(), AltLeft.into()]);
let a: UserInput = A.into();
let ctrl_a = UserInput::chord([ControlLeft, A]);
let ctrl_alt_a = UserInput::chord([ControlLeft, AltLeft, 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 for UserInput
impl PartialEq 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 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> CallHasher for T
impl<T> CallHasher for 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<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
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.