|
11 | 11 | #![cfg_attr(docsrs, feature(doc_auto_cfg))]
|
12 | 12 |
|
13 | 13 | //! The cross platform cursor icon type.
|
| 14 | +//! |
| 15 | +//! This type is intended to be used as a standard interopability type between |
| 16 | +//! GUI frameworks in order to convey the cursor icon type. |
| 17 | +//! |
| 18 | +//! # Example |
| 19 | +//! |
| 20 | +//! ``` |
| 21 | +//! use cursor_icon::CursorIcon; |
| 22 | +//! |
| 23 | +//! # fn main() -> Result<(), Box<dyn std::error::Error>> { |
| 24 | +//! // Parse a cursor icon from the string that describes it. |
| 25 | +//! let cursor_name = "pointer"; |
| 26 | +//! let cursor_icon: CursorIcon = cursor_name.parse()?; |
| 27 | +//! println!("The cursor icon is {:?}", cursor_icon); |
| 28 | +//! # Ok(()) |
| 29 | +//! # } |
| 30 | +//! ``` |
14 | 31 |
|
15 | 32 | // This file contains a portion of the CSS Basic User Interface Module Level 3
|
16 | 33 | // specification. In particular, the names for the cursor from the #cursor
|
@@ -94,6 +111,15 @@ extern crate alloc as _;
|
94 | 111 | ///
|
95 | 112 | /// The names are taken from the CSS W3C specification:
|
96 | 113 | /// <https://www.w3.org/TR/css-ui-3/#cursor>
|
| 114 | +/// |
| 115 | +/// # Examples |
| 116 | +/// |
| 117 | +/// ``` |
| 118 | +/// use cursor_icon::CursorIcon; |
| 119 | +/// |
| 120 | +/// // Get the cursor icon for the default cursor. |
| 121 | +/// let cursor_icon = CursorIcon::Default; |
| 122 | +/// ``` |
97 | 123 | #[non_exhaustive]
|
98 | 124 | #[derive(Debug, Default, Copy, Clone, PartialEq, Eq, Hash)]
|
99 | 125 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
@@ -231,6 +257,30 @@ impl CursorIcon {
|
231 | 257 | ///
|
232 | 258 | /// This name most of the time could be passed as is to cursor loading
|
233 | 259 | /// libraries on X11/Wayland and could be used as-is on web.
|
| 260 | + /// |
| 261 | + /// # Examples |
| 262 | + /// |
| 263 | + /// ```no_run |
| 264 | + /// use cursor_icon::CursorIcon; |
| 265 | + /// use wayland_cursor::CursorTheme; |
| 266 | + /// |
| 267 | + /// # use wayland_client::Connection; |
| 268 | + /// # use wayland_client::protocol::wl_shm::WlShm; |
| 269 | + /// # fn test(conn: &Connection, shm: WlShm) -> Result<(), Box<dyn std::error::Error>> { |
| 270 | + /// // Choose a cursor to load. |
| 271 | + /// let cursor = CursorIcon::Help; |
| 272 | + /// |
| 273 | + /// // Load the Wayland cursor theme. |
| 274 | + /// let mut cursor_theme = CursorTheme::load(conn, shm, 32)?; |
| 275 | + /// |
| 276 | + /// // Load the cursor. |
| 277 | + /// let cursor = cursor_theme.get_cursor(cursor.name()); |
| 278 | + /// if let Some(cursor) = cursor { |
| 279 | + /// println!("Total number of images: {}", cursor.image_count()); |
| 280 | + /// } |
| 281 | + /// # Ok(()) |
| 282 | + /// # } |
| 283 | + /// ``` |
234 | 284 | pub fn name(&self) -> &'static str {
|
235 | 285 | match self {
|
236 | 286 | CursorIcon::Default => "default",
|
@@ -316,6 +366,10 @@ impl core::str::FromStr for CursorIcon {
|
316 | 366 | }
|
317 | 367 |
|
318 | 368 | /// An error which could be returned when parsing [`CursorIcon`].
|
| 369 | +/// |
| 370 | +/// This occurs when the [`FromStr`] implementation of [`CursorIcon`] fails. |
| 371 | +/// |
| 372 | +/// [`FromStr`]: core::str::FromStr |
319 | 373 | #[derive(Debug, PartialEq, Eq)]
|
320 | 374 | pub struct CursorIconParseError {
|
321 | 375 | _private: (),
|
|
0 commit comments