Skip to content

Commit 5db4a04

Browse files
Bevy Input Docs : gamepad.rs (#9469)
# Objective Complete the documentation of `bevy_input` (#3492). This PR is part of a triptych of PRs : - #9467 - #9468 ## Solution Add missing documentation on items in `gamepad.rs` --------- Co-authored-by: Pascal Hertleif <[email protected]>
1 parent b9ab17e commit 5db4a04

File tree

1 file changed

+52
-18
lines changed

1 file changed

+52
-18
lines changed

crates/bevy_input/src/gamepad.rs

+52-18
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,17 @@ pub enum AxisSettingsError {
2727
/// Parameter `livezone_lowerbound` was not less than or equal to parameter `deadzone_lowerbound`.
2828
#[error("invalid parameter values livezone_lowerbound {} deadzone_lowerbound {}, expected livezone_lowerbound <= deadzone_lowerbound", .livezone_lowerbound, .deadzone_lowerbound)]
2929
LiveZoneLowerBoundGreaterThanDeadZoneLowerBound {
30+
/// The value of the `livezone_lowerbound` parameter.
3031
livezone_lowerbound: f32,
32+
/// The value of the `deadzone_lowerbound` parameter.
3133
deadzone_lowerbound: f32,
3234
},
3335
/// Parameter `deadzone_upperbound` was not less than or equal to parameter `livezone_upperbound`.
3436
#[error("invalid parameter values livezone_upperbound {} deadzone_upperbound {}, expected deadzone_upperbound <= livezone_upperbound", .livezone_upperbound, .deadzone_upperbound)]
3537
DeadZoneUpperBoundGreaterThanLiveZoneUpperBound {
38+
/// The value of the `livezone_upperbound` parameter.
3639
livezone_upperbound: f32,
40+
/// The value of the `deadzone_upperbound` parameter.
3741
deadzone_upperbound: f32,
3842
},
3943
/// The given parameter was not in range 0.0..=2.0.
@@ -53,7 +57,9 @@ pub enum ButtonSettingsError {
5357
/// Parameter `release_threshold` was not less than or equal to `press_threshold`.
5458
#[error("invalid parameter values release_threshold {} press_threshold {}, expected release_threshold <= press_threshold", .release_threshold, .press_threshold)]
5559
ReleaseThresholdGreaterThanPressThreshold {
60+
/// The value of the `press_threshold` parameter.
5661
press_threshold: f32,
62+
/// The value of the `release_threshold` parameter.
5763
release_threshold: f32,
5864
},
5965
}
@@ -100,6 +106,11 @@ impl Gamepad {
100106
reflect(Serialize, Deserialize)
101107
)]
102108
pub struct GamepadInfo {
109+
/// The name of the gamepad.
110+
///
111+
/// This name is generally defined by the OS.
112+
///
113+
/// For example on Windows the name may be "HID-compliant game controller".
103114
pub name: String,
104115
}
105116

@@ -130,6 +141,7 @@ impl Gamepads {
130141
self.gamepads.keys().copied()
131142
}
132143

144+
/// The name of the gamepad if this one is connected.
133145
pub fn name(&self, gamepad: Gamepad) -> Option<&str> {
134146
self.gamepads.get(&gamepad).map(|g| g.name.as_str())
135147
}
@@ -1025,6 +1037,7 @@ pub fn gamepad_connection_system(
10251037
}
10261038
}
10271039

1040+
/// The connection status of a gamepad.
10281041
#[derive(Debug, Clone, PartialEq, Reflect)]
10291042
#[reflect(Debug, PartialEq)]
10301043
#[cfg_attr(
@@ -1033,7 +1046,9 @@ pub fn gamepad_connection_system(
10331046
reflect(Serialize, Deserialize)
10341047
)]
10351048
pub enum GamepadConnection {
1049+
/// The gamepad is connected.
10361050
Connected(GamepadInfo),
1051+
/// The gamepad is disconnected.
10371052
Disconnected,
10381053
}
10391054

