bevy
bevy copied to clipboard
Make grab_mode a bool instead of enum
Objective
- Closes https://github.com/bevyengine/bevy/issues/6590
- The grab mode is platform dependent, this is problematic for bevy users since we can't easily use the recommended way to detect if the feature works like the winit docs recommend https://docs.rs/winit/0.27.5/winit/window/struct.Window.html#method.set_cursor_grab
Solution
Use a bool to represent the grab_mode on the bevy window and internally try to use the available mode like recommended by the winit docs.
Changelog
- Renamed
set_cursor_grab_modeandcursor_grab_modetoset_cursor_grabbed()andcursor_grabbed() set_cursor_grabbed()now takes a bool instead of an enumcursor_grabbed()now returns a bool
Migration Guide
// 0.9
// macos
window.set_cursor_grab_mode(CursorGrabMode::Locked);
// windows
window.set_cursor_grab_mode(CursorGrabMode::Confined);
// Now
window.set_cursor_grabbed(true);
Notes
~~Should we keep the grab_mode terminology? I'm not sure if I should rename this to something else.~~
Should we keep the existing api and add this new one to not break semver?
Yeah we should rename this to reflect the bool nature
Ugh, this is technically a breaking change :( I'm probably fine violating semver here: the provided API basically doesn't work.
One way to keep semver would be to keep the api and add a new one with bools. Maybe even tag the broken one as deprecated, but I'm not sure if deprecation warning break semver.
this was set_cursor_lock_mode in the 0.8 times
Yes, but I decided to keep the grab terminology to stay closer to winit. Would you say it's better to keep it named grab_mode instead of grabbed?
Yeah I like the idea of keeping the old API with a deprecation so we can put this in the point release
I reintroduced the api, but I modified the implementation a bit to avoid the error. This means that we technically don't need the boolean api, and this gives a tiny bit more control to the user. I left both in the PR for now, but I'm not sure what to do here.
Updated to only use the fixed api and don't introduce a new api or remove anything.
I'm very happy with this now. Can you update your PR description?
I updated the title and changed the docs a little bit to reflect that it's possible that the getter will return a value that is different from the one sent to winit.
Which commit is that? This PR shouldn't have any breaking commit.
Oh, is the issue that I made this PR from main? If that's the case then yeah the 0.9.1 release will only cherry pick this PR.
bors r+
Pull request successfully merged into main.
Build succeeded:
- build-and-install-on-iOS
- build-android
- build (macos-latest)
- build (ubuntu-latest)
- build-wasm
- build (windows-latest)
- build-without-default-features (bevy)
- build-without-default-features (bevy_ecs)
- build-without-default-features (bevy_reflect)
- check-compiles
- check-doc
- check-missing-examples-in-docs
- ci
- markdownlint
- run-examples
- run-examples-on-wasm
- run-examples-on-windows-dx12