diff --git a/Cargo.lock b/Cargo.lock index f9fe145..2704f80 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1381,8 +1381,8 @@ checksum = "bff34eb29ff4b8a8688bc7299f14fb6b597461ca80fec03ed7d22939ab33e48f" [[package]] name = "bevy_naga_reflect" -version = "0.1.0" -source = "git+https://github.com/tychedelia/bevy_naga_reflect#853dc6e9bc7294f91ad19d4b8983af74a75584c7" +version = "0.2.0" +source = "git+https://github.com/tychedelia/bevy_naga_reflect#3ec0374aaa3dadf522691154bc143050135f40cd" dependencies = [ "bevy", "naga", @@ -3371,15 +3371,6 @@ dependencies = [ "bytemuck", ] -[[package]] -name = "font-types" -version = "0.12.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a7299a780854a6d391be2ae1c8521c9368471b559dbfd6a8dbd9f407eaff100" -dependencies = [ - "bytemuck", -] - [[package]] name = "fontique" version = "0.7.0" @@ -6576,17 +6567,6 @@ dependencies = [ "font-types 0.11.3", ] -[[package]] -name = "read-fonts" -version = "0.41.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "046a7d674daf459825b32f5062056d6882db0d2f5a479fbd76ccfc870ac18709" -dependencies = [ - "bytemuck", - "font-types 0.12.2", - "once_cell", -] - [[package]] name = "realfft" version = "3.5.0" @@ -7059,16 +7039,6 @@ dependencies = [ "read-fonts 0.39.2", ] -[[package]] -name = "skrifa" -version = "0.44.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "819ab7d62b1d3e72d9d9dea5650bac30424f9111364bb94928dbf5ecad1baa68" -dependencies = [ - "bytemuck", - "read-fonts 0.41.0", -] - [[package]] name = "slab" version = "0.4.12" @@ -7214,7 +7184,7 @@ version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c2499c2d826531388872b2268718aed907a39bd785ab0dcfe57fab26283f92e" dependencies = [ - "skrifa 0.44.0", + "skrifa 0.42.1", "yazi", "zeno", ] diff --git a/crates/processing_ffi/src/lib.rs b/crates/processing_ffi/src/lib.rs index f7eac79..f2a98a8 100644 --- a/crates/processing_ffi/src/lib.rs +++ b/crates/processing_ffi/src/lib.rs @@ -2939,6 +2939,43 @@ pub extern "C" fn processing_input_focus(surface_id: u64, focused: bool) { error::check(|| input_set_focus(Entity::from_bits(surface_id), focused)); } +pub const PROCESSING_CURSOR_ARROW: u8 = 0; +pub const PROCESSING_CURSOR_CROSS: u8 = 1; +pub const PROCESSING_CURSOR_HAND: u8 = 2; +pub const PROCESSING_CURSOR_MOVE: u8 = 3; +pub const PROCESSING_CURSOR_TEXT: u8 = 4; +pub const PROCESSING_CURSOR_WAIT: u8 = 5; + +fn cursor_icon(kind: u8) -> bevy::window::SystemCursorIcon { + use bevy::window::SystemCursorIcon; + match kind { + PROCESSING_CURSOR_CROSS => SystemCursorIcon::Crosshair, + PROCESSING_CURSOR_HAND => SystemCursorIcon::Pointer, + PROCESSING_CURSOR_MOVE => SystemCursorIcon::Move, + PROCESSING_CURSOR_TEXT => SystemCursorIcon::Text, + PROCESSING_CURSOR_WAIT => SystemCursorIcon::Wait, + _ => SystemCursorIcon::Default, + } +} + +/// Show the mouse cursor with the given system type (PROCESSING_CURSOR_*). +#[unsafe(no_mangle)] +pub extern "C" fn processing_cursor(surface_id: u64, kind: u8) { + error::clear_error(); + let surface = Entity::from_bits(surface_id); + error::check(|| { + input_set_cursor_visible(surface, true)?; + input_set_cursor_icon(surface, cursor_icon(kind)) + }); +} + +/// Hide the mouse cursor. +#[unsafe(no_mangle)] +pub extern "C" fn processing_no_cursor(surface_id: u64) { + error::clear_error(); + error::check(|| input_set_cursor_visible(Entity::from_bits(surface_id), false)); +} + #[unsafe(no_mangle)] pub extern "C" fn processing_input_flush() { error::clear_error(); diff --git a/crates/processing_input/src/lib.rs b/crates/processing_input/src/lib.rs index 98d715c..4ee0bfd 100644 --- a/crates/processing_input/src/lib.rs +++ b/crates/processing_input/src/lib.rs @@ -177,6 +177,30 @@ pub fn input_cursor_visible(surface: Entity) -> error::Result { }) } +pub fn input_set_cursor_visible(surface: Entity, visible: bool) -> error::Result<()> { + app_mut(|app| { + if let Some(mut cursor) = app + .world_mut() + .get_mut::(surface) + { + cursor.visible = visible; + } + Ok(()) + }) +} + +pub fn input_set_cursor_icon( + surface: Entity, + icon: bevy::window::SystemCursorIcon, +) -> error::Result<()> { + app_mut(|app| { + if let Ok(mut entity) = app.world_mut().get_entity_mut(surface) { + entity.insert(bevy::window::CursorIcon::System(icon)); + } + Ok(()) + }) +} + /// Flushes the input state by running the relevant schedules. This is required to ensure that /// Bevy's bookkeeping of input state is up to date after manually sending input events. /// It should be called after sending any input events and before querying input state