bevy
bevy copied to clipboard
Add custom cursors
Objective
- Add custom images as cursors
- Fixes #9557
Solution
- Change cursor type to accommodate both native and image cursors
- I don't really like this solution because I couldn't use
Handle<Image>directly. I would need to importbevy_assetsand that causes a circular dependency. Alternatively we could use winit'sCustomCursorsmart pointers, but that seems hard because the event loop is needed to create those and is not easily accessable for users. So now I need to copy around rgba buffers which is sad. - I use a cache because especially on the web creating cursor images is really slow
- Sorry to #14196 for yoinking, I just wanted to make a quick solution for myself and thought that I should probably share it too.
Testing
- Added example which works fine at least on Linux Wayland (winit side has been tested with all platforms).
- I haven't tested if the url cursor works.
Migration Guide
CursorIconis now an enum which can hold custom images in addition to system icons. It's also notCopyanymore.- Old
CursorIconis renamed toNativeCursorIcon