@@ -27,13 +27,17 @@ pub enum AxisSettingsError {
27
27
/// Parameter `livezone_lowerbound` was not less than or equal to parameter `deadzone_lowerbound`.
28
28
#[ error( "invalid parameter values livezone_lowerbound {} deadzone_lowerbound {}, expected livezone_lowerbound <= deadzone_lowerbound" , . livezone_lowerbound, . deadzone_lowerbound) ]
29
29
LiveZoneLowerBoundGreaterThanDeadZoneLowerBound {
30
+ /// The value of the `livezone_lowerbound` parameter.
30
31
livezone_lowerbound : f32 ,
32
+ /// The value of the `deadzone_lowerbound` parameter.
31
33
deadzone_lowerbound : f32 ,
32
34
} ,
33
35
/// Parameter `deadzone_upperbound` was not less than or equal to parameter `livezone_upperbound`.
34
36
#[ error( "invalid parameter values livezone_upperbound {} deadzone_upperbound {}, expected deadzone_upperbound <= livezone_upperbound" , . livezone_upperbound, . deadzone_upperbound) ]
35
37
DeadZoneUpperBoundGreaterThanLiveZoneUpperBound {
38
+ /// The value of the `livezone_upperbound` parameter.
36
39
livezone_upperbound : f32 ,
40
+ /// The value of the `deadzone_upperbound` parameter.
37
41
deadzone_upperbound : f32 ,
38
42
} ,
39
43
/// The given parameter was not in range 0.0..=2.0.
@@ -53,7 +57,9 @@ pub enum ButtonSettingsError {
53
57
/// Parameter `release_threshold` was not less than or equal to `press_threshold`.
54
58
#[ error( "invalid parameter values release_threshold {} press_threshold {}, expected release_threshold <= press_threshold" , . release_threshold, . press_threshold) ]
55
59
ReleaseThresholdGreaterThanPressThreshold {
60
+ /// The value of the `press_threshold` parameter.
56
61
press_threshold : f32 ,
62
+ /// The value of the `release_threshold` parameter.
57
63
release_threshold : f32 ,
58
64
} ,
59
65
}
@@ -100,6 +106,11 @@ impl Gamepad {
100
106
reflect( Serialize , Deserialize )
101
107
) ]
102
108
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".
103
114
pub name : String ,
104
115
}
105
116
@@ -130,6 +141,7 @@ impl Gamepads {
130
141
self . gamepads . keys ( ) . copied ( )
131
142
}
132
143
144
+ /// The name of the gamepad if this one is connected.
133
145
pub fn name ( & self , gamepad : Gamepad ) -> Option < & str > {
134
146
self . gamepads . get ( & gamepad) . map ( |g| g. name . as_str ( ) )
135
147
}
@@ -1025,6 +1037,7 @@ pub fn gamepad_connection_system(
1025
1037
}
1026
1038
}
1027
1039
1040
+ /// The connection status of a gamepad.
1028
1041
#[ derive( Debug , Clone , PartialEq , Reflect ) ]
1029
1042
#[ reflect( Debug , PartialEq ) ]
1030
1043
#[ cfg_attr(
@@ -1033,7 +1046,9 @@ pub fn gamepad_connection_system(
1033
1046
reflect( Serialize , Deserialize )
1034
1047
) ]
1035
1048
pub enum GamepadConnection {
1049
+ /// The gamepad is connected.
1036
1050
Connected ( GamepadInfo ) ,
1051
+ /// The gamepad is disconnected.
1037
1052
Disconnected ,
1038
1053
}
1039
1054
@@ -1054,22 +1069,27 @@ pub struct GamepadConnectionEvent {
1054
1069
}
1055
1070
1056
1071
impl GamepadConnectionEvent {
1072
+ /// Creates a [`GamepadConnectionEvent`].
1057
1073
pub fn new ( gamepad : Gamepad , connection : GamepadConnection ) -> Self {
1058
1074
Self {
1059
1075
gamepad,
1060
1076
connection,
1061
1077
}
1062
1078
}
1063
1079
1080
+ /// Is the gamepad connected?
1064
1081
pub fn connected ( & self ) -> bool {
1065
1082
matches ! ( self . connection, GamepadConnection :: Connected ( _) )
1066
1083
}
1067
1084
1085
+ /// Is the gamepad disconnected?
1068
1086
pub fn disconnected ( & self ) -> bool {
1069
1087
!self . connected ( )
1070
1088
}
1071
1089
}
1072
1090
1091
+ /// Gamepad event for when the "value" on the axis changes
1092
+ /// by an amount larger than the threshold defined in [`GamepadSettings`].
1073
1093
#[ derive( Event , Debug , Clone , PartialEq , Reflect ) ]
1074
1094
#[ reflect( Debug , PartialEq ) ]
1075
1095
#[ cfg_attr(
@@ -1078,12 +1098,16 @@ impl GamepadConnectionEvent {
1078
1098
reflect( Serialize , Deserialize )
1079
1099
) ]
1080
1100
pub struct GamepadAxisChangedEvent {
1101
+ /// The gamepad on which the axis is triggered.
1081
1102
pub gamepad : Gamepad ,
1103
+ /// The type of the triggered axis.
1082
1104
pub axis_type : GamepadAxisType ,
1105
+ /// The value of the axis.
1083
1106
pub value : f32 ,
1084
1107
}
1085
1108
1086
1109
impl GamepadAxisChangedEvent {
1110
+ /// Creates a [`GamepadAxisChangedEvent`].
1087
1111
pub fn new ( gamepad : Gamepad , axis_type : GamepadAxisType , value : f32 ) -> Self {
1088
1112
Self {
1089
1113
gamepad,
@@ -1103,12 +1127,16 @@ impl GamepadAxisChangedEvent {
1103
1127
reflect( Serialize , Deserialize )
1104
1128
) ]
1105
1129
pub struct GamepadButtonChangedEvent {
1130
+ /// The gamepad on which the button is triggered.
1106
1131
pub gamepad : Gamepad ,
1132
+ /// The type of the triggered button.
1107
1133
pub button_type : GamepadButtonType ,
1134
+ /// The value of the button.
1108
1135
pub value : f32 ,
1109
1136
}
1110
1137
1111
1138
impl GamepadButtonChangedEvent {
1139
+ /// Creates a [`GamepadButtonChangedEvent`].
1112
1140
pub fn new ( gamepad : Gamepad , button_type : GamepadButtonType , value : f32 ) -> Self {
1113
1141
Self {
1114
1142
gamepad,
@@ -1163,8 +1191,11 @@ pub fn gamepad_button_event_system(
1163
1191
reflect( Serialize , Deserialize )
1164
1192
) ]
1165
1193
pub enum GamepadEvent {
1194
+ /// A gamepad has been connected or disconnected.
1166
1195
Connection ( GamepadConnectionEvent ) ,
1196
+ /// A button of the gamepad has been triggered.
1167
1197
Button ( GamepadButtonChangedEvent ) ,
1198
+ /// An axis of the gamepad has been triggered.
1168
1199
Axis ( GamepadAxisChangedEvent ) ,
1169
1200
}
1170
1201
@@ -1242,54 +1273,54 @@ const ALL_AXIS_TYPES: [GamepadAxisType; 6] = [
1242
1273
/// The intensity at which a gamepad's force-feedback motors may rumble.
1243
1274
#[ derive( Clone , Copy , Debug , PartialEq ) ]
1244
1275
pub struct GamepadRumbleIntensity {
1245
- /// The rumble intensity of the strong gamepad motor
1276
+ /// The rumble intensity of the strong gamepad motor.
1246
1277
///
1247
- /// Ranges from 0.0 to 1.0
1278
+ /// Ranges from ` 0.0` to ` 1.0`.
1248
1279
///
1249
1280
/// By convention, this is usually a low-frequency motor on the left-hand
1250
1281
/// side of the gamepad, though it may vary across platforms and hardware.
1251
1282
pub strong_motor : f32 ,
1252
- /// The rumble intensity of the weak gamepad motor
1283
+ /// The rumble intensity of the weak gamepad motor.
1253
1284
///
1254
- /// Ranges from 0.0 to 1.0
1285
+ /// Ranges from ` 0.0` to ` 1.0`.
1255
1286
///
1256
1287
/// By convention, this is usually a high-frequency motor on the right-hand
1257
1288
/// side of the gamepad, though it may vary across platforms and hardware.
1258
1289
pub weak_motor : f32 ,
1259
1290
}
1260
1291
1261
1292
impl GamepadRumbleIntensity {
1262
- /// Rumble both gamepad motors at maximum intensity
1293
+ /// Rumble both gamepad motors at maximum intensity.
1263
1294
pub const MAX : Self = GamepadRumbleIntensity {
1264
1295
strong_motor : 1.0 ,
1265
1296
weak_motor : 1.0 ,
1266
1297
} ;
1267
1298
1268
- /// Rumble the weak motor at maximum intensity
1299
+ /// Rumble the weak motor at maximum intensity.
1269
1300
pub const WEAK_MAX : Self = GamepadRumbleIntensity {
1270
1301
strong_motor : 0.0 ,
1271
1302
weak_motor : 1.0 ,
1272
1303
} ;
1273
1304
1274
- /// Rumble the strong motor at maximum intensity
1305
+ /// Rumble the strong motor at maximum intensity.
1275
1306
pub const STRONG_MAX : Self = GamepadRumbleIntensity {
1276
1307
strong_motor : 1.0 ,
1277
1308
weak_motor : 0.0 ,
1278
1309
} ;
1279
1310
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.
1281
1312
///
1282
- /// Clamped within the 0 to 1 range
1313
+ /// Clamped within the `0.0` to `1.0` range.
1283
1314
pub const fn weak_motor ( intensity : f32 ) -> Self {
1284
1315
Self {
1285
1316
weak_motor : intensity,
1286
1317
strong_motor : 0.0 ,
1287
1318
}
1288
1319
}
1289
1320
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.
1291
1322
///
1292
- /// Clamped within the 0 to 1 range
1323
+ /// Clamped within the `0.0` to `1.0` range.
1293
1324
pub const fn strong_motor ( intensity : f32 ) -> Self {
1294
1325
Self {
1295
1326
strong_motor : intensity,
@@ -1298,7 +1329,7 @@ impl GamepadRumbleIntensity {
1298
1329
}
1299
1330
}
1300
1331
1301
- /// An event that controls force-feedback rumbling of a [`Gamepad`]
1332
+ /// An event that controls force-feedback rumbling of a [`Gamepad`].
1302
1333
///
1303
1334
/// # Notes
1304
1335
///
@@ -1340,19 +1371,22 @@ pub enum GamepadRumbleRequest {
1340
1371
///
1341
1372
/// To replace an existing rumble, send a [`GamepadRumbleRequest::Stop`] event first.
1342
1373
Add {
1343
- /// How long the gamepad should rumble
1374
+ /// How long the gamepad should rumble.
1344
1375
duration : Duration ,
1345
- /// How intense the rumble should be
1376
+ /// How intense the rumble should be.
1346
1377
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.
1348
1384
gamepad : Gamepad ,
1349
1385
} ,
1350
- /// Stop all running rumbles on the given [`Gamepad`]
1351
- Stop { gamepad : Gamepad } ,
1352
1386
}
1353
1387
1354
1388
impl GamepadRumbleRequest {
1355
- /// Get the [`Gamepad`] associated with this request
1389
+ /// Get the [`Gamepad`] associated with this request.
1356
1390
pub fn gamepad ( & self ) -> Gamepad {
1357
1391
match self {
1358
1392
Self :: Add { gamepad, .. } | Self :: Stop { gamepad } => * gamepad,
0 commit comments