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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

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

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 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.

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
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-Needs-Review Needs reviewer attention (from anyone!) to move forward
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants