diff --git a/crates/drag/src/lib.rs b/crates/drag/src/lib.rs index 2de7588..cb4a6e6 100644 --- a/crates/drag/src/lib.rs +++ b/crates/drag/src/lib.rs @@ -163,6 +163,10 @@ unsafe impl objc::Encode for DragMode { pub struct Options { pub skip_animatation_on_cancel_or_failure: bool, pub mode: DragMode, + /// Optional icon size (width, height) in pixels. + /// If set, the drag preview icon will be scaled to this size. + /// If None, the original image size will be used. + pub icon_size: Option<(u32, u32)>, } /// An image definition. diff --git a/crates/drag/src/platform_impl/macos/mod.rs b/crates/drag/src/platform_impl/macos/mod.rs index f232590..011130b 100644 --- a/crates/drag/src/platform_impl/macos/mod.rs +++ b/crates/drag/src/platform_impl/macos/mod.rs @@ -67,7 +67,8 @@ pub fn start_drag); - + if operation == 0 { // NSDragOperationNone callback_closure(DragResult::Cancel, mouse_location); @@ -269,7 +278,7 @@ pub fn start_drag)); + drop(Box::from_raw(*callback as *mut Box)); } } diff --git a/crates/drag/src/platform_impl/windows/mod.rs b/crates/drag/src/platform_impl/windows/mod.rs index ee9ee4f..7e9d434 100644 --- a/crates/drag/src/platform_impl/windows/mod.rs +++ b/crates/drag/src/platform_impl/windows/mod.rs @@ -239,7 +239,7 @@ pub fn start_drag(&CLSID_DragDropHelper) { @@ -280,7 +280,7 @@ pub fn start_drag(&CLSID_DragDropHelper) { @@ -312,7 +312,7 @@ pub fn start_drag Option { +fn get_drag_image(image: Image, icon_size: Option<(u32, u32)>) -> Option { let hbitmap = match image { Image::Raw(bytes) => image::read_bytes_to_hbitmap(&bytes).ok(), Image::File(path) => image::read_path_to_hbitmap(&path).ok(), @@ -320,7 +320,10 @@ fn get_drag_image(image: Image) -> Option { hbitmap.map(|hbitmap| unsafe { // get image size let mut bitmap: BITMAP = BITMAP::default(); - let (width, height) = if 0 + let (width, height) = if let Some((w, h)) = icon_size { + // Use specified icon size + (w as i32, h as i32) + } else if 0 == GetObjectW( hbitmap, std::mem::size_of::() as i32,