Consolidate input types to avoid portability hazards #107
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The following types have been moved from game_activity/input.rs to input.rs so they can be shared by both backends:
Axis, ButtonState, EdgeFlags, KeyAction, KeyEventFlags, Keycode, MetaState, MotionAction, MotionEventFlags
This addresses a portability hazard whereby code (such as Winit) would inadvertently use the
ndk
type which works OK with the native-activity backend but then wouldn't compile against the game-activity backend.The alternative of consolidating on the
ndk::events
types instead was considered but we've repeatedly needed to diverge from thendk
API for the sake of maintaining a consistent input API across thegame-activity
andnative-activity
backends (input is an area where the backends differ significantly in their implementation) and so it generally seems slightly preferable to consolidate on types from this crate (though it shouldn't make much difference for these types which are almost direct bindings from ndk_sys).The types can be converted to their
ndk::events
counterpart via theFrom
trait.For now some of the
From
trait implementations rely ontry_from().unwrap()
but the intention is to replace these with infallible implementations once we bump the MSRV > 1.66 where we can usenum_enum::FromPrimitive
after adding a catch-allOther(u32)
to these enums.Fixes: #92