You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This means that functions like key_pressed actually come with an invariant about when they can be called. (only when the window is focused, and if called multiple times between steps, it may return different results)
It also means that input actions can silently be dropped, for example when the following sequence of events happens
step
User presses W
Window loses focus <== all unfinished events get dropped
input.key_pressed(...)
step
I think it would be more elegant to have the step method return a struct that contains all the user inputs that have happened in a given frame. Let's call it WindowInputs.
So, the new flow would be
step
User presses W. WinitInputHelper internally updates everything
Window loses focus. WinitInputHelper simply sets a "lost focus" flag and ignores mouse motion events.
if let Some(inputs) = input.update(event) { if input.key_pressed(...) { ... } }
Where input.update will call step when appropriate, and return its WindowInputs struct.
This library currently uses a lot of Option<..>s to represent that the inputs are only valid at certain points in time.
This means that functions like
key_pressed
actually come with an invariant about when they can be called. (only when the window is focused, and if called multiple times betweenstep
s, it may return different results)It also means that input actions can silently be dropped, for example when the following sequence of events happens
W
input.key_pressed(...)
I think it would be more elegant to have the
step
method return a struct that contains all the user inputs that have happened in a given frame. Let's call itWindowInputs
.So, the new flow would be
W
.WinitInputHelper
internally updates everythingWinitInputHelper
simply sets a "lost focus" flag and ignores mouse motion events.if let Some(inputs) = input.update(event) { if input.key_pressed(...) { ... }
}Where
input.update
will callstep
when appropriate, and return itsWindowInputs
struct.I did, in fact, write my own library that works like this. It is heavily based on winit_input_helper, but makes a few different design decisions.
The text was updated successfully, but these errors were encountered: