pub struct ButtonlikeChord(/* private fields */);
Expand description
A combined input that groups multiple Buttonlike
s together,
allowing you to define complex input combinations like hotkeys, shortcuts, and macros.
A chord is pressed only if all its constituent buttons are pressed simultaneously.
Adding duplicate buttons within a chord will ignore the extras, preventing redundant data fetching from multiple instances of the same input.
use bevy::prelude::*;
use bevy::input::InputPlugin;
use leafwing_input_manager::plugin::{AccumulatorPlugin, CentralInputStorePlugin};
use leafwing_input_manager::prelude::*;
use leafwing_input_manager::user_input::testing_utils::FetchUserInput;
let mut app = App::new();
app.add_plugins((InputPlugin, AccumulatorPlugin, CentralInputStorePlugin));
// Define a chord using A and B keys
let input = ButtonlikeChord::new([KeyCode::KeyA, KeyCode::KeyB]);
// Pressing only one key doesn't activate the input
KeyCode::KeyA.press(app.world_mut());
app.update();
assert!(!app.read_pressed(input.clone()));
// Pressing both keys activates the input
KeyCode::KeyA.press(app.world_mut());
KeyCode::KeyB.press(app.world_mut());
app.update();
assert!(app.read_pressed(input.clone()));
Implementations§
source§impl ButtonlikeChord
impl ButtonlikeChord
sourcepub fn new<U: Buttonlike>(inputs: impl IntoIterator<Item = U>) -> Self
pub fn new<U: Buttonlike>(inputs: impl IntoIterator<Item = U>) -> Self
Creates a ButtonlikeChord
from multiple Buttonlike
s, avoiding duplicates.
Note that all elements within the iterator must be of the same type (homogeneous).
You can still use other methods to add different types of inputs into the chord.
sourcepub fn from_single(input: impl Buttonlike) -> Self
pub fn from_single(input: impl Buttonlike) -> Self
Creates a ButtonlikeChord
that only contains the given Buttonlike
.
You can still use other methods to add different types of inputs into the chord.
sourcepub fn modified(modifier: ModifierKey, input: impl Buttonlike) -> Self
pub fn modified(modifier: ModifierKey, input: impl Buttonlike) -> Self
Creates a ButtonlikeChord
that combines the provided modifier and the given Buttonlike
.
sourcepub fn with(self, input: impl Buttonlike) -> Self
pub fn with(self, input: impl Buttonlike) -> Self
Adds the given Buttonlike
into this chord, avoiding duplicates.
sourcepub fn with_multiple<U: Buttonlike>(
self,
inputs: impl IntoIterator<Item = U>,
) -> Self
pub fn with_multiple<U: Buttonlike>( self, inputs: impl IntoIterator<Item = U>, ) -> Self
Adds multiple Buttonlike
s into this chord, avoiding duplicates.
Note that all elements within the iterator must be of the same type (homogeneous).
Trait Implementations§
source§impl Buttonlike for ButtonlikeChord
impl Buttonlike for ButtonlikeChord
source§fn pressed(&self, input_store: &CentralInputStore, gamepad: Gamepad) -> bool
fn pressed(&self, input_store: &CentralInputStore, gamepad: Gamepad) -> bool
Checks if all the inner inputs within the chord are active simultaneously.
source§fn press(&self, world: &mut World)
fn press(&self, world: &mut World)
source§fn release(&self, world: &mut World)
fn release(&self, world: &mut World)
source§impl Clone for ButtonlikeChord
impl Clone for ButtonlikeChord
source§fn clone(&self) -> ButtonlikeChord
fn clone(&self) -> ButtonlikeChord
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for ButtonlikeChord
impl Debug for ButtonlikeChord
source§impl Default for ButtonlikeChord
impl Default for ButtonlikeChord
source§fn default() -> ButtonlikeChord
fn default() -> ButtonlikeChord
source§impl<'de> Deserialize<'de> for ButtonlikeChord
impl<'de> Deserialize<'de> for ButtonlikeChord
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<U: Buttonlike> FromIterator<U> for ButtonlikeChord
impl<U: Buttonlike> FromIterator<U> for ButtonlikeChord
source§fn from_iter<T: IntoIterator<Item = U>>(iter: T) -> Self
fn from_iter<T: IntoIterator<Item = U>>(iter: T) -> Self
Creates a ButtonlikeChord
from an iterator over multiple Buttonlike
s, avoiding duplicates.
Note that all elements within the iterator must be of the same type (homogeneous).
You can still use other methods to add different types of inputs into the chord.
source§impl FromReflect for ButtonlikeChordwhere
Self: Any + Send + Sync,
Vec<Box<dyn Buttonlike>>: FromReflect + TypePath + RegisterForReflection,
impl FromReflect for ButtonlikeChordwhere
Self: Any + Send + Sync,
Vec<Box<dyn Buttonlike>>: FromReflect + TypePath + RegisterForReflection,
source§fn from_reflect(reflect: &dyn Reflect) -> Option<Self>
fn from_reflect(reflect: &dyn Reflect) -> Option<Self>
Self
from a reflected value.source§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 ButtonlikeChordwhere
Self: Any + Send + Sync,
Vec<Box<dyn Buttonlike>>: FromReflect + TypePath + RegisterForReflection,
impl GetTypeRegistration for ButtonlikeChordwhere
Self: Any + Send + Sync,
Vec<Box<dyn Buttonlike>>: FromReflect + TypePath + RegisterForReflection,
source§fn get_type_registration() -> TypeRegistration
fn get_type_registration() -> TypeRegistration
TypeRegistration
for this type.source§fn register_type_dependencies(registry: &mut TypeRegistry)
fn register_type_dependencies(registry: &mut TypeRegistry)
source§impl Hash for ButtonlikeChord
impl Hash for ButtonlikeChord
source§impl PartialEq for ButtonlikeChord
impl PartialEq for ButtonlikeChord
source§impl Reflect for ButtonlikeChordwhere
Self: Any + Send + Sync,
Vec<Box<dyn Buttonlike>>: FromReflect + TypePath + RegisterForReflection,
impl Reflect for ButtonlikeChordwhere
Self: Any + Send + Sync,
Vec<Box<dyn Buttonlike>>: FromReflect + TypePath + RegisterForReflection,
source§fn get_represented_type_info(&self) -> Option<&'static TypeInfo>
fn get_represented_type_info(&self) -> Option<&'static TypeInfo>
source§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: Box<dyn Reflect>) -> Result<(), Box<dyn Reflect>>
fn set(&mut self, value: Box<dyn Reflect>) -> Result<(), Box<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_partial_eq(&self, value: &dyn Reflect) -> Option<bool>
fn reflect_partial_eq(&self, value: &dyn Reflect) -> Option<bool>
source§fn apply(&mut self, value: &(dyn Reflect + 'static))
fn apply(&mut self, value: &(dyn Reflect + 'static))
source§fn reflect_hash(&self) -> Option<u64>
fn reflect_hash(&self) -> Option<u64>
source§fn debug(&self, f: &mut Formatter<'_>) -> Result<(), Error>
fn debug(&self, f: &mut Formatter<'_>) -> Result<(), Error>
source§fn serializable(&self) -> Option<Serializable<'_>>
fn serializable(&self) -> Option<Serializable<'_>>
source§fn is_dynamic(&self) -> bool
fn is_dynamic(&self) -> bool
source§impl<'de> RegisterTypeTag<'de, dyn Buttonlike> for ButtonlikeChord
impl<'de> RegisterTypeTag<'de, dyn Buttonlike> for ButtonlikeChord
source§fn register_typetag(registry: &mut InfallibleMapRegistry<dyn Buttonlike>)
fn register_typetag(registry: &mut InfallibleMapRegistry<dyn Buttonlike>)
InfallibleMapRegistry
.source§impl Serialize for ButtonlikeChord
impl Serialize for ButtonlikeChord
source§impl TupleStruct for ButtonlikeChordwhere
Self: Any + Send + Sync,
Vec<Box<dyn Buttonlike>>: FromReflect + TypePath + RegisterForReflection,
impl TupleStruct for ButtonlikeChordwhere
Self: Any + Send + Sync,
Vec<Box<dyn Buttonlike>>: FromReflect + TypePath + RegisterForReflection,
source§fn field(&self, index: usize) -> Option<&dyn Reflect>
fn field(&self, index: usize) -> Option<&dyn Reflect>
index
as a
&dyn Reflect
.source§fn field_mut(&mut self, index: usize) -> Option<&mut dyn Reflect>
fn field_mut(&mut self, index: usize) -> Option<&mut dyn Reflect>
index
as a &mut dyn Reflect
.source§fn iter_fields(&self) -> TupleStructFieldIter<'_>
fn iter_fields(&self) -> TupleStructFieldIter<'_>
source§fn clone_dynamic(&self) -> DynamicTupleStruct
fn clone_dynamic(&self) -> DynamicTupleStruct
DynamicTupleStruct
.source§impl TypePath for ButtonlikeChord
impl TypePath for ButtonlikeChord
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 ButtonlikeChordwhere
Self: Any + Send + Sync,
Vec<Box<dyn Buttonlike>>: FromReflect + TypePath + RegisterForReflection,
impl Typed for ButtonlikeChordwhere
Self: Any + Send + Sync,
Vec<Box<dyn Buttonlike>>: FromReflect + TypePath + RegisterForReflection,
source§impl UserInput for ButtonlikeChord
impl UserInput for ButtonlikeChord
source§fn kind(&self) -> InputControlKind
fn kind(&self) -> InputControlKind
ButtonlikeChord
acts as a virtual button.
source§fn decompose(&self) -> BasicInputs
fn decompose(&self) -> BasicInputs
Retrieves a list of simple, atomic Buttonlike
s that compose the chord.
The length of the basic inputs is the sum of the lengths of the inner inputs.
impl Eq for ButtonlikeChord
impl StructuralPartialEq for ButtonlikeChord
Auto Trait Implementations§
impl Freeze for ButtonlikeChord
impl !RefUnwindSafe for ButtonlikeChord
impl Send for ButtonlikeChord
impl Sync for ButtonlikeChord
impl Unpin for ButtonlikeChord
impl !UnwindSafe for ButtonlikeChord
Blanket Implementations§
source§impl<T, U> AsBindGroupShaderType<U> for T
impl<T, U> AsBindGroupShaderType<U> for T
source§fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> 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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
source§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
.source§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
.source§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.source§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<T> DowncastSync for T
impl<T> DowncastSync for T
source§impl<T> DynamicTypePath for Twhere
T: TypePath,
impl<T> DynamicTypePath for Twhere
T: TypePath,
source§fn reflect_type_path(&self) -> &str
fn reflect_type_path(&self) -> &str
TypePath::type_path
.source§fn reflect_short_type_path(&self) -> &str
fn reflect_short_type_path(&self) -> &str
source§fn reflect_type_ident(&self) -> Option<&str>
fn reflect_type_ident(&self) -> Option<&str>
TypePath::type_ident
.source§fn reflect_crate_name(&self) -> Option<&str>
fn reflect_crate_name(&self) -> Option<&str>
TypePath::crate_name
.source§fn reflect_module_path(&self) -> Option<&str>
fn reflect_module_path(&self) -> Option<&str>
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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.source§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
source§fn from_world(_world: &mut World) -> T
fn from_world(_world: &mut World) -> T
Self
using data from the given World
.source§impl<T> GetPath for T
impl<T> GetPath for T
source§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 moresource§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 moresource§fn path<'p, T>(
&self,
path: impl ReflectPath<'p>,
) -> Result<&T, ReflectPathError<'p>>where
T: Reflect,
fn path<'p, T>(
&self,
path: impl ReflectPath<'p>,
) -> Result<&T, ReflectPathError<'p>>where
T: Reflect,
path
. Read moresource§fn path_mut<'p, T>(
&mut self,
path: impl ReflectPath<'p>,
) -> Result<&mut T, ReflectPathError<'p>>where
T: Reflect,
fn path_mut<'p, T>(
&mut self,
path: impl ReflectPath<'p>,
) -> Result<&mut T, ReflectPathError<'p>>where
T: Reflect,
path
. Read moresource§impl<S> GetTupleStructField for Swhere
S: TupleStruct,
impl<S> GetTupleStructField for Swhere
S: TupleStruct,
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more