-
Notifications
You must be signed in to change notification settings - Fork 567
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 #1183
Custom cursor #1183
Conversation
cool, this is definitely something on my radar, so happy to have someone else interested too. My feeling is that this needs to be a per-platform thing in druid-shell, and shouldn't really concern piet. I think cursors are going to have to be resource files that are provided per-platform; at launch time you would load these in druid, and then you could reference them by some sort of name or id when you wanted to set the cursor. This per-platform resource thing is something (like application icons) that we haven't really tackled, yet, and so I'm just expressing my current best-guess for how this should work. I've skimmed this patch and it doesn't seem unreasonable, but my gut is still that cursor data should be opaque; It may be that different platforms have different conventions around cursor size, or how you indicate a cursor's hit-position relative to the image resource, etc etc. I'll give this some more thought, though! |
I looked at winit to see if they have this functionality (I think we should always try to learn from them), but it seems like they pretty much only have an enum of standard variants for now, though there is an issue to add custom cursors. Might be worth taking a closer look at that to see how they're thinking about it (again, I didn't dig in). Getting this really clean cross-platform might be challenging, especially because it's an area where the design of the cursor maybe should be platform-specific, but yes, it seems like useful functionality within the intended scope of druid-shell. I also have no problem with this moving forward. |
Regarding the cross-platform possibilities, I found the following information (mostly by googling and looking at API docs, which I didn't find particularly discoverable so I probably missed some things).
Leaving aside web for now, we basically seem to have a choice between 1) use platform-specific code to load image files and/or resources into a cursor, or 2) use platform-independent code to load image files into a buffer and then use platform-specific functionality to turn those buffers into a cursor. I went for 2 in this PR, partly because we already have some code for loading image files into a buffer and partly because 1 has the disadvantage of introducing extra platform-dependent packaging steps (i.e. turning say, a png cursor into a |
I had a quick look at the winit PR.
|
Sorry to let this sit. Your summary sounds accurate to me, and I think you describe the possible implementation approaches well. My gut prefers doing platform-specific stuff, but that would be blocked on resource bundles, so I'm okay with the other approach for the time being? I'm not sure if we could use the |
Ok, I think this is ready for another look. I couldn't use |
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.
Okay, this looks good to me; a few little notes but no blockers. I think there are some larger questions about whether or not we would like a more general image format in piet, but this is a very reasonable solution for now. Feel free to open an issue about adding support on mac; I'll do that at some point if nobody beats me to it.
) -> impl Iterator<Item = impl Iterator<Item = Color> + 'a> + 'a { | ||
// TODO: a version of this exists in piet-web and piet-coregraphics. Maybe put it somewhere | ||
// common? | ||
fn unpremul(x: u8, a: u8) -> u8 { |
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 could see this in the piet util
module?
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.
Sure, I'll make a piet PR
Ok, I think this addresses the druid comments. I'll make a separate piet pr. I'll let this sit until at least tomorrow in case of further comments, and then if I haven't heard any objections I'll merge. |
This isn't finished yet (at the very least, the windows implementation needs testing and error handling), but I'm posting it here because I have a question: the lowest-common-denominator across platforms seems to be that we can create cursors from bitmaps in memory, so it would be really handy to have support for that in
druid-shell
. I've put inImageBuf
as a placeholder, but there's a ton of overlap withdruid::widgets::ImageData
, but I didn't want to moveImageData
intodruid-shell
because that would entail fiddling with the "image" feature. So my questions are:piet
to have some kind of bitmap type?