Crate input_helper

Source
Expand description

The main job of Input Helper is to provide a single, unified way to process input from any input framework.

§The Problem

Most libraries that take user input do so in a library-specific way. In order to use the library, you must write library-specific code.

For example: You can’t switch from Winit to SDL, or Gilrs to SDL, or any other library without having to rewrite all your input code. This can either couple your project to specific framework(s), or force you to waste time duplicating code. In the case of using multiple input libraries, such as pairing Winit and Gilrs you must handle each framework separately.

§The Solution

Library-specific input events can be converted to InputEvents, and sent through Input Helper using InputHelper::send(). Then your application code can be written against Input Helper. If you ever need to switch your input system, then there’s no need to rewrite your business logic. This also allows you to process all input in a single place regardless of its source.

Input Helper will provide default integration functions for common frameworks such as Winit, SDL, and Gilrs.

§Getting Started

Create the InputHelper and send it some InputEvent events.

use input_helper::*;

let input_helper = InputHelper::new();

input_helper.send(InputEvent::KeyDown("a"));
input_helper.send(InputEvent::KeyUp("a"));

Read events using an InputReader. You can request a new InputReader using InputHelper::reader().

let input_reader = input_helper.reader();

for input in input_reader.read() {
    // Do something cool.
}

Query input state using an InputMap. An InputMap is created from an existing InputHelper instance.

let mut input_map = InputMap::new(&input_helper);

input_map.update(); // Read queued events and update the input state.
input_map.is_pressed("a"); // Query the input state.

Structs§

InputHelper
Provides a generic input event queue.
InputMap
Provide a map for querying the current input state.

Enums§

ButtonState
Provides state for a button, indicating if it is currently up or down.
InputEvent
Provides a set of generic input events.
InputState
Represents the current state of an input for the InputMap.

Type Aliases§

InputFeed
Defines a Feed of InputEvents.
InputName
Defines the type used for naming inputs.
InputReader
Defines a Reader for InputEvents.