-
Notifications
You must be signed in to change notification settings - Fork 932
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom cursor icon support #3039
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this is the kinda stuff that goes into src/platform/web.rs
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implementations are usually in platform_impl
indeed, but public platform-specific API is in platform
.
@@ -36,6 +37,7 @@ pub(crate) use self::event_loop::{ | |||
pub use self::monitor::{MonitorHandle, VideoMode}; | |||
pub use self::window::{PlatformSpecificWindowBuilderAttributes, Window, WindowId}; | |||
|
|||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub(crate) use crate::icon::NoIcon as PlatformIcon; |
Superseded by #3218 |
CHANGELOG.md
if 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_icon
method.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.