Skip to content

Commit

Permalink
chore: add documents and size parm input
Browse files Browse the repository at this point in the history
  • Loading branch information
Decodetalkers committed Apr 11, 2024
1 parent 7b16293 commit e47352a
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions wayland-cursor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ pub struct CursorTheme {
fallback: Option<FallBack>,
}

struct FallBack(Box<dyn Fn(&str) -> Option<Cow<'static, [u8]>>>);
struct FallBack(Box<dyn Fn(&str, u32) -> Option<Cow<'static, [u8]>>>);

Check failure on line 89 in wayland-cursor/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy-check

very complex type used. Consider factoring parts into `type` definitions

Check failure on line 89 in wayland-cursor/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy-check

very complex type used. Consider factoring parts into `type` definitions

impl FallBack {
fn new<F>(fallback: F) -> Self
where
F: Fn(&str) -> Option<Cow<'static, [u8]>> + 'static,
F: Fn(&str, u32) -> Option<Cow<'static, [u8]>> + 'static,
{
Self(Box::new(fallback))
}
Expand Down Expand Up @@ -198,7 +198,7 @@ impl CursorTheme {
let Some(ref fallback) = self.fallback else {

Check failure on line 198 in wayland-cursor/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy-check

this `let...else` may be rewritten with the `?` operator

Check failure on line 198 in wayland-cursor/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy-check

this `let...else` may be rewritten with the `?` operator
return None;
};
let data = fallback.0(name)?;
let data = fallback.0(name, self.size)?;
let images = xparser::parse_xcursor(&data)?;
let conn = Connection::from_backend(self.backend.upgrade()?);
Cursor::new(&conn, name, self, &images, self.size)
Expand All @@ -211,11 +211,22 @@ impl CursorTheme {
}
}

/// Set the set_callback, the return value of the fallback function should be the source of
/// Set the callback to load the data, the return value of the fallback function should be the source of
/// xcursor
/// Same as calling the following:
/// ```
/// # use wayland_cursor::CursorTheme;
/// # use wayland_client::{Connection, backend::InvalidId, protocol::wl_shm};
/// # fn example(conn: &Connection, shm: wl_shm::WlShm, size: u32) -> Result<CursorTheme, InvalidId> {
/// let mut theme = CursorTheme::load_or(conn, shm, "default", size);
/// theme.set_callback(|name, size| {
/// include_bytes!("./icons/default")
/// });
/// # }
/// ```
pub fn set_callback<F>(&mut self, fallback: F)
where
F: Fn(&str) -> Option<Cow<'static, [u8]>> + 'static,
F: Fn(&str, u32) -> Option<Cow<'static, [u8]>> + 'static,
{
self.fallback = Some(FallBack::new(fallback))
}
Expand Down

0 comments on commit e47352a

Please sign in to comment.