Skip to content

Commit 543065a

Browse files
committed
Add GamepadButtonEvent::d_pad_direction
1 parent b77b549 commit 543065a

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

lighthouse-protocol/src/input/gamepad_button_event.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use serde::{Deserialize, Serialize};
22

3+
use crate::{Delta, Unity, Zero};
4+
35
/// A button event on a gamepad.
46
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
57
#[serde(tag = "control", rename_all = "camelCase")]
@@ -11,3 +13,17 @@ pub struct GamepadButtonEvent {
1113
/// The value of the button (between 0.0 and 1.0, modeled after the Web Gamepad API).
1214
pub value: f64,
1315
}
16+
17+
impl GamepadButtonEvent {
18+
/// The direction if one of the D-pad buttons was pressed.
19+
/// See https://www.w3.org/TR/gamepad/#dfn-standard-gamepad
20+
pub fn d_pad_direction<T>(&self) -> Option<Delta<T>> where T: Zero + Unity {
21+
match self.index {
22+
12 => Some(Delta::UP),
23+
13 => Some(Delta::DOWN),
24+
14 => Some(Delta::LEFT),
25+
15 => Some(Delta::RIGHT),
26+
_ => None,
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)