docs: Documentation and clean up of bevy_input#3692
Conversation
Continued updating bevy_input. Small fixes.
| pub fn gilrs_event_startup_system(gilrs: NonSend<Gilrs>, mut events: EventWriter<GamepadEventRaw>) { | ||
| for (id, _) in gilrs.gamepads() { | ||
| events.send(GamepadEventRaw( | ||
| events.send(GamepadEventRaw::new( |
There was a problem hiding this comment.
On review, I think this is nicer than the tuple structs.
There was a problem hiding this comment.
Not sure if I like it better than a named struct though.
There was a problem hiding this comment.
In my eyes tuple structs should be avoided in most cases, because they are a pain to work with. I'm fine with both the named struct and the new() constructor. Would probably be a good idea to have a place where we note things like this so we can keep things consistent.
There was a problem hiding this comment.
Yeah, we have an engine style guide: https://github.com/bevyengine/bevy/blob/main/.github/contributing/engine_style_guide.md
@cart, do you have strong feelings?
alice-i-cecile
left a comment
There was a problem hiding this comment.
Excellent work. The tests are great, the docs are clear and comprehensive, the cleanup is solid and uncontroversial. #3419 should be rebased on top of this IMO.
I'll do another pass once these comments are addressed.
|
@alice-i-cecile Done. There is still an open conversation about the |
|
@KDecay WRT Regardless, I think that's out of scope for this PR :) |
|
I agree. It would be a great idea to collect them all and discuss what we want to do with them. I resolved the conversation for now. Currently the only open thing in here is which type of struct creation we prefer:
|
@cart, when you get a chance could you weigh in on this? Then we'll add the decision to the style guide. |
|
This PR should be merged before #3419. |
|
the merge commit may have gone wrong |
|
Did it? Looking at the |
|
My bad, somehow GitHub UI is not loading for me when I try to view the changes. Loading it when in another browser works fine 🤷 |
|
@bevyengine/docs-team Can I get a couple more eyes on this? IMO this should be merged ASAP, to unblock more improvements to |
|
@BoxyUwU isn't thrilled with the addition of the I wrote my own replacement for it here: https://github.com/Leafwing-Studios/leafwing_input_manager/blob/main/macros/src/actionlike.rs. IMO we should remove that change from this PR, and then remind me to make a PR to port that macro over. |
|
Done. You could create an issue for it so we don't forget and can worry about fixing it another time. |
# Objective - Part of the splitting process of #3692. ## Solution - Remove / change the tuple structs inside of `gamepad.rs` of `bevy_input` to normal structs. ## Reasons - It made the `gamepad_connection_system` cleaner. - It made the `gamepad_input_events.rs` example cleaner (which is probably the most notable change for the user facing API). - Tuple structs are not descriptive (`.0`, `.1`). - Using tuple structs for more than 1 field is a bad idea (This means that the `Gamepad` type might be fine as a tuple struct, but I still prefer normal structs over tuple structs). Feel free to discuss this change as this is more or less just a matter of taste. ## Changelog ### Changed - The `Gamepad`, `GamepadButton`, `GamepadAxis`, `GamepadEvent` and `GamepadEventRaw` types are now normal structs instead of tuple structs and have a `new()` function. ## Migration Guide - The `Gamepad`, `GamepadButton`, `GamepadAxis`, `GamepadEvent` and `GamepadEventRaw` types are now normal structs instead of tuple structs and have a `new()` function. To migrate change every instantiation to use the `new()` function instead and use the appropriate field names instead of `.0` and `.1`.
# Objective - Part of the splitting process of #3692. ## Solution - Remove / change the tuple structs inside of `gamepad.rs` of `bevy_input` to normal structs. ## Reasons - It made the `gamepad_connection_system` cleaner. - It made the `gamepad_input_events.rs` example cleaner (which is probably the most notable change for the user facing API). - Tuple structs are not descriptive (`.0`, `.1`). - Using tuple structs for more than 1 field is a bad idea (This means that the `Gamepad` type might be fine as a tuple struct, but I still prefer normal structs over tuple structs). Feel free to discuss this change as this is more or less just a matter of taste. ## Changelog ### Changed - The `Gamepad`, `GamepadButton`, `GamepadAxis`, `GamepadEvent` and `GamepadEventRaw` types are now normal structs instead of tuple structs and have a `new()` function. ## Migration Guide - The `Gamepad`, `GamepadButton`, `GamepadAxis`, `GamepadEvent` and `GamepadEventRaw` types are now normal structs instead of tuple structs and have a `new()` function. To migrate change every instantiation to use the `new()` function instead and use the appropriate field names instead of `.0` and `.1`.
# Objective - Part of the splitting process of #3692. ## Solution - Document `keyboard.rs` inside of `bevy_input`. Co-authored-by: KDecay <KDecayMusic@protonmail.com>
# Objective - Part of the splitting process of bevyengine#3692. ## Solution - Document `keyboard.rs` inside of `bevy_input`. Co-authored-by: KDecay <KDecayMusic@protonmail.com>
# Objective - Part of the splitting process of bevyengine#3692. ## Solution - Document `system.rs` inside of `bevy_input`.
# Objective - Part of the splitting process of bevyengine#3692. ## Solution - Rename `ElementState` to `ButtonState` ## Reasons - The old name was too generic. - If something can be pressed it is automatically button-like (thanks to @alice-i-cecile for bringing it up in bevyengine#3692). - The reason it is called `ElementState` is because that's how `winit` calls it. - It is used to define if a keyboard or mouse **button** is pressed or not. - Discussion in bevyengine#3692. ## Changelog ### Changed - The `ElementState` type received a rename and is now called `ButtonState`. ## Migration Guide - The `ElementState` type received a rename and is now called `ButtonState`. To migrate you just have to change every occurrence of `ElementState` to `ButtonState`. Co-authored-by: KDecay <KDecayMusic@protonmail.com>
# Objective - Part of the splitting process of bevyengine#3692. ## Solution - Document `input.rs` inside of `bevy_input`.
# Objective - Part of the splitting process of bevyengine#3692. ## Solution - Add more tests to `input.rs` inside of `bevy_input`. ## Note - The tests would now catch a change like bevyengine#4410 and fail accordingly.
# Objective - Part of the splitting process of bevyengine#3692. ## Solution - Document `mouse.rs` inside of `bevy_input`. Co-authored-by: KDecay <KDecayMusic@protonmail.com>
# Objective - Part of the splitting process of bevyengine#3692. ## Solution - Remove / change the tuple structs inside of `gamepad.rs` of `bevy_input` to normal structs. ## Reasons - It made the `gamepad_connection_system` cleaner. - It made the `gamepad_input_events.rs` example cleaner (which is probably the most notable change for the user facing API). - Tuple structs are not descriptive (`.0`, `.1`). - Using tuple structs for more than 1 field is a bad idea (This means that the `Gamepad` type might be fine as a tuple struct, but I still prefer normal structs over tuple structs). Feel free to discuss this change as this is more or less just a matter of taste. ## Changelog ### Changed - The `Gamepad`, `GamepadButton`, `GamepadAxis`, `GamepadEvent` and `GamepadEventRaw` types are now normal structs instead of tuple structs and have a `new()` function. ## Migration Guide - The `Gamepad`, `GamepadButton`, `GamepadAxis`, `GamepadEvent` and `GamepadEventRaw` types are now normal structs instead of tuple structs and have a `new()` function. To migrate change every instantiation to use the `new()` function instead and use the appropriate field names instead of `.0` and `.1`.
# Objective - Part of the splitting process of bevyengine#3692. ## Solution - Document `keyboard.rs` inside of `bevy_input`. Co-authored-by: KDecay <KDecayMusic@protonmail.com>
# Objective - Part of the splitting process of bevyengine#3692. ## Solution - Change the `gamepad_connection_system` to run after the `InputSystem` label. ## Reasons I changed the `gamepad_connection_system` to run after the `InputSystem` instead of in parallel, because this system checks the `GamepadEvent`s which get send inside of the `gamepad_event_system`. This means that the `gamepad_connection_system` could respond to the events one frame later, instead of instantly resulting in one frame lag. Old possible case: 1. `gamepad_connection_system` (reacts to the `GamepadEvent`s too early) 2. `gamepad_event_system` (sends the `GamepadEvent`s) New fixed ordering: 1. `gamepad_event_system` (sends the `GamepadEvent`s) 2. `gamepad_connection_system` (reacts to the `GamepadEvent`s)
# Objective - Fixes bevyengine#5544 - Part of the splitting process of bevyengine#3692. ## Solution - Document everything in the `gamepad.rs` file. - Add a doc example for mocking gamepad input. --- ## Changelog - Added and updated the documentation inside of the `gamepad.rs` file.
# Objective - Fixes bevyengine#5544 - Part of the splitting process of bevyengine#3692. ## Solution - Document everything in the `gamepad.rs` file. - Add a doc example for mocking gamepad input. --- ## Changelog - Added and updated the documentation inside of the `gamepad.rs` file.
# Objective - Fixes bevyengine#5544 - Part of the splitting process of bevyengine#3692. ## Solution - Document everything in the `gamepad.rs` file. - Add a doc example for mocking gamepad input. --- ## Changelog - Added and updated the documentation inside of the `gamepad.rs` file.
# Objective - Part of the splitting process of bevyengine#3692. ## Solution - Change the `gamepad_connection_system` to run after the `InputSystem` label. ## Reasons I changed the `gamepad_connection_system` to run after the `InputSystem` instead of in parallel, because this system checks the `GamepadEvent`s which get send inside of the `gamepad_event_system`. This means that the `gamepad_connection_system` could respond to the events one frame later, instead of instantly resulting in one frame lag. Old possible case: 1. `gamepad_connection_system` (reacts to the `GamepadEvent`s too early) 2. `gamepad_event_system` (sends the `GamepadEvent`s) New fixed ordering: 1. `gamepad_event_system` (sends the `GamepadEvent`s) 2. `gamepad_connection_system` (reacts to the `GamepadEvent`s)
# Objective - Part of the splitting process of bevyengine#3692. ## Solution - Document `touch.rs` inside of `bevy_input`.
# Objective - Part of the splitting process of bevyengine#3692. ## Solution - Document `axis.rs` inside of `bevy_input`.
# Objective - Part of the splitting process of bevyengine#3692. ## Solution - Document `system.rs` inside of `bevy_input`.
# Objective - Part of the splitting process of bevyengine#3692. ## Solution - Rename `ElementState` to `ButtonState` ## Reasons - The old name was too generic. - If something can be pressed it is automatically button-like (thanks to @alice-i-cecile for bringing it up in bevyengine#3692). - The reason it is called `ElementState` is because that's how `winit` calls it. - It is used to define if a keyboard or mouse **button** is pressed or not. - Discussion in bevyengine#3692. ## Changelog ### Changed - The `ElementState` type received a rename and is now called `ButtonState`. ## Migration Guide - The `ElementState` type received a rename and is now called `ButtonState`. To migrate you just have to change every occurrence of `ElementState` to `ButtonState`. Co-authored-by: KDecay <KDecayMusic@protonmail.com>
# Objective - Part of the splitting process of bevyengine#3692. ## Solution - Document `input.rs` inside of `bevy_input`.
# Objective - Part of the splitting process of bevyengine#3692. ## Solution - Add more tests to `input.rs` inside of `bevy_input`. ## Note - The tests would now catch a change like bevyengine#4410 and fail accordingly.
# Objective - Part of the splitting process of bevyengine#3692. ## Solution - Document `mouse.rs` inside of `bevy_input`. Co-authored-by: KDecay <KDecayMusic@protonmail.com>
# Objective - Part of the splitting process of bevyengine#3692. ## Solution - Remove / change the tuple structs inside of `gamepad.rs` of `bevy_input` to normal structs. ## Reasons - It made the `gamepad_connection_system` cleaner. - It made the `gamepad_input_events.rs` example cleaner (which is probably the most notable change for the user facing API). - Tuple structs are not descriptive (`.0`, `.1`). - Using tuple structs for more than 1 field is a bad idea (This means that the `Gamepad` type might be fine as a tuple struct, but I still prefer normal structs over tuple structs). Feel free to discuss this change as this is more or less just a matter of taste. ## Changelog ### Changed - The `Gamepad`, `GamepadButton`, `GamepadAxis`, `GamepadEvent` and `GamepadEventRaw` types are now normal structs instead of tuple structs and have a `new()` function. ## Migration Guide - The `Gamepad`, `GamepadButton`, `GamepadAxis`, `GamepadEvent` and `GamepadEventRaw` types are now normal structs instead of tuple structs and have a `new()` function. To migrate change every instantiation to use the `new()` function instead and use the appropriate field names instead of `.0` and `.1`.
# Objective - Part of the splitting process of bevyengine#3692. ## Solution - Document `keyboard.rs` inside of `bevy_input`. Co-authored-by: KDecay <KDecayMusic@protonmail.com>
Part of #3492.
Objective
bevy_inputdocumentation to achieve a 100% documentation coverage.#![warn(missing_docs)]lint to keep the documentation coverage for the future.Solution
#[warn(missing_docs)]to thelib.rsfile.cargo +nightly doc -p bevy_input --all-features --no-depscommand with theRUSTDOCFLAGS="-Z unstable-options -- show-coverage"environment variable which returned a doc coverage of 100%.Additional work
I did some additional work while documenting the crate. I'm happy to change/discuss any of these.
Tuple structs
I changed
GamepadAxis,GamepadButton,Gamepad,GamepadEvent, andGamepadEventRawto be normal structs instead of tuple structs. Main reason being is that tuple structs are not descriptive and extending them is harder.Constructors
I added
new()functions toGamepadAxis,GamepadButton,GamepadEvent,GamepadEventRaw,Gamepad,KeyboardInput,MouseButtonInput,MouseMotion,MouseWheel, andTouchInput. The main reason being that it made changing the tuple structs to normal structs easier. The Events also received anew()function that isn't used inside ofBevy, but I thought it would be a good idea to add them for consistency and also for users ofBevythat might use these to simulate inputs (for tests or even game logic).Structure change
I split up the
keyboard.rs,mouse.rs,gamepad.rs, andtouch.rsfiles into smaller chunks, because some of these files were quite huge and hard to navigate (especiallygamepad.rs).Logic change
I changed the
gamepad_connection_systemto run after theInputSysteminstead of in parallel, because this system checks theGamepadEvents which get send inside of thegamepad_event_system. This means that thegamepad_connection_systemcould respond to the events one frame later, instead of instantly resulting in one frame lag.Old possible case:
gamepad_connection_system(reacts to theGamepadEvents too early)gamepad_event_system(sends theGamepadEvents)New:
gamepad_event_system(sends theGamepadEvents)gamepad_connection_system(reacts to theGamepadEvents)Removed constants
I removed the
Axis::MINandAxis::Maxconstants, because they were only used inside of one spot. I also removed theALL_BUTTON_TYPESandALL_AXIS_TYPESconstants, because I addedstruminstead to use theEnumIterinstead (as suggested by @alice-i-cecile).Renamed
ElementStateI renamed the
ElementStatetoButtonStateas the old name was too generic and if something can be pressed it is automatically button-like (thanks to @alice-i-cecile for bringing it up).Breaking Changes
GamepadAxis,GamepadButton,Gamepad,GamepadEvent, andGamepadEventRaware no longer tuple structs. To create instances of them you would have to use thenew()function or a struct literal.Axis::MIN,Axis::Max,ALL_BUTTON_TYPESandALL_AXIS_TYPESconstants have been removed. The minimum axis value is-1.0and the maximum axis value is1.0. To iterate through theGamepadButtonTypes andGamepadAxisTypes you can now use theiter()method provided bystrum(GamepadButtonType::iter()orGamepadAxisType::iter()).ElementStatereceived a rename and is now calledButtonState.