Skip to content

Changed the way cursors are defined in bevy_feathers. #20169

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

Merged
merged 10 commits into from
Jul 29, 2025

Conversation

viridia
Copy link
Contributor

@viridia viridia commented Jul 17, 2025

Originally, we re-used the CursorIcon component which was intended to be placed on the window, and expanded its use so that it could be placed on any hoverable entity.

In this PR, we restore CursorIcon to its original usage, and instead introduce a new type EntityCursor intended to be placed on hoverable entities.

Part of the motivation for this is that it will make it easier to support custom cursors in BSN templates without having to add new trait impls in bevy_winit.

Bikeshedding on the name EntityCursor is welcome. Originally I had thought NodeCursor, but it's not just for Nodes, it can be placed on any hoverable entity.

Note: this was discussed in Discord with @cart

@viridia viridia requested review from cart and alice-i-cecile July 17, 2025 00:35
@alice-i-cecile alice-i-cecile added this to the 0.17 milestone Jul 17, 2025
mut q_windows: Query<(Entity, &mut Window, Option<&CursorIcon>)>,
r_default_cursor: Res<DefaultCursorIcon>,
r_default_cursor: Res<DefaultEntityCursor>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of interest, does it make sense to make the default cursor a component on window rather than a global resource? Presumably you could then define the per-window default as well.

Is there a case where there’s something further up the tree than a window which would make this suggestion fall apart?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer not to add features based on hypothetical use cases - ones that may or may not ever come up. The vast majority of apps only have one window.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see why you would ever want to have a distinct default cursor per window.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason I mentioned this is that it seemed like a natural place to put it instead of it being a resource. That is to say, if you only have 1 window most of the time, then your window is your “resource singleton” anyway. The cursor already “belongs to” the window (via CursorIcon) and the code already iterates over all windows AFAICS and so it just felt natural.

But yeah I’m not at all fussed, was just a thought.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to resolve this, I can’t.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For what it's worth, @mgi388 that's actually what we do in one app for work (although Python and GTK) - the different windows have different usages and different cursors for "prod" or "test" environment.

(Why that's in one app and not two: don't ask!)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I could see use cases exist here. Like maybe you have a map in a separate window that you default to a grab cursor (because you just pan the map around using your cursor) and then the primary window is just a pointer.

I guess my point really was that if it was a component per window entity then a) that use case would magically already be solved and b) it seems like a concept that belongs to the window entity so may as well add it there rather than as a global resource, which felt cleaner to me (e.g. you wouldn’t have a dangling resource that is only relevant to if you have a window in your app).

But yeah, I’m still not fussed, I’m sure it can be changed in the future if needed.

Copy link
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small naming + docs suggestion, then LGTM.

@viridia
Copy link
Contributor Author

viridia commented Jul 17, 2025

@alice-i-cecile Ideally this whole thing should move to bevy_picking; the only possible reason why you might not is that this would add a dependency bevy_picking -> bevy_winit, but since it already depends on bevy_window I don't see why this would be a problem.

@viridia
Copy link
Contributor Author

viridia commented Jul 17, 2025

Also, I don't know why the check-advisories CI is whinging.

@cart
Copy link
Member

cart commented Jul 17, 2025

but since it already depends on bevy_window I don't see why this would be a problem.

The issue here is that bevy_winit is considered a "backend" for bevy_window, which is the backend-agnostic interface. Ideally bevy_picking is "backend independent". Aka it doesn't care if someone wants to use bevy_sdl2 instead of bevy_winit.

@viridia
Copy link
Contributor Author

viridia commented Jul 17, 2025

but since it already depends on bevy_window I don't see why this would be a problem.

The issue here is that bevy_winit is considered a "backend" for bevy_window, which is the backend-agnostic interface. Ideally bevy_picking is "backend independent". Aka it doesn't care if someone wants to use bevy_sdl2 instead of bevy_winit.

If that's the case, then maybe we need to abstract out cursor definitions from bevy_winit.

@cart
Copy link
Member

cart commented Jul 17, 2025

If that's the case, then maybe we need to abstract out cursor definitions from bevy_winit.

Agreed. I think this was attempted in the past (I vaguely remember advocating for it), but I also vaguely remember there being something that made it non-trivial.

@alice-i-cecile
Copy link
Member

If that's the case, then maybe we need to abstract out cursor definitions from bevy_winit.

Agreed. I think this was attempted in the past (I vaguely remember advocating for it), but I also vaguely remember there being something that made it non-trivial.

IIRC the problem was horrible circular dependencies with respect to rendering, assets, windowing and bevy_image. Same flavor of problem as our yet-unfixed "set window decoration" stuff.

@viridia
Copy link
Contributor Author

viridia commented Jul 17, 2025

Added #20182

@alice-i-cecile alice-i-cecile added C-Feature A new feature, making something new possible A-UI Graphical user interfaces, styles, layouts, and widgets S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jul 17, 2025
@viridia
Copy link
Contributor Author

viridia commented Jul 25, 2025

Fixes #20283

Also, I pushed a new version which streamlines the logic for setting the window cursor considerably.

@alice-i-cecile
Copy link
Member

@viridia can you tackle merge conflicts for this now? I think this should be the last round of them.

viridia added 8 commits July 28, 2025 12:36
Originally, we re-used the `CursorIcon` component which was intended to
be placed on the window, and expanded its use so that it could be placed
on any hoverable entity.

In this PR, we restore `CursorIcon` to its original usage, and instead
introduce a new type `EntityCursor` intended to be placed on hoverable
entities.

Part of the motivation for this is that it will make it easier to
support BSN templates without having to add new trait impls in
bevy_winit.
@viridia
Copy link
Contributor Author

viridia commented Jul 28, 2025

@alice-i-cecile Should be good to go once the CI finishes.

@alice-i-cecile alice-i-cecile added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jul 29, 2025
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Jul 29, 2025
Merged via the queue into bevyengine:main with commit e76a4ed Jul 29, 2025
38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-UI Graphical user interfaces, styles, layouts, and widgets C-Feature A new feature, making something new possible S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants