use std::cell::Cell;
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum CursorIcon {
#[default]
Default,
None,
ContextMenu,
Help,
PointingHand,
Progress,
Wait,
Cell,
Crosshair,
Text,
VerticalText,
Alias,
Copy,
Move,
NoDrop,
NotAllowed,
Grab,
Grabbing,
AllScroll,
ResizeHorizontal,
ResizeNeSw,
ResizeNwSe,
ResizeVertical,
ResizeEast,
ResizeSouthEast,
ResizeSouth,
ResizeSouthWest,
ResizeWest,
ResizeNorthWest,
ResizeNorth,
ResizeNorthEast,
ResizeColumn,
ResizeRow,
ZoomIn,
ZoomOut,
}
impl CursorIcon {
pub fn to_css(self) -> &'static str {
match self {
Self::Default => "default",
Self::None => "none",
Self::ContextMenu => "context-menu",
Self::Help => "help",
Self::PointingHand => "pointer",
Self::Progress => "progress",
Self::Wait => "wait",
Self::Cell => "cell",
Self::Crosshair => "crosshair",
Self::Text => "text",
Self::VerticalText => "vertical-text",
Self::Alias => "alias",
Self::Copy => "copy",
Self::Move => "move",
Self::NoDrop => "no-drop",
Self::NotAllowed => "not-allowed",
Self::Grab => "grab",
Self::Grabbing => "grabbing",
Self::AllScroll => "all-scroll",
Self::ResizeHorizontal => "ew-resize",
Self::ResizeNeSw => "nesw-resize",
Self::ResizeNwSe => "nwse-resize",
Self::ResizeVertical => "ns-resize",
Self::ResizeEast => "e-resize",
Self::ResizeSouthEast => "se-resize",
Self::ResizeSouth => "s-resize",
Self::ResizeSouthWest => "sw-resize",
Self::ResizeWest => "w-resize",
Self::ResizeNorthWest => "nw-resize",
Self::ResizeNorth => "n-resize",
Self::ResizeNorthEast => "ne-resize",
Self::ResizeColumn => "col-resize",
Self::ResizeRow => "row-resize",
Self::ZoomIn => "zoom-in",
Self::ZoomOut => "zoom-out",
}
}
}
thread_local! {
static CURSOR_ICON: Cell<CursorIcon> = Cell::new(CursorIcon::Default);
}
pub fn set_cursor_icon(icon: CursorIcon) {
CURSOR_ICON.with(|c| c.set(icon));
}
pub fn current_cursor_icon() -> CursorIcon {
CURSOR_ICON.with(|c| c.get())
}
pub fn reset_cursor_icon() {
CURSOR_ICON.with(|c| c.set(CursorIcon::Default));
}