Use cursor-icon crate for CursorIcon
This crate is aimed to simplify handling of cursor icon across various crates and be used in the public API.
This commit is contained in:
parent
596c0edf0f
commit
bd9cc2a9da
11 changed files with 54 additions and 250 deletions
|
|
@ -2026,7 +2026,7 @@ unsafe fn public_window_callback_inner<T: 'static>(
|
|||
|
||||
match set_cursor_to {
|
||||
Some(cursor) => {
|
||||
let cursor = LoadCursorW(0, cursor.to_windows_cursor());
|
||||
let cursor = LoadCursorW(0, util::to_windows_cursor(cursor));
|
||||
SetCursor(cursor);
|
||||
0
|
||||
}
|
||||
|
|
|
|||
|
|
@ -164,32 +164,30 @@ pub fn get_instance_handle() -> HINSTANCE {
|
|||
unsafe { &__ImageBase as *const _ as _ }
|
||||
}
|
||||
|
||||
impl CursorIcon {
|
||||
pub(crate) fn to_windows_cursor(self) -> PCWSTR {
|
||||
match self {
|
||||
CursorIcon::Arrow | CursorIcon::Default => IDC_ARROW,
|
||||
CursorIcon::Hand => IDC_HAND,
|
||||
CursorIcon::Crosshair => IDC_CROSS,
|
||||
CursorIcon::Text | CursorIcon::VerticalText => IDC_IBEAM,
|
||||
CursorIcon::NotAllowed | CursorIcon::NoDrop => IDC_NO,
|
||||
CursorIcon::Grab | CursorIcon::Grabbing | CursorIcon::Move | CursorIcon::AllScroll => {
|
||||
IDC_SIZEALL
|
||||
}
|
||||
CursorIcon::EResize
|
||||
| CursorIcon::WResize
|
||||
| CursorIcon::EwResize
|
||||
| CursorIcon::ColResize => IDC_SIZEWE,
|
||||
CursorIcon::NResize
|
||||
| CursorIcon::SResize
|
||||
| CursorIcon::NsResize
|
||||
| CursorIcon::RowResize => IDC_SIZENS,
|
||||
CursorIcon::NeResize | CursorIcon::SwResize | CursorIcon::NeswResize => IDC_SIZENESW,
|
||||
CursorIcon::NwResize | CursorIcon::SeResize | CursorIcon::NwseResize => IDC_SIZENWSE,
|
||||
CursorIcon::Wait => IDC_WAIT,
|
||||
CursorIcon::Progress => IDC_APPSTARTING,
|
||||
CursorIcon::Help => IDC_HELP,
|
||||
_ => IDC_ARROW, // use arrow for the missing cases.
|
||||
pub(crate) fn to_windows_cursor(cursor: CursorIcon) -> PCWSTR {
|
||||
match cursor {
|
||||
CursorIcon::Default => IDC_ARROW,
|
||||
CursorIcon::Pointer => IDC_HAND,
|
||||
CursorIcon::Crosshair => IDC_CROSS,
|
||||
CursorIcon::Text | CursorIcon::VerticalText => IDC_IBEAM,
|
||||
CursorIcon::NotAllowed | CursorIcon::NoDrop => IDC_NO,
|
||||
CursorIcon::Grab | CursorIcon::Grabbing | CursorIcon::Move | CursorIcon::AllScroll => {
|
||||
IDC_SIZEALL
|
||||
}
|
||||
CursorIcon::EResize
|
||||
| CursorIcon::WResize
|
||||
| CursorIcon::EwResize
|
||||
| CursorIcon::ColResize => IDC_SIZEWE,
|
||||
CursorIcon::NResize
|
||||
| CursorIcon::SResize
|
||||
| CursorIcon::NsResize
|
||||
| CursorIcon::RowResize => IDC_SIZENS,
|
||||
CursorIcon::NeResize | CursorIcon::SwResize | CursorIcon::NeswResize => IDC_SIZENESW,
|
||||
CursorIcon::NwResize | CursorIcon::SeResize | CursorIcon::NwseResize => IDC_SIZENWSE,
|
||||
CursorIcon::Wait => IDC_WAIT,
|
||||
CursorIcon::Progress => IDC_APPSTARTING,
|
||||
CursorIcon::Help => IDC_HELP,
|
||||
_ => IDC_ARROW, // use arrow for the missing cases.
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -333,7 +333,7 @@ impl Window {
|
|||
pub fn set_cursor_icon(&self, cursor: CursorIcon) {
|
||||
self.window_state_lock().mouse.cursor = cursor;
|
||||
self.thread_executor.execute_in_thread(move || unsafe {
|
||||
let cursor = LoadCursorW(0, cursor.to_windows_cursor());
|
||||
let cursor = LoadCursorW(0, util::to_windows_cursor(cursor));
|
||||
SetCursor(cursor);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue