Merge Window::set_cursor_icon() and Window::set_custom_cursor() (#3308)

This commit is contained in:
daxpedda 2023-12-25 07:20:52 +01:00 committed by GitHub
parent 34dd2cdba9
commit be4a660011
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 165 additions and 159 deletions

View file

@ -6,6 +6,7 @@ use std::ops;
use std::sync::{Mutex, MutexGuard};
use crate::{
cursor::Cursor,
dpi::{
LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize, Position, Size, Size::Logical,
},
@ -20,11 +21,11 @@ use crate::{
monitor::{self, MonitorHandle, VideoMode},
view::WinitView,
window_delegate::WinitWindowDelegate,
Fullscreen, OsError, PlatformCustomCursor,
Fullscreen, OsError,
},
window::{
CursorGrabMode, CursorIcon, ImePurpose, ResizeDirection, Theme, UserAttentionType,
WindowAttributes, WindowButtons, WindowId as RootWindowId, WindowLevel,
CursorGrabMode, ImePurpose, ResizeDirection, Theme, UserAttentionType, WindowAttributes,
WindowButtons, WindowId as RootWindowId, WindowLevel,
},
};
use core_graphics::display::{CGDisplay, CGPoint};
@ -795,17 +796,19 @@ impl WinitWindow {
buttons
}
pub fn set_cursor_icon(&self, icon: CursorIcon) {
let view = self.view();
view.set_cursor_icon(cursor_from_icon(icon));
self.invalidateCursorRectsForView(&view);
}
#[inline]
pub(crate) fn set_custom_cursor(&self, cursor: PlatformCustomCursor) {
let view = self.view();
view.set_cursor_icon(cursor.0.clone());
self.invalidateCursorRectsForView(&view);
pub fn set_cursor(&self, cursor: Cursor) {
match cursor {
Cursor::Icon(icon) => {
let view = self.view();
view.set_cursor_icon(cursor_from_icon(icon));
self.invalidateCursorRectsForView(&view);
}
Cursor::Custom(cursor) => {
let view = self.view();
view.set_cursor_icon(cursor.inner.0.clone());
self.invalidateCursorRectsForView(&view);
}
}
}
#[inline]