@@ -1054,22 +1069,27 @@ pub struct GamepadConnectionEvent {
10541069
}
10551070

10561071
impl GamepadConnectionEvent {
1072+
/// Creates a [`GamepadConnectionEvent`].
10571073
pub fn new(gamepad: Gamepad, connection: GamepadConnection) -> Self {
10581074
Self {
10591075
gamepad,
10601076
connection,
10611077
}
10621078
}
10631079

1080+
/// Is the gamepad connected?
10641081
pub fn connected(&self) -> bool {
10651082
matches!(self.connection, GamepadConnection::Connected(_))
10661083
}
10671084

1085+
/// Is the gamepad disconnected?
10681086
pub fn disconnected(&self) -> bool {
10691087
!self.connected()
10701088
}
10711089
}
10721090

1091+
/// Gamepad event for when the "value" on the axis changes
1092+
/// by an amount larger than the threshold defined in [`GamepadSettings`].
10731093
#[derive(Event, Debug, Clone, PartialEq, Reflect)]
10741094
#[reflect(Debug, PartialEq)]
10751095
#[cfg_attr(
@@ -1078,12 +1098,16 @@ impl GamepadConnectionEvent {
10781098
reflect(Serialize, Deserialize)
10791099
)]
10801100
pub struct GamepadAxisChangedEvent {
1101+
/// The gamepad on which the axis is triggered.
10811102
pub gamepad: Gamepad,
1103+
/// The type of the triggered axis.
10821104
pub axis_type: GamepadAxisType,
1105+
/// The value of the axis.
10831106
pub value: f32,
10841107
}
10851108

