1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
//! Define actions and their list of input binds. and then see if its `pressing`, `pressed` or
//! `released`. This library handles variable pressure through the `value` function as well as
//! multiple variable pressure inputs for things like 1d axis (through `axis`) and 2d vectors
//! (through `dir` and `dir_max_len_1`). This makes it easy to have things like 3d camera controls
//! applied for both mouse movement and the gamepads right stick.
//!
//! The binds are structured by a list of `(Action, bind, bind, ..)`. An action is pressed if any
//! of its binds are pressed. Binds are described as either `[InputCode, InputCode, ..]` or
//! InputCode. A bind is pressed if all its InputCodes are pressed.
//!
//! The input map also can get the `mouse_pos`, what was `recently_pressed` (used for rebinding
//! things) and the `text_typed` (useful for typing) to make sure it is fully featured.
//! For better user control there are the `mouse_scale` and `scroll_scale` variables to make
//! sensitivity align with eveything else 0-1 range and a `press_sensitivity` to control when an
//! action counts as being pressed. Finaly, theres an `input_map!` macro to reduce boilerplate and
//! increase readability.
//! ```no_run
//! use winit::{
//! window::*, application::*, keyboard::*,
//! event_loop::*, event::*
//! };
//! use gilrs::Gilrs;
//! use winit_input_map::*;
//!
//! #[derive(Hash, PartialEq, Eq, Clone, Copy)]
//! enum Actions{ Foo }
//! use Actions::*;
//!
//! let input = { use base_input_codes::*; input_map!(
//! (Foo, KeyCode::Space, [GamepadInput::South, RightTrigger])
//! ) };
//! let ev = EventLoop::new().unwrap();
//! let gilrs = Gilrs::new().unwrap();
//! ev.run_app(&mut App { window: None, input, gilrs }).unwrap();
//!
//! struct App {
//! window: Option<Window>,
//! input: InputMap<Actions>,
//! gilrs: Gilrs
//! }
//! impl ApplicationHandler for App {
//! fn resumed(&mut self, event_loop: &ActiveEventLoop) {
//! let window_settings = Window::default_attributes();
//! let window = event_loop.create_window(window_settings);
//! self.window = Some(window.unwrap());
//! }
//! fn window_event(
//! &mut self, event_loop: &ActiveEventLoop, _: WindowId,
//! event: WindowEvent
//! ) {
//! self.input.update_with_window_event(&event);
//! if let WindowEvent::CloseRequested = &event
//! { event_loop.exit() }
//! }
//! fn device_event(
//! &mut self, _: &ActiveEventLoop, id: DeviceId,
//! event: DeviceEvent
//! ) {
//! self.input.update_with_device_event(id, &event);
//! }
//! fn about_to_wait(&mut self, _: &ActiveEventLoop) {
//! self.input.update_with_gilrs(&mut self.gilrs);
//!
//! // your code here!
//! if self.input.pressed(Foo) { println!("bar") }
//!
//! self.input.init();
//! }
//! }
//! ```
pub use crate*;
pub use crate*;
/// Outputs an input with the inputed binds.
///
/// The input is structured by a list of `(Action, bind, bind, ..)`. An action is pressed if any of
/// its binds are pressed.
///
/// Binds are described as either `[InputCode, InputCode, ..]` or InputCode. A bind is pressed if all
/// its InputCodes are pressed.
/// ```
/// use winit_input_map::*;
/// use Action::*;
/// #[derive(PartialEq, Eq, Clone, Copy, Hash, Debug)]
/// enum Action {
/// Select, Undo, Redo, Confirm
/// }
/// let input = { use base_input_codes::*; input_map!(
/// (Select, MouseButton::Left, ShiftLeft, ShiftRight),
/// (Action::Undo, [KeyZ, ControlLeft], [KeyZ, ControlRight]),
/// (Redo, [KeyR, ControlLeft], [KeyR, ControlRight]),
/// (Confirm, MouseButton::Left, Enter)
/// ) };
/// ```
/// Outputs binds in the expected format for `add_binds`, `set_binds` and `InputMap::new` though in
/// the latter case `input_map!` should be used to skip the middle man.
///
/// The input is structured by a list of `(Action, bind, bind, ..)`. An action is pressed if any of
/// its binds are pressed.
///
/// Binds are described as either `[InputCode, InputCode, ..]` or InputCode. A bind is pressed if all
/// its InputCodes are pressed.
/// ```
/// use winit_input_map::*;
/// use Action::*;
/// #[derive(PartialEq, Eq, Clone, Copy, Hash, Debug)]
/// enum Action {
/// Select, Undo, Redo, Confirm
/// }
/// let mut input = input_map!((Select, base_input_codes::ShiftLeft));
///
/// let binds = { use base_input_codes::*; binds!(
/// (Select, MouseButton::Left, ShiftRight),
/// (Action::Undo, [KeyZ, ControlLeft], [KeyZ, ControlRight], KeyCode::Undo),
/// (Redo, [KeyR, ControlLeft], [KeyR, ControlRight]),
/// (Confirm, MouseButton::Left, Enter)
/// ) };
///
/// input.add_binds(&binds);
/// ```
};
}