#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub enum Cursor {
#[default]
Arrow,
Pointer,
Grab,
Grabbing,
Crosshair,
Text,
Move,
NotAllowed,
Wait,
Held,
}
impl Cursor {
pub(crate) fn holds_pointer(self) -> bool {
matches!(self, Self::Held)
}
#[cfg(not(feature = "ui"))]
pub(crate) fn window_icon(self) -> Option<winit::window::CursorIcon> {
Some(match self {
Self::Arrow => winit::window::CursorIcon::Default,
Self::Pointer => winit::window::CursorIcon::Pointer,
Self::Grab => winit::window::CursorIcon::Grab,
Self::Grabbing => winit::window::CursorIcon::Grabbing,
Self::Crosshair => winit::window::CursorIcon::Crosshair,
Self::Text => winit::window::CursorIcon::Text,
Self::Move => winit::window::CursorIcon::Move,
Self::NotAllowed => winit::window::CursorIcon::NotAllowed,
Self::Wait => winit::window::CursorIcon::Wait,
Self::Held => return None,
})
}
#[cfg(feature = "ui")]
pub(crate) fn ui_icon(self) -> egui::CursorIcon {
match self {
Self::Arrow => egui::CursorIcon::Default,
Self::Pointer => egui::CursorIcon::PointingHand,
Self::Grab => egui::CursorIcon::Grab,
Self::Grabbing => egui::CursorIcon::Grabbing,
Self::Crosshair => egui::CursorIcon::Crosshair,
Self::Text => egui::CursorIcon::Text,
Self::Move => egui::CursorIcon::Move,
Self::NotAllowed => egui::CursorIcon::NotAllowed,
Self::Wait => egui::CursorIcon::Wait,
Self::Held => egui::CursorIcon::None,
}
}
#[cfg(feature = "ui")]
pub(crate) fn of_ui(icon: egui::CursorIcon) -> Option<Self> {
use egui::CursorIcon as Ui;
match icon {
Ui::Default => None,
Ui::PointingHand => Some(Self::Pointer),
Ui::Grab => Some(Self::Grab),
Ui::Grabbing => Some(Self::Grabbing),
Ui::Cell | Ui::Crosshair => Some(Self::Crosshair),
Ui::Text | Ui::VerticalText => Some(Self::Text),
Ui::NoDrop | Ui::NotAllowed => Some(Self::NotAllowed),
Ui::Progress | Ui::Wait => Some(Self::Wait),
Ui::AllScroll
| Ui::Move
| Ui::ResizeColumn
| Ui::ResizeEast
| Ui::ResizeHorizontal
| Ui::ResizeNeSw
| Ui::ResizeNorth
| Ui::ResizeNorthEast
| Ui::ResizeNorthWest
| Ui::ResizeNwSe
| Ui::ResizeRow
| Ui::ResizeSouth
| Ui::ResizeSouthEast
| Ui::ResizeSouthWest
| Ui::ResizeVertical
| Ui::ResizeWest => Some(Self::Move),
Ui::Alias
| Ui::ContextMenu
| Ui::Copy
| Ui::Help
| Ui::None
| Ui::ZoomIn
| Ui::ZoomOut => Some(Self::Arrow),
}
}
}