Struct gilrs::Gilrs
[−]
[src]
pub struct Gilrs { /* fields omitted */ }
Main object responsible of managing gamepads.
Event loop
All interesting actions like button was pressed or new controller was connected are represented
by tuple (usize,
Event
)
. You should call poll_events()
method once in
your event loop and then iterate over all available events.
use gilrs::{Gilrs, Event, Button}; let mut gilrs = Gilrs::new(); // Event loop loop { for event in gilrs.poll_events() { match event { (id, Event::ButtonPressed(Button::South, _)) => { println!("Player {}: jump!", id + 1) } (id, Event::Disconnected) => println!("We lost player {}", id + 1), _ => (), }; } }
Additionally, every time you use poll_events()
, cached gamepad state is updated. Use
gamepad(usize)
method or index operator to borrow gamepad and then state()
,
is_pressed(Button)
or value(Axis)
to examine gamepad's state. See
Gamepad
for more info.
Methods
impl Gilrs
[src]
fn new() -> Self
Creates new Gilrs
.
fn with_mappings(sdl_mapping: &str) -> Self
Creates new Gilrs
and add content of sdl_mapping
to internal database. Each mapping
should be in separate line. Lines that does not start from UUID are ignored.
This function does not check validity of mappings.
fn poll_events(&mut self) -> EventIterator
Creates iterator over available events. See Event
for more information.
fn gamepad(&self, id: usize) -> &Gamepad
Borrow gamepad with given id. This method always return reference to some gamepad, even if
it was disconnected or never observed. If gamepad's status is not equal to
Status::Connected
all actions preformed on it are no-op and all values in cached gamepad
state are 0 (false for buttons and 0.0 for axes).
fn gamepad_mut(&mut self, id: usize) -> &mut Gamepad
See gamepad()
fn gamepads(&self) -> ConnectedGamepadsIterator
Returns iterator over all connected gamepads and their ids.
for (id, gamepad) in gilrs.gamepads() { assert!(gamepad.is_connected()); println!("Gamepad with id {} and name {} is connected", id, gamepad.name()); }
fn connected_gamepad(&self, id: usize) -> Option<&Gamepad>
Returns a reference to connected gamepad or None
.
fn connected_gamepad_mut(&mut self, id: usize) -> Option<&mut Gamepad>
Returns a mutable reference to connected gamepad or None
.
Trait Implementations
impl Debug for Gilrs
[src]
impl Index<usize> for Gilrs
[src]
type Output = Gamepad
The returned type after indexing
fn index(&self, idx: usize) -> &Gamepad
The method for the indexing (container[index]
) operation