Custom cursor icon support#3039
Conversation
kchibisov
left a comment
There was a problem hiding this comment.
I'm not sure that reusing Icon is a good idea, how does it map to the cursor icon used on the platforms? I'm interested wrt macOS/Web/Windows, since X11/Wayland use just argb/xrgb buffers for all of that.
Also, without hotspot it's all kind of useless.
|
For web: you would have to use css and the "cursor" property, where you can specify a url, which can also be an base64 string, containing the png encoded cursor, but this is already how it works, its just a question of encoding the icon (rgba) to png and packing it into base64 For iOS: NSCursor has an instance method called initWithImage with NSImage and hotSpot, this would suggest Icon being of type NSImage, but cursor icon doesn't seem to implemented there? Good point, didn't thought about hotspot, would have to be platform-specific as for Windows and Web its part of the icon |
daxpedda
left a comment
There was a problem hiding this comment.
This isn't really feasible for Web like this.
Firstly PlatformIcon has to be split, because it's currently used for both cursor and window, in the case of Web window needs to continue using NoIcon but cursor now requires RgbaIcon.
Secondly adding the image dependency is overkill. I would argue that Web should support links before it starts supporting raw RGBA in the first place anyway. If we really want to support RGBA on Web then we should either use the png crate directly or use the WebAPI to do the conversion: ImageData -> ImageBitmap -> Canvas -> data URL.
Adding platform-specific formats shouldn't be a problem as they go through methods on Icon anyway.
|
I definitely agree with the image crate being overkill, and I'll split up Icon (as normal icons also don't need the hotspot property). Using urls could definitely be an option, and for RGBA, I'll take a look into utilizing the web api. |
# Conflicts: # CHANGELOG.md
|
Split-up Icon and CustomCursorIcon pub import, and switched to png crate, web also doesn't use RgbaImage and instead just the url repr. |
There was a problem hiding this comment.
I believe this is the kinda stuff that goes into src/platform/web.rs.
There was a problem hiding this comment.
The platform-specific implementation at least for Windows is in the platform_impl module, and they are exposed in platform, by extending Icon
Basically just copied it from there
There was a problem hiding this comment.
Implementations are usually in platform_impl indeed, but public platform-specific API is in platform.
|
|
||
| pub(crate) use self::icon::WebIcon as PlatformCustomCursorIcon; | ||
| pub(crate) use self::keyboard::KeyEventExtra; | ||
| pub(crate) use crate::icon::NoIcon as PlatformIcon; |
There was a problem hiding this comment.
| pub(crate) use crate::icon::NoIcon as PlatformIcon; |
|
Superseded by #3218 |
CHANGELOG.mdif knowledge of this change could be valuable to usersOne possible solution for #3005, adds a way to set custom icons in winit using the existing
Window::set_cursor_iconmethod.At the moment this is only a draft, because not all major platforms are implemented/tested
I can't really test for Apple platforms because I don't own Apple devices.