rich_sdl2_rust/event/joystick/
axis.rs1use std::os::raw::c_int;
4
5use crate::bind;
6
7use super::{InputIndex, Joystick};
8
9#[derive(Debug)]
11pub struct Axis<'joystick> {
12 index: c_int,
13 joystick: &'joystick Joystick,
14}
15
16impl<'joystick> Axis<'joystick> {
17 pub(super) fn new(index: InputIndex, joystick: &'joystick Joystick) -> Self {
18 Self {
19 index: index.0,
20 joystick,
21 }
22 }
23
24 #[must_use]
26 pub fn state(&self) -> i16 {
27 unsafe { bind::SDL_JoystickGetAxis(self.joystick.ptr.as_ptr(), self.index) }
28 }
29}
30
31#[derive(Debug)]
33pub struct Axes<'joystick>(pub Vec<Axis<'joystick>>);
34
35impl<'joystick> Axes<'joystick> {
36 pub(super) fn new(joystick: &'joystick Joystick) -> Self {
37 let num_axes = unsafe { bind::SDL_JoystickNumAxes(joystick.ptr.as_ptr()) };
38 let axes = (0..num_axes)
39 .map(|index| Axis { index, joystick })
40 .collect();
41 Self(axes)
42 }
43}