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]

Creates new Gilrs.

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.

Creates iterator over available events. See Event for more information.

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).

See gamepad()

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());
}

Returns a reference to connected gamepad or None.

Returns a mutable reference to connected gamepad or None.

Trait Implementations

impl Debug for Gilrs
[src]

Formats the value using the given formatter.

impl Index<usize> for Gilrs
[src]

The returned type after indexing

The method for the indexing (container[index]) operation

impl IndexMut<usize> for Gilrs
[src]

The method for the mutable indexing (container[index]) operation