Skip to content

Commit 13d73fb

Browse files
author
Fernan Lukban
committed
Add Hidden to CursorIcon and CursorSource enums
1 parent 9386bd0 commit 13d73fb

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

crates/bevy_render/src/view/window/cursor.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ impl Plugin for CursorPlugin {
3737
#[derive(Component, Debug, Clone, Reflect, PartialEq, Eq)]
3838
#[reflect(Component, Debug, Default, PartialEq)]
3939
pub enum CursorIcon {
40+
Hidden,
4041
/// Custom cursor image.
4142
Custom(CustomCursor),
4243
/// System provided cursor icon.
@@ -98,6 +99,7 @@ pub fn update_cursors(
9899
}
99100

100101
let cursor_source = match cursor.as_ref() {
102+
CursorIcon::Hidden => CursorSource::Hidden,
101103
CursorIcon::Custom(CustomCursor::Image { handle, hotspot }) => {
102104
let cache_key = match handle.id() {
103105
AssetId::Index { index, .. } => {

crates/bevy_winit/src/state.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ pub struct CustomCursorCache(pub HashMap<CustomCursorCacheKey, winit::window::Cu
149149
/// A source for a cursor. Is created in `bevy_render` and consumed by the winit event loop.
150150
#[derive(Debug)]
151151
pub enum CursorSource {
152+
/// Cursor was set to hidden, so we need to pass this onto the winit_window
153+
Hidden,
152154
/// A custom cursor was identified to be cached, no reason to recreate it.
153155
CustomCached(CustomCursorCacheKey),
154156
/// A custom cursor was not cached, so it needs to be created by the winit event loop.
@@ -795,22 +797,28 @@ impl<T: Event> WinitAppRunnerState<T> {
795797
continue;
796798
};
797799

798-
let final_cursor: winit::window::Cursor = match pending_cursor {
800+
let final_cursor: Option<winit::window::Cursor> = match pending_cursor {
801+
CursorSource::Hidden => None,
799802
CursorSource::CustomCached(cache_key) => {
800803
let Some(cached_cursor) = cursor_cache.0.get(&cache_key) else {
801804
error!("Cursor should have been cached, but was not found");
802805
continue;
803806
};
804-
cached_cursor.clone().into()
807+
Some(cached_cursor.clone().into())
805808
}
806809
CursorSource::Custom((cache_key, cursor)) => {
807810
let custom_cursor = event_loop.create_custom_cursor(cursor);
808811
cursor_cache.0.insert(cache_key, custom_cursor.clone());
809-
custom_cursor.into()
812+
Some(custom_cursor.into())
810813
}
811-
CursorSource::System(system_cursor) => system_cursor.into(),
814+
CursorSource::System(system_cursor) => Some(system_cursor.into()),
812815
};
813-
winit_window.set_cursor(final_cursor);
816+
if let Some(final_cursor) = final_cursor {
817+
winit_window.set_cursor_visible(true);
818+
winit_window.set_cursor(final_cursor);
819+
} else {
820+
winit_window.set_cursor_visible(false);
821+
}
814822
}
815823
}
816824
}

0 commit comments

Comments
 (0)