Skip to content

Add CursorTheme::load_icon_with_depth method #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,22 @@ impl CursorTheme {
let mut walked_themes = HashSet::new();

self.theme
.load_icon(icon_name, &self.search_paths, &mut walked_themes)
.load_icon_with_depth(icon_name, &self.search_paths, &mut walked_themes)
.map(|(pathbuf, _)| pathbuf)
}

/// Try to load an icon from the theme, returning it with its inheritance
/// depth.
///
/// If the icon is not found within this theme's directories, then the
/// function looks at the theme from which this theme is inherited. The
/// second element of the returned tuple indicates how many levels of
/// inheritance were traversed before the icon was found.
pub fn load_icon_with_depth(&self, icon_name: &str) -> Option<(PathBuf, usize)> {
let mut walked_themes = HashSet::new();

self.theme
.load_icon_with_depth(icon_name, &self.search_paths, &mut walked_themes)
}
}

Expand Down Expand Up @@ -82,18 +97,18 @@ impl CursorThemeIml {
}

/// The implementation of cursor icon loading.
fn load_icon(
fn load_icon_with_depth(
&self,
icon_name: &str,
search_paths: &[PathBuf],
walked_themes: &mut HashSet<String>,
) -> Option<PathBuf> {
) -> Option<(PathBuf, usize)> {
for data in &self.data {
let mut icon_path = data.0.clone();
icon_path.push("cursors");
icon_path.push(icon_name);
if icon_path.is_file() {
return Some(icon_path);
return Some((icon_path, 0));
}
}

Expand All @@ -115,8 +130,8 @@ impl CursorThemeIml {

let inherited_theme = CursorThemeIml::load(inherits, search_paths);

match inherited_theme.load_icon(icon_name, search_paths, walked_themes) {
Some(icon_path) => return Some(icon_path),
match inherited_theme.load_icon_with_depth(icon_name, search_paths, walked_themes) {
Some((icon_path, depth)) => return Some((icon_path, depth + 1)),
None => continue,
}
}
Expand Down
Loading