pub trait Buttonlike:
UserInput
+ DynClone
+ DynEq
+ DynHash
+ Reflect
+ Serialize {
// Required method
fn get_pressed(
&self,
input_store: &CentralInputStore,
gamepad: Entity,
) -> Option<bool>;
// Provided methods
fn pressed(&self, input_store: &CentralInputStore, gamepad: Entity) -> bool { ... }
fn released(&self, input_store: &CentralInputStore, gamepad: Entity) -> bool { ... }
fn value(&self, input_store: &CentralInputStore, gamepad: Entity) -> f32 { ... }
fn get_value(
&self,
input_store: &CentralInputStore,
gamepad: Entity,
) -> Option<f32> { ... }
fn press(&self, world: &mut World) { ... }
fn press_as_gamepad(&self, world: &mut World, _gamepad: Option<Entity>) { ... }
fn release(&self, world: &mut World) { ... }
fn release_as_gamepad(&self, world: &mut World, _gamepad: Option<Entity>) { ... }
fn set_value(&self, world: &mut World, value: f32) { ... }
fn set_value_as_gamepad(
&self,
world: &mut World,
value: f32,
_gamepad: Option<Entity>,
) { ... }
}Expand description
A trait used for buttonlike user inputs, which can be pressed or released with a value for how much they are pressed.
Required Methods§
Sourcefn get_pressed(
&self,
input_store: &CentralInputStore,
gamepad: Entity,
) -> Option<bool>
fn get_pressed( &self, input_store: &CentralInputStore, gamepad: Entity, ) -> Option<bool>
Checks if the input is currently active.
Provided Methods§
Sourcefn pressed(&self, input_store: &CentralInputStore, gamepad: Entity) -> bool
fn pressed(&self, input_store: &CentralInputStore, gamepad: Entity) -> bool
Checks if the input is currently active.
Sourcefn released(&self, input_store: &CentralInputStore, gamepad: Entity) -> bool
fn released(&self, input_store: &CentralInputStore, gamepad: Entity) -> bool
Checks if the input is currently inactive.
Sourcefn value(&self, input_store: &CentralInputStore, gamepad: Entity) -> f32
fn value(&self, input_store: &CentralInputStore, gamepad: Entity) -> f32
Gets the current value of the button as an f32.
The returned value should be between 0.0 and 1.0,
with 0.0 representing the input being fully released
and 1.0 representing the input being fully pressed.
Sourcefn get_value(
&self,
input_store: &CentralInputStore,
gamepad: Entity,
) -> Option<f32>
fn get_value( &self, input_store: &CentralInputStore, gamepad: Entity, ) -> Option<f32>
Gets the current value of the button as an f32.
Or None if the input has never been pressed or set.
The returned value should be between 0.0 and 1.0,
with 0.0 representing the input being fully released
and 1.0 representing the input being fully pressed.
Sourcefn press(&self, world: &mut World)
fn press(&self, world: &mut World)
Simulates a press of the buttonlike input by sending the appropriate message.
This method defaults to calling Buttonlike::press_as_gamepad if not overridden,
as is the case for gamepad-reliant inputs.
Sourcefn press_as_gamepad(&self, world: &mut World, _gamepad: Option<Entity>)
fn press_as_gamepad(&self, world: &mut World, _gamepad: Option<Entity>)
Simulate a press of the buttonlike input, pretending to be the provided gamepad Entity.
This method defaults to calling Buttonlike::press if not overridden,
as is the case for things like mouse buttons and keyboard keys.
Use find_gamepad inside of this method to search for a gamepad to press the button on
if the provided gamepad is None.
Sourcefn release(&self, world: &mut World)
fn release(&self, world: &mut World)
Simulates a release of the buttonlike input by sending the appropriate message.
This method defaults to calling Buttonlike::release_as_gamepad if not overridden,
as is the case for gamepad-reliant inputs.
Sourcefn release_as_gamepad(&self, world: &mut World, _gamepad: Option<Entity>)
fn release_as_gamepad(&self, world: &mut World, _gamepad: Option<Entity>)
Simulate a release of the buttonlike input, pretending to be the provided gamepad Entity.
This method defaults to calling Buttonlike::release if not overridden,
as is the case for things like mouse buttons and keyboard keys.
Use find_gamepad inside of this method to search for a gamepad to press the button on
if the provided gamepad is None.
Sourcefn set_value(&self, world: &mut World, value: f32)
fn set_value(&self, world: &mut World, value: f32)
Simulate a value change of the buttonlike input by sending the appropriate message.
This method defaults to calling Buttonlike::set_value_as_gamepad if not overridden,
as is the case for gamepad-reliant inputs.
Also updates the state of the button based on the value:
- If
value > 0.0, the button will be pressed. - If
value <= 0.0, the button will be released.
Sourcefn set_value_as_gamepad(
&self,
world: &mut World,
value: f32,
_gamepad: Option<Entity>,
)
fn set_value_as_gamepad( &self, world: &mut World, value: f32, _gamepad: Option<Entity>, )
Simulate a value change of the buttonlike input, pretending to be the provided gamepad Entity.
This method defaults to calling Buttonlike::set_value if not overridden,
as is the case for things like a mouse wheel.
Also updates the state of the button based on the value:
- If
value > 0.0, the button will be pressed. - If
value <= 0.0, the button will be released.
Use find_gamepad inside of this method to search for a gamepad to press the button on
if the provided gamepad is None.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Box<dyn Buttonlike>
impl<'de> Deserialize<'de> for Box<dyn Buttonlike>
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 FromReflect for Box<dyn Buttonlike>
impl FromReflect for Box<dyn Buttonlike>
Source§fn from_reflect(reflect: &dyn PartialReflect) -> Option<Self>
fn from_reflect(reflect: &dyn PartialReflect) -> Option<Self>
Self from a reflected value.Source§fn take_from_reflect(
reflect: Box<dyn PartialReflect>,
) -> Result<Self, Box<dyn PartialReflect>>
fn take_from_reflect( reflect: Box<dyn PartialReflect>, ) -> Result<Self, Box<dyn PartialReflect>>
Self using,
constructing the value using from_reflect if that fails. Read moreSource§impl GetTypeRegistration for Box<dyn Buttonlike>
impl GetTypeRegistration for Box<dyn Buttonlike>
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> Hash for dyn Buttonlike + 'hash
impl<'hash> Hash for dyn Buttonlike + 'hash
Source§impl<'hash> Hash for dyn Buttonlike + Send + 'hash
impl<'hash> Hash for dyn Buttonlike + Send + 'hash
Source§impl<'hash> Hash for dyn Buttonlike + Sync + 'hash
impl<'hash> Hash for dyn Buttonlike + Sync + 'hash
Source§impl<'eq> PartialEq<&Box<dyn Buttonlike + 'eq>> for Box<dyn Buttonlike + 'eq>
impl<'eq> PartialEq<&Box<dyn Buttonlike + 'eq>> for Box<dyn Buttonlike + 'eq>
Source§impl<'eq> PartialEq<&Box<dyn Buttonlike + Send + 'eq>> for Box<dyn Buttonlike + Send + 'eq>
impl<'eq> PartialEq<&Box<dyn Buttonlike + Send + 'eq>> for Box<dyn Buttonlike + Send + 'eq>
Source§impl<'eq> PartialEq<&Box<dyn Buttonlike + Sync + Send + 'eq>> for Box<dyn Buttonlike + Send + Sync + 'eq>
impl<'eq> PartialEq<&Box<dyn Buttonlike + Sync + Send + 'eq>> for Box<dyn Buttonlike + Send + Sync + 'eq>
Source§impl<'eq> PartialEq<&Box<dyn Buttonlike + Sync + 'eq>> for Box<dyn Buttonlike + Sync + 'eq>
impl<'eq> PartialEq<&Box<dyn Buttonlike + Sync + 'eq>> for Box<dyn Buttonlike + Sync + 'eq>
Source§impl<'eq> PartialEq for dyn Buttonlike + 'eq
impl<'eq> PartialEq for dyn Buttonlike + 'eq
Source§impl<'eq> PartialEq for dyn Buttonlike + Send + 'eq
impl<'eq> PartialEq for dyn Buttonlike + Send + 'eq
Source§impl<'eq> PartialEq for dyn Buttonlike + Sync + 'eq
impl<'eq> PartialEq for dyn Buttonlike + Sync + 'eq
Source§impl PartialReflect for Box<dyn Buttonlike>
impl PartialReflect for Box<dyn Buttonlike>
Source§fn get_represented_type_info(&self) -> Option<&'static TypeInfo>
fn get_represented_type_info(&self) -> Option<&'static TypeInfo>
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 try_apply(&mut self, value: &dyn PartialReflect) -> Result<(), ApplyError>
fn try_apply(&mut self, value: &dyn PartialReflect) -> Result<(), ApplyError>
Source§fn into_partial_reflect(self: Box<Self>) -> Box<dyn PartialReflect>
fn into_partial_reflect(self: Box<Self>) -> Box<dyn PartialReflect>
Source§fn as_partial_reflect(&self) -> &dyn PartialReflect
fn as_partial_reflect(&self) -> &dyn PartialReflect
Source§fn as_partial_reflect_mut(&mut self) -> &mut dyn PartialReflect
fn as_partial_reflect_mut(&mut self) -> &mut dyn PartialReflect
Source§fn try_into_reflect(
self: Box<Self>,
) -> Result<Box<dyn Reflect>, Box<dyn PartialReflect>>
fn try_into_reflect( self: Box<Self>, ) -> Result<Box<dyn Reflect>, Box<dyn PartialReflect>>
Source§fn try_as_reflect(&self) -> Option<&dyn Reflect>
fn try_as_reflect(&self) -> Option<&dyn Reflect>
Source§fn try_as_reflect_mut(&mut self) -> Option<&mut dyn Reflect>
fn try_as_reflect_mut(&mut self) -> Option<&mut dyn Reflect>
Source§fn apply(&mut self, value: &(dyn PartialReflect + 'static))
fn apply(&mut self, value: &(dyn PartialReflect + 'static))
Source§fn to_dynamic(&self) -> Box<dyn PartialReflect>
fn to_dynamic(&self) -> Box<dyn PartialReflect>
Source§fn reflect_clone(&self) -> Result<Box<dyn Reflect>, ReflectCloneError>
fn reflect_clone(&self) -> Result<Box<dyn Reflect>, ReflectCloneError>
Self using reflection. Read moreSource§fn reflect_clone_and_take<T>(&self) -> Result<T, ReflectCloneError>
fn reflect_clone_and_take<T>(&self) -> Result<T, ReflectCloneError>
PartialReflect, combines reflect_clone and
take in a useful fashion, automatically constructing an appropriate
ReflectCloneError if the downcast fails. Read moreSource§fn reflect_hash(&self) -> Option<u64>
fn reflect_hash(&self) -> Option<u64>
Source§fn reflect_partial_eq(
&self,
_value: &(dyn PartialReflect + 'static),
) -> Option<bool>
fn reflect_partial_eq( &self, _value: &(dyn PartialReflect + 'static), ) -> Option<bool>
Source§fn debug(&self, f: &mut Formatter<'_>) -> Result<(), Error>
fn debug(&self, f: &mut Formatter<'_>) -> Result<(), Error>
Source§fn is_dynamic(&self) -> bool
fn is_dynamic(&self) -> bool
Source§impl Reflect for Box<dyn Buttonlike>
impl Reflect for Box<dyn Buttonlike>
Source§fn as_any_mut(&mut self) -> &mut dyn Any
fn as_any_mut(&mut self) -> &mut dyn Any
&mut dyn Any. Read moreSource§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§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<'de> RegisterTypeTag<'de, dyn Buttonlike> for GamepadButton
impl<'de> RegisterTypeTag<'de, dyn Buttonlike> for GamepadButton
Source§fn register_typetag(registry: &mut InfallibleMapRegistry<dyn Buttonlike>)
fn register_typetag(registry: &mut InfallibleMapRegistry<dyn Buttonlike>)
InfallibleMapRegistry.Source§impl<'de> RegisterTypeTag<'de, dyn Buttonlike> for GamepadControlDirection
impl<'de> RegisterTypeTag<'de, dyn Buttonlike> for GamepadControlDirection
Source§fn register_typetag(registry: &mut InfallibleMapRegistry<dyn Buttonlike>)
fn register_typetag(registry: &mut InfallibleMapRegistry<dyn Buttonlike>)
InfallibleMapRegistry.Source§impl<'de> RegisterTypeTag<'de, dyn Buttonlike> for KeyCode
impl<'de> RegisterTypeTag<'de, dyn Buttonlike> for KeyCode
Source§fn register_typetag(registry: &mut InfallibleMapRegistry<dyn Buttonlike>)
fn register_typetag(registry: &mut InfallibleMapRegistry<dyn Buttonlike>)
InfallibleMapRegistry.Source§impl<'de> RegisterTypeTag<'de, dyn Buttonlike> for ModifierKey
impl<'de> RegisterTypeTag<'de, dyn Buttonlike> for ModifierKey
Source§fn register_typetag(registry: &mut InfallibleMapRegistry<dyn Buttonlike>)
fn register_typetag(registry: &mut InfallibleMapRegistry<dyn Buttonlike>)
InfallibleMapRegistry.Source§impl<'de> RegisterTypeTag<'de, dyn Buttonlike> for MouseButton
impl<'de> RegisterTypeTag<'de, dyn Buttonlike> for MouseButton
Source§fn register_typetag(registry: &mut InfallibleMapRegistry<dyn Buttonlike>)
fn register_typetag(registry: &mut InfallibleMapRegistry<dyn Buttonlike>)
InfallibleMapRegistry.Source§impl<'de> RegisterTypeTag<'de, dyn Buttonlike> for MouseMoveDirection
impl<'de> RegisterTypeTag<'de, dyn Buttonlike> for MouseMoveDirection
Source§fn register_typetag(registry: &mut InfallibleMapRegistry<dyn Buttonlike>)
fn register_typetag(registry: &mut InfallibleMapRegistry<dyn Buttonlike>)
InfallibleMapRegistry.Source§impl<'de> RegisterTypeTag<'de, dyn Buttonlike> for MouseScrollDirection
impl<'de> RegisterTypeTag<'de, dyn Buttonlike> for MouseScrollDirection
Source§fn register_typetag(registry: &mut InfallibleMapRegistry<dyn Buttonlike>)
fn register_typetag(registry: &mut InfallibleMapRegistry<dyn Buttonlike>)
InfallibleMapRegistry.Source§impl<'de> RegisterTypeTag<'de, dyn Buttonlike> for SpecificGamepadButton
impl<'de> RegisterTypeTag<'de, dyn Buttonlike> for SpecificGamepadButton
Source§fn register_typetag(registry: &mut InfallibleMapRegistry<dyn Buttonlike>)
fn register_typetag(registry: &mut InfallibleMapRegistry<dyn Buttonlike>)
InfallibleMapRegistry.Source§impl Serialize for dyn Buttonlike + '_
impl Serialize for dyn Buttonlike + '_
Source§impl TypePath for Box<dyn Buttonlike>
impl TypePath for Box<dyn Buttonlike>
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 Box<dyn Buttonlike>
impl Typed for Box<dyn Buttonlike>
impl<'eq> Eq for dyn Buttonlike + 'eq
impl<'eq> Eq for dyn Buttonlike + Send + 'eq
impl<'eq> Eq for dyn Buttonlike + Send + Sync + 'eq
impl<'eq> Eq for dyn Buttonlike + Sync + 'eq
Implementations on Foreign Types§
Source§impl Buttonlike for GamepadButton
impl Buttonlike for GamepadButton
Source§fn get_pressed(
&self,
input_store: &CentralInputStore,
gamepad: Entity,
) -> Option<bool>
fn get_pressed( &self, input_store: &CentralInputStore, gamepad: Entity, ) -> Option<bool>
Checks if the specified button is currently pressed down.
Source§fn value(&self, input_store: &CentralInputStore, gamepad: Entity) -> f32
fn value(&self, input_store: &CentralInputStore, gamepad: Entity) -> f32
Retrieves the current value of the specified button.
This will be 0.0 if the button is released, and 1.0 if it is pressed. Physically triggerlike buttons will return a value between 0.0 and 1.0, depending on how far the button is pressed.
Source§fn press_as_gamepad(&self, world: &mut World, gamepad: Option<Entity>)
fn press_as_gamepad(&self, world: &mut World, gamepad: Option<Entity>)
Sends a RawGamepadEvent::Button message with a magnitude of 1.0 in the direction defined by self on the provided gamepad Entity.
Source§fn release_as_gamepad(&self, world: &mut World, gamepad: Option<Entity>)
fn release_as_gamepad(&self, world: &mut World, gamepad: Option<Entity>)
Sends a RawGamepadEvent::Button message with a magnitude of 0.0 in the direction defined by self on the provided gamepad Entity.
Source§fn set_value_as_gamepad(
&self,
world: &mut World,
value: f32,
gamepad: Option<Entity>,
)
fn set_value_as_gamepad( &self, world: &mut World, value: f32, gamepad: Option<Entity>, )
Sends a RawGamepadEvent::Button message with the specified value in the direction defined by self on the provided gamepad Entity.
Source§impl Buttonlike for KeyCode
impl Buttonlike for KeyCode
Source§fn get_pressed(
&self,
input_store: &CentralInputStore,
_gamepad: Entity,
) -> Option<bool>
fn get_pressed( &self, input_store: &CentralInputStore, _gamepad: Entity, ) -> Option<bool>
Checks if the specified key is currently pressed down.
Source§fn press(&self, world: &mut World)
fn press(&self, world: &mut World)
Sends a fake KeyboardInput message to the world with ButtonState::Pressed.
§Note
The logical_key and window fields will be filled with placeholder values.
Source§fn release(&self, world: &mut World)
fn release(&self, world: &mut World)
Sends a fake KeyboardInput message to the world with ButtonState::Released.
§Note
The logical_key and window fields will be filled with placeholder values.
Source§impl Buttonlike for MouseButton
impl Buttonlike for MouseButton
Source§fn get_pressed(
&self,
input_store: &CentralInputStore,
_gamepad: Entity,
) -> Option<bool>
fn get_pressed( &self, input_store: &CentralInputStore, _gamepad: Entity, ) -> Option<bool>
Checks if the specified button is currently pressed down.
Source§fn press(&self, world: &mut World)
fn press(&self, world: &mut World)
Sends a fake MouseButtonInput message to the world with ButtonState::Pressed.
§Note
The window field will be filled with a placeholder value.
Source§fn release(&self, world: &mut World)
fn release(&self, world: &mut World)
Sends a fake MouseButtonInput message to the world with ButtonState::Released.
§Note
The window field will be filled with a placeholder value.