-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Add Hidden to CursorIcon and CursorSource enums #15386
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
base: main
Are you sure you want to change the base?
Changes from all commits
13d73fb
7cd2a57
bc9e1a3
b0e7ce4
6d7b8c8
9217457
905d75e
9b9e1cd
b9ed614
b48136e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -154,6 +154,8 @@ pub struct CustomCursorCache(pub HashMap<CustomCursorCacheKey, winit::window::Cu | |
/// A source for a cursor. Is created in `bevy_render` and consumed by the winit event loop. | ||
#[derive(Debug)] | ||
pub enum CursorSource { | ||
/// A hidden cursor, used to hide the cursor in `winit_window` | ||
Hidden, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we should propagate cursor visibility to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm starting to think what we really need to do is do something along the lines of not having a cursor from being instead
Overtime, I want to probably work on moving the system related I would ideally like to have these all live in the same crate so maybe looking at breaking the circular dependencies next is the thing to do. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As to the
I don't get quite this means? Are you suggesting that if it isn't a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What I would be proposing is to just move cursor options from the window component to the cursor component and doing absolutely everything the exact same it was done before and make a new cursor component. struct Cursor {
pub visible: bool,
... other options ...
pub icon: CursorIcon,
} Then move everything that was done in the window update system to the cursor update system. But I that is a different proposal than what is included in the related issue, so it might not be relevant to this PR.
Yes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
E.g. if we want to use sprite sheets as animated cursors, those would need to be converted to be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is still missing documentation about platform specific behavior. |
||
/// A custom cursor was identified to be cached, no reason to recreate it. | ||
CustomCached(CustomCursorCacheKey), | ||
/// A custom cursor was not cached, so it needs to be created by the winit event loop. | ||
|
@@ -800,22 +802,28 @@ impl<T: Event> WinitAppRunnerState<T> { | |
continue; | ||
}; | ||
|
||
let final_cursor: winit::window::Cursor = match pending_cursor { | ||
let final_cursor: Option<winit::window::Cursor> = match pending_cursor { | ||
CursorSource::Hidden => None, | ||
CursorSource::CustomCached(cache_key) => { | ||
let Some(cached_cursor) = cursor_cache.0.get(&cache_key) else { | ||
error!("Cursor should have been cached, but was not found"); | ||
continue; | ||
}; | ||
cached_cursor.clone().into() | ||
Some(cached_cursor.clone().into()) | ||
} | ||
CursorSource::Custom((cache_key, cursor)) => { | ||
let custom_cursor = event_loop.create_custom_cursor(cursor); | ||
cursor_cache.0.insert(cache_key, custom_cursor.clone()); | ||
custom_cursor.into() | ||
Some(custom_cursor.into()) | ||
} | ||
CursorSource::System(system_cursor) => system_cursor.into(), | ||
CursorSource::System(system_cursor) => Some(system_cursor.into()), | ||
}; | ||
winit_window.set_cursor(final_cursor); | ||
if let Some(final_cursor) = final_cursor { | ||
winit_window.set_cursor_visible(true); | ||
winit_window.set_cursor(final_cursor); | ||
} else { | ||
winit_window.set_cursor_visible(false); | ||
} | ||
} | ||
} | ||
} | ||
|
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.
@eero-lehtinen this was quite pretty to do, I remember reading the example for this last week and now this seems so nice