feat: add support for additional search paths for icons

Blocked by https://github.com/oknozor/freedesktop-icons/pull/30

Needed to support application-provided icon directories in cosmic-applet-status-area
This commit is contained in:
Gavin John 2026-01-01 14:13:09 -05:00
parent a9f64c33ce
commit a8a26fdbc8
3 changed files with 45 additions and 7 deletions

View file

@ -281,17 +281,38 @@ impl Context {
.class(crate::theme::Button::AppletIcon)
}
pub fn get_icon_button_icon_with_path<'a, Message: Clone + 'static>(
&self,
icon_name: &'a str,
extra_search_path: Option<Vec<std::path::PathBuf>>,
) -> Named {
let suggested_size = self.suggested_size(true);
widget::icon::from_name_with_path(icon_name, extra_search_path)
.symbolic(true)
.size(suggested_size.0)
.into()
}
pub fn icon_button<'a, Message: Clone + 'static>(
&self,
icon_name: &'a str,
extra_search_path: Option<Vec<std::path::PathBuf>>,
) -> crate::widget::Button<'a, Message> {
self.icon_button_from_handle(self.get_icon_button_icon_with_path(icon_name, extra_search_path))
}
pub fn get_icon_button_icon<'a, Message: Clone + 'static>(
&self,
icon_name: &'a str,
) -> Named {
self.get_icon_button_icon_with_path(icon_name, None)
}
pub fn icon_button<'a, Message: Clone + 'static>(
&self,
icon_name: &'a str,
) -> crate::widget::Button<'a, Message> {
let suggested_size = self.suggested_size(true);
self.icon_button_from_handle(
widget::icon::from_name(icon_name)
.symbolic(true)
.size(suggested_size.0)
.into(),
)
self.icon_button_from_handle(self.get_icon_button_icon(icon_name))
}
pub fn applet_tooltip<'a, Message: 'static>(

View file

@ -36,6 +36,11 @@ pub fn from_name(name: impl Into<Arc<str>>) -> Named {
Named::new(name)
}
/// Create an icon handle from its XDG icon name and additional search directories.
pub fn from_name_with_path(name: impl Into<Arc<str>>, extra_search_path: Option<Vec<std::path::PathBuf>>) -> Named {
Named::new_with_path(name, extra_search_path)
}
/// An image which may be an SVG or PNG.
#[must_use]
#[derive(Clone, Setters)]

View file

@ -36,10 +36,17 @@ pub struct Named {
/// Prioritizes SVG over PNG
pub prefer_svg: bool,
// Additional directories to search
extra_search_path: Option<Vec<std::path::PathBuf>>,
}
impl Named {
pub fn new(name: impl Into<Arc<str>>) -> Self {
Named::new_with_path(name, None)
}
pub fn new_with_path(name: impl Into<Arc<str>>, extra_search_path: Option<Vec<std::path::PathBuf>>) -> Self {
let name = name.into();
let symbolic = name.ends_with("-symbolic");
Self {
@ -49,6 +56,7 @@ impl Named {
size: None,
scale: None,
prefer_svg: symbolic,
extra_search_path,
}
}
@ -69,6 +77,10 @@ impl Named {
if let Some(size) = self.size {
lookup = lookup.with_size(size);
}
if let Some(extra_search_path) = self.extra_search_path {
lookup = lookup.with_extra_search_path(extra_search_path);
}
if self.prefer_svg {
lookup = lookup.force_svg();