pub struct Cursor { /* private fields */ }Expand description
A loaded cursor, immutable once built.
Implementations§
Source§impl Cursor
impl Cursor
Sourcepub fn load(
resolved: &ThemeResolution,
requested_size: u32,
) -> Result<Self, CursorError>
pub fn load( resolved: &ThemeResolution, requested_size: u32, ) -> Result<Self, CursorError>
Load from a resolved theme entry at the nearest available size.
Cursor files are multi-resolution packs, so this picks the nominal size
closest to requested_size and takes every frame filed under it. A
requested_size of zero means the default nominal size.
§Errors
CursorError::Ioif the file cannot be read.CursorError::Malformedif it is not a cursor file, is truncated, or contradicts itself.CursorError::TooLargeif the size it would load has more frames, or larger ones, than the loader accepts.CursorError::NoImagesif it parses but holds no images.
Sourcepub fn load_named(
theme: &Theme,
cursor_name: &str,
preferred_theme: &str,
requested_size: u32,
) -> Result<Self, CursorError>
pub fn load_named( theme: &Theme, cursor_name: &str, preferred_theme: &str, requested_size: u32, ) -> Result<Self, CursorError>
Sourcepub fn from_bytes(
bytes: &[u8],
requested_size: u32,
) -> Result<Self, CursorError>
pub fn from_bytes( bytes: &[u8], requested_size: u32, ) -> Result<Self, CursorError>
Load from the bytes of a cursor file.
The seam the fuzz target drives, so it exercises the same bounds the real loader does.
§Errors
As Cursor::load, less the I/O.
Sourcepub fn from_argb(
pixels: &[u32],
width: u32,
height: u32,
xhot: u32,
yhot: u32,
) -> Result<Self, CursorError>
pub fn from_argb( pixels: &[u32], width: u32, height: u32, xhot: u32, yhot: u32, ) -> Result<Self, CursorError>
Build a static cursor from caller-supplied pixels.
The in-process fallback for when no cursor theme is installed. Pixels
are premultiplied 0xAARRGGBB, row-major, and are copied.
§Errors
CursorError::InvalidImage for a zero or oversize dimension, or a
pixel count that does not match the dimensions. A caller bug, surfaced
here rather than as a surprise at render time.
Sourcepub fn from_frames(frames: Vec<Frame>) -> Result<Self, CursorError>
pub fn from_frames(frames: Vec<Frame>) -> Result<Self, CursorError>
Build a cursor from frames the caller already has.
The many-frame form of Cursor::from_argb, for a caller generating
cursors rather than loading them – a compositor drawing its own
spinner, or a test. Frames play in the order given.
§Errors
CursorError::NoImagesfor an empty set.CursorError::InvalidImageif any frame’s pixel count disagrees with its dimensions, or a dimension is zero or past the limit.CursorError::TooLargefor more frames than the loader accepts.
Sourcepub fn is_animated(&self) -> bool
pub fn is_animated(&self) -> bool
Whether this cursor actually animates.
More than one frame is not enough: some themes ship multi-frame packs with a zero delay on every frame, which would otherwise loop instantly and flicker.
Sourcepub fn frame_at(&self, elapsed: Duration) -> &Frame
pub fn frame_at(&self, elapsed: Duration) -> &Frame
The frame showing at elapsed since the cursor started displaying.
Deterministic and total: a static cursor, or one whose frames all declare no delay, always answers with the first frame.
Sourcepub fn frame_index_at(&self, elapsed: Duration) -> usize
pub fn frame_index_at(&self, elapsed: Duration) -> usize
Which frame is showing at elapsed.
The index rather than the frame, so a caller redrawing into a buffer can tell that nothing has changed and skip the work. A cursor ticking at 60 Hz through 100 ms frames redraws on one tick in six.