Trait Buttonlike

Source
pub trait Buttonlike:
    UserInput
    + DynClone
    + DynEq
    + DynHash
    + Reflect
    + Serialize {
    // Required method
    fn pressed(&self, input_store: &CentralInputStore, gamepad: Entity) -> bool;

    // Provided methods
    fn released(&self, input_store: &CentralInputStore, gamepad: Entity) -> bool { ... }
    fn value(&self, input_store: &CentralInputStore, gamepad: Entity) -> 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§

Source

fn pressed(&self, input_store: &CentralInputStore, gamepad: Entity) -> bool

Checks if the input is currently active.

Provided Methods§

Source

fn released(&self, input_store: &CentralInputStore, gamepad: Entity) -> bool

Checks if the input is currently inactive.

Source

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.

Source

fn press(&self, world: &mut World)

Simulates a press of the buttonlike input by sending the appropriate event.

This method defaults to calling Buttonlike::press_as_gamepad if not overridden, as is the case for gamepad-reliant inputs.

Source

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.

Source

fn release(&self, world: &mut World)

Simulates a release of the buttonlike input by sending the appropriate event.

This method defaults to calling Buttonlike::release_as_gamepad if not overridden, as is the case for gamepad-reliant inputs.

Source

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.

Source

fn set_value(&self, world: &mut World, value: f32)

Simulate a value change of the buttonlike input by sending the appropriate event.

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.
Source

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>

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl FromReflect for Box<dyn Buttonlike>

Source§

fn from_reflect(reflect: &dyn PartialReflect) -> Option<Self>

Constructs a concrete instance of Self from a reflected value.
Source§

fn take_from_reflect( reflect: Box<dyn PartialReflect>, ) -> Result<Self, Box<dyn PartialReflect>>

Attempts to downcast the given value to Self using, constructing the value using from_reflect if that fails. Read more
Source§

impl GetTypeRegistration for Box<dyn Buttonlike>

Source§

fn get_type_registration() -> TypeRegistration

Returns the default TypeRegistration for this type.
Source§

fn register_type_dependencies(_registry: &mut TypeRegistry)

Registers other types needed by this type. Read more
Source§

impl<'hash> Hash for dyn Buttonlike + 'hash

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
Source§

impl<'hash> Hash for dyn Buttonlike + Send + 'hash

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
Source§

impl<'hash> Hash for dyn Buttonlike + Send + Sync + 'hash

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
Source§

impl<'hash> Hash for dyn Buttonlike + Sync + 'hash

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
Source§

impl<'eq> PartialEq<&Box<dyn Buttonlike + 'eq>> for Box<dyn Buttonlike + 'eq>

Source§

fn eq(&self, other: &&Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'eq> PartialEq<&Box<dyn Buttonlike + Send + 'eq>> for Box<dyn Buttonlike + Send + 'eq>

Source§

fn eq(&self, other: &&Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'eq> PartialEq<&Box<dyn Buttonlike + Sync + Send + 'eq>> for Box<dyn Buttonlike + Send + Sync + 'eq>

Source§

fn eq(&self, other: &&Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'eq> PartialEq<&Box<dyn Buttonlike + Sync + 'eq>> for Box<dyn Buttonlike + Sync + 'eq>

Source§

fn eq(&self, other: &&Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'eq> PartialEq for dyn Buttonlike + 'eq

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'eq> PartialEq for dyn Buttonlike + Send + 'eq

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'eq> PartialEq for dyn Buttonlike + Send + Sync + 'eq

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'eq> PartialEq for dyn Buttonlike + Sync + 'eq

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialReflect for Box<dyn Buttonlike>

Source§

fn get_represented_type_info(&self) -> Option<&'static TypeInfo>

Returns the TypeInfo of the type represented by this value. Read more
Source§

fn reflect_kind(&self) -> ReflectKind

Returns a zero-sized enumeration of “kinds” of type. Read more
Source§

fn reflect_ref(&self) -> ReflectRef<'_>

Returns an immutable enumeration of “kinds” of type. Read more
Source§

fn reflect_mut(&mut self) -> ReflectMut<'_>

Returns a mutable enumeration of “kinds” of type. Read more
Source§

fn reflect_owned(self: Box<Self>) -> ReflectOwned

Returns an owned enumeration of “kinds” of type. Read more
Source§

fn clone_value(&self) -> Box<dyn PartialReflect>

👎Deprecated since 0.16.0: to clone reflected values, prefer using reflect_clone. To convert reflected values to dynamic ones, use to_dynamic.
Clones Self into its dynamic representation. Read more
Source§

fn try_apply(&mut self, value: &dyn PartialReflect) -> Result<(), ApplyError>

Tries to apply a reflected value to this value. Read more
Source§

fn into_partial_reflect(self: Box<Self>) -> Box<dyn PartialReflect>

Casts this type to a boxed, reflected value. Read more
Source§

fn as_partial_reflect(&self) -> &dyn PartialReflect

Casts this type to a reflected value. Read more
Source§

fn as_partial_reflect_mut(&mut self) -> &mut dyn PartialReflect

Casts this type to a mutable, reflected value. Read more
Source§

fn try_into_reflect( self: Box<Self>, ) -> Result<Box<dyn Reflect>, Box<dyn PartialReflect>>

Attempts to cast this type to a boxed, fully-reflected value.
Source§

fn try_as_reflect(&self) -> Option<&dyn Reflect>

Attempts to cast this type to a fully-reflected value.
Source§

fn try_as_reflect_mut(&mut self) -> Option<&mut dyn Reflect>

Attempts to cast this type to a mutable, fully-reflected value.
Source§

fn apply(&mut self, value: &(dyn PartialReflect + 'static))

Applies a reflected value to this value. Read more
Source§

fn to_dynamic(&self) -> Box<dyn PartialReflect>

Converts this reflected value into its dynamic representation based on its kind. Read more
Source§

fn reflect_clone(&self) -> Result<Box<dyn Reflect>, ReflectCloneError>

Attempts to clone Self using reflection. Read more
Source§

fn reflect_hash(&self) -> Option<u64>

Returns a hash of the value (which includes the type). Read more
Source§

fn reflect_partial_eq( &self, _value: &(dyn PartialReflect + 'static), ) -> Option<bool>

Returns a “partial equality” comparison result. Read more
Source§

fn debug(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Debug formatter for the value. Read more
Source§

fn is_dynamic(&self) -> bool

Indicates whether or not this type is a dynamic type. Read more
Source§

impl Reflect for Box<dyn Buttonlike>

Source§

fn into_any(self: Box<Self>) -> Box<dyn Any>

Returns the value as a Box<dyn Any>. Read more
Source§

fn as_any(&self) -> &dyn Any

Returns the value as a &dyn Any. Read more
Source§

fn as_any_mut(&mut self) -> &mut dyn Any

Returns the value as a &mut dyn Any. Read more
Source§

fn into_reflect(self: Box<Self>) -> Box<dyn Reflect>

Casts this type to a boxed, fully-reflected value.
Source§

fn as_reflect(&self) -> &dyn Reflect

Casts this type to a fully-reflected value.
Source§

fn as_reflect_mut(&mut self) -> &mut dyn Reflect

Casts this type to a mutable, fully-reflected value.
Source§

fn set(&mut self, value: Box<dyn Reflect>) -> Result<(), Box<dyn Reflect>>

Performs a type-checked assignment of a reflected value to this value. Read more
Source§

impl<'de> RegisterTypeTag<'de, dyn Buttonlike> for ButtonlikeChord

Source§

fn register_typetag(registry: &mut InfallibleMapRegistry<dyn Buttonlike>)

Registers the specified type tag into the InfallibleMapRegistry.
Source§

impl<'de> RegisterTypeTag<'de, dyn Buttonlike> for GamepadButton

Source§

fn register_typetag(registry: &mut InfallibleMapRegistry<dyn Buttonlike>)

Registers the specified type tag into the InfallibleMapRegistry.
Source§

impl<'de> RegisterTypeTag<'de, dyn Buttonlike> for GamepadControlDirection

Source§

fn register_typetag(registry: &mut InfallibleMapRegistry<dyn Buttonlike>)

Registers the specified type tag into the InfallibleMapRegistry.
Source§

impl<'de> RegisterTypeTag<'de, dyn Buttonlike> for KeyCode

Source§

fn register_typetag(registry: &mut InfallibleMapRegistry<dyn Buttonlike>)

Registers the specified type tag into the InfallibleMapRegistry.
Source§

impl<'de> RegisterTypeTag<'de, dyn Buttonlike> for ModifierKey

Source§

fn register_typetag(registry: &mut InfallibleMapRegistry<dyn Buttonlike>)

Registers the specified type tag into the InfallibleMapRegistry.
Source§

impl<'de> RegisterTypeTag<'de, dyn Buttonlike> for MouseButton

Source§

fn register_typetag(registry: &mut InfallibleMapRegistry<dyn Buttonlike>)

Registers the specified type tag into the InfallibleMapRegistry.
Source§

impl<'de> RegisterTypeTag<'de, dyn Buttonlike> for MouseMoveDirection

Source§

fn register_typetag(registry: &mut InfallibleMapRegistry<dyn Buttonlike>)

Registers the specified type tag into the InfallibleMapRegistry.
Source§

impl<'de> RegisterTypeTag<'de, dyn Buttonlike> for MouseScrollDirection

Source§

fn register_typetag(registry: &mut InfallibleMapRegistry<dyn Buttonlike>)

Registers the specified type tag into the InfallibleMapRegistry.
Source§

impl<'de> RegisterTypeTag<'de, dyn Buttonlike> for SpecificGamepadButton

Source§

fn register_typetag(registry: &mut InfallibleMapRegistry<dyn Buttonlike>)

Registers the specified type tag into the InfallibleMapRegistry.
Source§

impl Serialize for dyn Buttonlike + '_

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl TypePath for Box<dyn Buttonlike>

Source§

fn type_path() -> &'static str

Returns the fully qualified path of the underlying type. Read more
Source§

fn short_type_path() -> &'static str

Returns a short, pretty-print enabled path to the type. Read more
Source§

fn type_ident() -> Option<&'static str>

Returns the name of the type, or None if it is anonymous. Read more
Source§

fn crate_name() -> Option<&'static str>

Returns the name of the crate the type is in, or None if it is anonymous. Read more
Source§

fn module_path() -> Option<&'static str>

Returns the path to the module the type is in, or None if it is anonymous. Read more
Source§

impl Typed for Box<dyn Buttonlike>

Source§

fn type_info() -> &'static TypeInfo

Returns the compile-time info for the underlying type.
Source§

impl<'eq> Eq for dyn Buttonlike + 'eq

Source§

impl<'eq> Eq for dyn Buttonlike + Send + 'eq

Source§

impl<'eq> Eq for dyn Buttonlike + Send + Sync + 'eq

Source§

impl<'eq> Eq for dyn Buttonlike + Sync + 'eq

Implementations on Foreign Types§

Source§

impl Buttonlike for GamepadButton

Source§

fn pressed(&self, input_store: &CentralInputStore, gamepad: Entity) -> bool

Checks if the specified button is currently pressed down.

Source§

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>)

Sends a RawGamepadEvent::Button event 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>)

Sends a RawGamepadEvent::Button event 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>, )

Sends a RawGamepadEvent::Button event with the specified value in the direction defined by self on the provided gamepad Entity.

Source§

impl Buttonlike for KeyCode

Source§

fn pressed(&self, input_store: &CentralInputStore, _gamepad: Entity) -> bool

Checks if the specified key is currently pressed down.

Source§

fn press(&self, world: &mut World)

Sends a fake KeyboardInput event 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)

Sends a fake KeyboardInput event to the world with ButtonState::Released.

§Note

The logical_key and window fields will be filled with placeholder values.

Source§

fn set_value(&self, world: &mut World, value: f32)

If the value is greater than 0.0, press the key; otherwise release it.

Source§

impl Buttonlike for MouseButton

Source§

fn pressed(&self, input_store: &CentralInputStore, _gamepad: Entity) -> bool

Checks if the specified button is currently pressed down.

Source§

fn press(&self, world: &mut World)

Sends a fake MouseButtonInput event to the world with ButtonState::Pressed.

§Note

The window field will be filled with a placeholder value.

Source§

fn release(&self, world: &mut World)

Sends a fake MouseButtonInput event to the world with ButtonState::Released.

§Note

The window field will be filled with a placeholder value.

Source§

fn set_value(&self, world: &mut World, value: f32)

If the value is greater than 0.0, press the key; otherwise release it.

Implementors§