10861109
impl GamepadAxisChangedEvent {
1110+
/// Creates a [`GamepadAxisChangedEvent`].
10871111
pub fn new(gamepad: Gamepad, axis_type: GamepadAxisType, value: f32) -> Self {
10881112
Self {
10891113
gamepad,
@@ -1103,12 +1127,16 @@ impl GamepadAxisChangedEvent {
11031127
reflect(Serialize, Deserialize)
11041128
)]
11051129
pub struct GamepadButtonChangedEvent {
1130+
/// The gamepad on which the button is triggered.
11061131
pub gamepad: Gamepad,
1132+
/// The type of the triggered button.
11071133
pub button_type: GamepadButtonType,
1134+
/// The value of the button.
11081135
pub value: f32,
11091136
}
11101137

11111138
impl GamepadButtonChangedEvent {
1139+
/// Creates a [`GamepadButtonChangedEvent`].
11121140
pub fn new(gamepad: Gamepad, button_type: GamepadButtonType, value: f32) -> Self {
11131141
Self {
11141142
gamepad,
@@ -1163,8 +1191,11 @@ pub fn gamepad_button_event_system(
11631191
reflect(Serialize, Deserialize)
11641192
)]
11651193
pub enum GamepadEvent {
1194+
/// A gamepad has been connected or disconnected.
11661195
Connection(GamepadConnectionEvent),
1196+
/// A button of the gamepad has been triggered.
11671197
Button(GamepadButtonChangedEvent),
1198+
/// An axis of the gamepad has been triggered.
11681199
Axis(GamepadAxisChangedEvent),
11691200
}
11701201

@@ -1242,54 +1273,54 @@ const ALL_AXIS_TYPES: [GamepadAxisType; 6] = [
12421273
/// The intensity at which a gamepad's force-feedback motors may rumble.
12431274
#[derive(Clone, Copy, Debug, PartialEq)]
12441275
pub struct GamepadRumbleIntensity {
1245-
/// The rumble intensity of the strong gamepad motor
1276+
/// The rumble intensity of the strong gamepad motor.
12461277
///
1247-
/// Ranges from 0.0 to 1.0
1278+
/// Ranges from `0.0` to `1.0`.
12481279
///
12491280
/// By convention, this is usually a low-frequency motor on the left-hand
12501281
/// side of the gamepad, though it may vary across platforms and hardware.
12511282
pub strong_motor: f32,
1252-
/// The rumble intensity of the weak gamepad motor
1283+
/// The rumble intensity of the weak gamepad motor.
12531284
///
1254-
/// Ranges from 0.0 to 1.0
1285+
/// Ranges from `0.0` to `1.0`.
12551286
///
12561287
/// By convention, this is usually a high-frequency motor on the right-hand
12571288
/// side of the gamepad, though it may vary across platforms and hardware.
12581289
pub weak_motor: f32,
12591290
}
12601291

12611292
impl GamepadRumbleIntensity {
1262-
/// Rumble both gamepad motors at maximum intensity
1293+
/// Rumble both gamepad motors at maximum intensity.
12631294
pub const MAX: Self = GamepadRumbleIntensity {
12641295
strong_motor: 1.0,
12651296
weak_motor: 1.0,
12661297
};
12671298

1268-
/// Rumble the weak motor at maximum intensity
1299+
/// Rumble the weak motor at maximum intensity.
12691300
pub const WEAK_MAX: Self = GamepadRumbleIntensity {
12701301
strong_motor: 0.0,
12711302
weak_motor: 1.0,
12721303
};
12731304

1274-
/// Rumble the strong motor at maximum intensity
1305+
/// Rumble the strong motor at maximum intensity.
12751306
pub const STRONG_MAX: Self = GamepadRumbleIntensity {
12761307
strong_motor: 1.0,
12771308
weak_motor: 0.0,
12781309
};
12791310

1280-
/// Creates a new rumble intensity with weak motor intensity set to the given value
1311+
/// Creates a new rumble intensity with weak motor intensity set to the given value.
12811312
///
1282-
/// Clamped within the 0 to 1 range
1313+
/// Clamped within the `0.0` to `1.0` range.
12831314
pub const fn weak_motor(intensity: f32) -> Self {
12841315
Self {
12851316
weak_motor: intensity,
12861317
strong_motor: 0.0,
12871318
}
12881319
}
12891320

1290-
/// Creates a new rumble intensity with strong motor intensity set to the given value
1321+
/// Creates a new rumble intensity with strong motor intensity set to the given value.
12911322
///
1292-
/// Clamped within the 0 to 1 range
1323+
/// Clamped within the `0.0` to `1.0` range.
12931324
pub const fn strong_motor(intensity: f32) -> Self {
12941325
Self {
12951326
strong_motor: intensity,
@@ -1298,7 +1329,7 @@ impl GamepadRumbleIntensity {
12981329
}
12991330
}
13001331

1301-
/// An event that controls force-feedback rumbling of a [`Gamepad`]
1332+
/// An event that controls force-feedback rumbling of a [`Gamepad`].
13021333
///
13031334
/// # Notes
13041335
///
@@ -1340,19 +1371,22 @@ pub enum GamepadRumbleRequest {
13401371
///
13411372
/// To replace an existing rumble, send a [`GamepadRumbleRequest::Stop`] event first.
13421373
Add {
1343-
/// How long the gamepad should rumble
1374+
/// How long the gamepad should rumble.
13441375
duration: Duration,
1345-
/// How intense the rumble should be
1376+
/// How intense the rumble should be.
13461377
intensity: GamepadRumbleIntensity,
1347-
/// The gamepad to rumble
1378+
/// The gamepad to rumble.
1379+
gamepad: Gamepad,
1380+
},
1381+
/// Stop all running rumbles on the given [`Gamepad`].
1382+
Stop {
1383+
/// The gamepad to stop rumble.
13481384
gamepad: Gamepad,
13491385
},
1350-
/// Stop all running rumbles on the given [`Gamepad`]
1351-
Stop { gamepad: Gamepad },
13521386
}
13531387

13541388
impl GamepadRumbleRequest {
1355-
/// Get the [`Gamepad`] associated with this request
1389+
/// Get the [`Gamepad`] associated with this request.
13561390
pub fn gamepad(&self) -> Gamepad {
13571391
match self {
13581392
Self::Add { gamepad, .. } | Self::Stop { gamepad } => *gamepad,

0 commit comments

Comments
 (0)