Skip to content

Commit f32eed6

Browse files
Shaturalice-i-cecile
authored andcommitted
Gamepad improvements (#16222)
# Objective Closes #16221. ## Solution - Make `Gamepad` fields public and remove delegates / getters. - Move `impl Into` to `Axis` methods (delegates for `Axis` used `impl Into` to allow passing both `GamepadAxis` and `GamepadButton`). - Improve docs. ## Testing - I run tests. Not sure if the migration guide is needed, since it's a feature from RC, but I wrote it just in case. --- ## Migration Guide - `Gamepad` fields are now public. - Instead of using `Gamepad` delegates like `Gamepad::just_pressed`, call these methods directly on the fields. --------- Co-authored-by: Alice Cecile <[email protected]>
1 parent 7329d60 commit f32eed6

File tree

5 files changed

+69
-237
lines changed

5 files changed

+69
-237
lines changed

crates/bevy_input/src/axis.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,16 @@ where
4545
/// If the `input_device`:
4646
/// - was present before, the position data is updated, and the old value is returned.
4747
/// - wasn't present before, `None` is returned.
48-
pub fn set(&mut self, input_device: T, position_data: f32) -> Option<f32> {
49-
self.axis_data.insert(input_device, position_data)
48+
pub fn set(&mut self, input_device: impl Into<T>, position_data: f32) -> Option<f32> {
49+
self.axis_data.insert(input_device.into(), position_data)
5050
}
5151

5252
/// Returns the position data of the provided `input_device`.
5353
///
5454
/// This will be clamped between [`Axis::MIN`] and [`Axis::MAX`] inclusive.
55-
pub fn get(&self, input_device: T) -> Option<f32> {
55+
pub fn get(&self, input_device: impl Into<T>) -> Option<f32> {
5656
self.axis_data
57-
.get(&input_device)
57+
.get(&input_device.into())
5858
.copied()
5959
.map(|value| value.clamp(Self::MIN, Self::MAX))
6060
}
@@ -66,13 +66,13 @@ where
6666
/// Use for things like camera zoom, where you want devices like mouse wheels to be able to
6767
/// exceed the normal range. If being able to move faster on one input device
6868
/// than another would give an unfair advantage, you should likely use [`Axis::get`] instead.
69-
pub fn get_unclamped(&self, input_device: T) -> Option<f32> {
70-
self.axis_data.get(&input_device).copied()
69+
pub fn get_unclamped(&self, input_device: impl Into<T>) -> Option<f32> {
70+
self.axis_data.get(&input_device.into()).copied()
7171
}
7272

7373
/// Removes the position data of the `input_device`, returning the position data if the input device was previously set.
74-
pub fn remove(&mut self, input_device: T) -> Option<f32> {
75-
self.axis_data.remove(&input_device)
74+
pub fn remove(&mut self, input_device: impl Into<T>) -> Option<f32> {
75+
self.axis_data.remove(&input_device.into())
7676
}
7777

7878
/// Returns an iterator over all axes.

0 commit comments

Comments
 (0)