Table of contents
About
Input is relative; the library itself currently implements by default keyboard, mouse and gamepad support, but this is subject to change. Please feel free to contribute to the library by submitting pull requests. Touch support is stil planned, but not yet implemented.
ezinput strives to be simple as possible, while still being powerful and flexible without using any unsafe code.
All bindings are stored in a InputView struct, which is passed as a component to your ECS entitity. To allow an input method to be handled,
you need to add a service marker component (MouseMarker, KeyboardMarker or GamepadMarker) to the ECS entity. You aren't limited to one marker, since you can use multiple markers to handle multiple input methods. An advantage of this implementation is that input views aren't
limited to specific input sources, so you can reutilize the same view for multiple input methods just by adding new input receivers to bindings.
Not everything is documented yet or documented with a high level of detail, so any feedback is appreciated. You can contact me on Discord or here on GitHub!
Limitations
- Mouse wheel support is not implemented yet.
- Touch support is not implemented yet.
- Input receivers are limited only to implemented input sources.
- Input sources are a hard-coded enumeration (it might not be that bad in most cases though).
Branches
Getting started
Add the following to your Cargo.toml (replace ^0.3 with the latest version):
[]
= "^0.3"
- Now, you need to import
ezinput::prelude::*. - Create an input view by using the
input!macro. You can see an example here.
use *;
input!
// Is the same as this:
// #[derive(BindingTypeView, Debug, Clone, Copy, PartialEq, Eq, Hash)]
// pub enum EnumeratedBinding {
// Movement(EnumeratedMovementBinding),
// }
// #[derive(BindingTypeView, Debug, Clone, Copy, PartialEq, Eq, Hash)]
// pub enum EnumeratedMovementBinding {
// Vertical,
// Horizontal,
// }
// impl EnumeratedBinding {
// pub fn view() -> InputView<Self> {
// let mut view = InputView::new();
// EnumeratdMovementBinding::apply(&mut view);
// view
// }
// }
// impl EnumeratedMovementBinding {
// pub fn apply(view: &mut InputView<EnumeratedBinding>) {
// let mut binding = ActionBinding::from(EnumeratedBinding::Movement(EnumeratedMovementBinding::Vertical));
// binding.receiver(KeyboardKey(KeyCode::W));
// binding.receiver(KeyboardKey(KeyCode::S));
// binding.default_axis_value(KeyboardKey(KeyCode::S), -1);
// view.add_binding(binding);
// // ...
// }
// }