#![cfg_attr(not(feature = "std"), no_std)]
#![deny(rust_2018_idioms)]
#![deny(rustdoc::broken_intra_doc_links)]
#![deny(unsafe_op_in_unsafe_fn)]
#![deny(improper_ctypes, improper_ctypes_definitions)]
#![deny(clippy::all)]
#![deny(missing_debug_implementations)]
#![deny(missing_docs)]
#![forbid(unsafe_code)]
#![cfg_attr(clippy, deny(warnings))]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#[cfg(feature = "serde")]
#[macro_use]
extern crate serde;
#[cfg(feature = "alloc")]
extern crate alloc as _;
#[non_exhaustive]
#[derive(Debug, Default, Copy, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum CursorIcon {
#[default]
Default,
ContextMenu,
Help,
Pointer,
Progress,
Wait,
Cell,
Crosshair,
Text,
VerticalText,
Alias,
Copy,
Move,
NoDrop,
NotAllowed,
Grab,
Grabbing,
EResize,
NResize,
NeResize,
NwResize,
SResize,
SeResize,
SwResize,
WResize,
EwResize,
NsResize,
NeswResize,
NwseResize,
ColResize,
RowResize,
AllScroll,
ZoomIn,
ZoomOut,
DndAsk,
AllResize,
}
impl CursorIcon {
pub fn name(&self) -> &'static str {
match self {
CursorIcon::Default => "default",
CursorIcon::ContextMenu => "context-menu",
CursorIcon::Help => "help",
CursorIcon::Pointer => "pointer",
CursorIcon::Progress => "progress",
CursorIcon::Wait => "wait",
CursorIcon::Cell => "cell",
CursorIcon::Crosshair => "crosshair",
CursorIcon::Text => "text",
CursorIcon::VerticalText => "vertical-text",
CursorIcon::Alias => "alias",
CursorIcon::Copy => "copy",
CursorIcon::Move => "move",
CursorIcon::NoDrop => "no-drop",
CursorIcon::NotAllowed => "not-allowed",
CursorIcon::Grab => "grab",
CursorIcon::Grabbing => "grabbing",
CursorIcon::EResize => "e-resize",
CursorIcon::NResize => "n-resize",
CursorIcon::NeResize => "ne-resize",
CursorIcon::NwResize => "nw-resize",
CursorIcon::SResize => "s-resize",
CursorIcon::SeResize => "se-resize",
CursorIcon::SwResize => "sw-resize",
CursorIcon::WResize => "w-resize",
CursorIcon::EwResize => "ew-resize",
CursorIcon::NsResize => "ns-resize",
CursorIcon::NeswResize => "nesw-resize",
CursorIcon::NwseResize => "nwse-resize",
CursorIcon::ColResize => "col-resize",
CursorIcon::RowResize => "row-resize",
CursorIcon::AllScroll => "all-scroll",
CursorIcon::ZoomIn => "zoom-in",
CursorIcon::ZoomOut => "zoom-out",
CursorIcon::DndAsk => "dnd-ask",
CursorIcon::AllResize => "all-resize",
}
}
pub fn alt_names(&self) -> &[&'static str] {
match self {
CursorIcon::Default => &["left_ptr", "arrow", "top_left_arrow", "left_arrow"],
CursorIcon::ContextMenu => &[],
CursorIcon::Help => &["question_arrow", "whats_this"],
CursorIcon::Pointer => &["hand2", "hand1", "hand", "pointing_hand"],
CursorIcon::Progress => &["left_ptr_watch", "half-busy"],
CursorIcon::Wait => &["watch"],
CursorIcon::Cell => &["plus"],
CursorIcon::Crosshair => &["cross"],
CursorIcon::Text => &["xterm", "ibeam"],
CursorIcon::VerticalText => &[],
CursorIcon::Alias => &["link"],
CursorIcon::Copy => &[],
CursorIcon::Move => &[],
CursorIcon::NoDrop => &["circle"],
CursorIcon::NotAllowed => &["crossed_circle", "forbidden"],
CursorIcon::Grab => &["openhand", "fleur"],
CursorIcon::Grabbing => &["closedhand"],
CursorIcon::EResize => &["right_side"],
CursorIcon::NResize => &["top_side"],
CursorIcon::NeResize => &["top_right_corner"],
CursorIcon::NwResize => &["top_left_corner"],
CursorIcon::SResize => &["bottom_side"],
CursorIcon::SeResize => &["bottom_right_corner"],
CursorIcon::SwResize => &["bottom_left_corner"],
CursorIcon::WResize => &["left_side"],
CursorIcon::EwResize => &["h_double_arrow", "size_hor"],
CursorIcon::NsResize => &["v_double_arrow", "size_ver"],
CursorIcon::NeswResize => &["fd_double_arrow", "size_bdiag"],
CursorIcon::NwseResize => &["bd_double_arrow", "size_fdiag"],
CursorIcon::ColResize => &["split_h", "h_double_arrow", "sb_h_double_arrow"],
CursorIcon::RowResize => &["split_v", "v_double_arrow", "sb_v_double_arrow"],
CursorIcon::AllScroll => &["size_all"],
CursorIcon::ZoomIn => &[],
CursorIcon::ZoomOut => &[],
CursorIcon::DndAsk => &["copy"],
CursorIcon::AllResize => &["move"],
}
}
}
impl core::fmt::Display for CursorIcon {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.write_str(self.name())
}
}
impl core::str::FromStr for CursorIcon {
type Err = ParseError;
fn from_str(name: &str) -> Result<Self, Self::Err> {
match name {
"default" => Ok(CursorIcon::Default),
"context-menu" => Ok(CursorIcon::ContextMenu),
"help" => Ok(CursorIcon::Help),
"pointer" => Ok(CursorIcon::Pointer),
"progress" => Ok(CursorIcon::Progress),
"wait" => Ok(CursorIcon::Wait),
"cell" => Ok(CursorIcon::Cell),
"crosshair" => Ok(CursorIcon::Crosshair),
"text" => Ok(CursorIcon::Text),
"vertical-text" => Ok(CursorIcon::VerticalText),
"alias" => Ok(CursorIcon::Alias),
"copy" => Ok(CursorIcon::Copy),
"move" => Ok(CursorIcon::Move),
"no-drop" => Ok(CursorIcon::NoDrop),
"not-allowed" => Ok(CursorIcon::NotAllowed),
"grab" => Ok(CursorIcon::Grab),
"grabbing" => Ok(CursorIcon::Grabbing),
"e-resize" => Ok(CursorIcon::EResize),
"n-resize" => Ok(CursorIcon::NResize),
"ne-resize" => Ok(CursorIcon::NeResize),
"nw-resize" => Ok(CursorIcon::NwResize),
"s-resize" => Ok(CursorIcon::SResize),
"se-resize" => Ok(CursorIcon::SeResize),
"sw-resize" => Ok(CursorIcon::SwResize),
"w-resize" => Ok(CursorIcon::WResize),
"ew-resize" => Ok(CursorIcon::EwResize),
"ns-resize" => Ok(CursorIcon::NsResize),
"nesw-resize" => Ok(CursorIcon::NeswResize),
"nwse-resize" => Ok(CursorIcon::NwseResize),
"col-resize" => Ok(CursorIcon::ColResize),
"row-resize" => Ok(CursorIcon::RowResize),
"all-scroll" => Ok(CursorIcon::AllScroll),
"zoom-in" => Ok(CursorIcon::ZoomIn),
"zoom-out" => Ok(CursorIcon::ZoomOut),
_ => Err(ParseError { _private: () }),
}
}
}
#[derive(Debug, PartialEq, Eq, Hash)]
pub struct ParseError {
_private: (),
}
impl core::fmt::Display for ParseError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.write_str("failed to parse cursor icon")
}
}
#[cfg(feature = "std")]
impl std::error::Error for ParseError {}